Skip to content

Commit f34c0eb

Browse files
committed
Port to 1.20.5
1 parent 172713b commit f34c0eb

32 files changed

+265
-115
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
10-
- name: Set up JDK 17
10+
- name: Set up JDK 21
1111
uses: actions/setup-java@v3
1212
with:
1313
distribution: 'temurin'
14-
java-version: 17
14+
java-version: 21
1515
cache: 'gradle'
1616
- name: Make gradlew executable
1717
run: chmod +x ./gradlew

build.gradle

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
plugins {
22
// Required for NeoGradle
33
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7"
4-
id "net.darkhax.curseforgegradle" version "1.1.17" apply(false)
4+
id "net.darkhax.curseforgegradle" version "1.1.18" apply(false)
55
id "com.modrinth.minotaur" version "2.+" apply(false)
66
}
77

88
subprojects {
99
apply plugin: 'java'
1010

11-
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
11+
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
1212
java.withSourcesJar()
1313

1414
jar {
@@ -47,7 +47,7 @@ subprojects {
4747

4848
tasks.withType(JavaCompile).configureEach {
4949
it.options.encoding = 'UTF-8'
50-
it.options.getRelease().set(17)
50+
it.options.getRelease().set(21)
5151
}
5252

5353
processResources {
@@ -63,3 +63,11 @@ subprojects {
6363
enabled = false
6464
}
6565
}
66+
67+
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
68+
idea {
69+
module {
70+
downloadSources = true
71+
downloadJavadoc = true
72+
}
73+
}

common/src/main/java/com/mrbysco/armorposer/client/gui/ArmorGlowScreen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ArmorGlowScreen extends Screen {
2424

2525
private ArmorGlowWidget armorListWidget;
2626
private ArmorGlowWidget.ListEntry selected = null;
27-
private List<ArmorStand> armorStands;
27+
private final List<ArmorStand> armorStands;
2828
private Button locateButton;
2929
private Button modifyButton;
3030

common/src/main/java/com/mrbysco/armorposer/client/gui/ArmorPosesScreen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Component getButtonText() {
3636

3737
private static final int PADDING = 6;
3838

39-
private PoseListWidget[] poseListWidget = new PoseListWidget[2];
39+
private final PoseListWidget[] poseListWidget = new PoseListWidget[2];
4040
private PoseListWidget.ListEntry selected = null;
4141
private List<PoseEntry> poses;
4242
private final List<PoseEntry> unsortedPoses;

common/src/main/java/com/mrbysco/armorposer/client/gui/ArmorStandScreen.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import com.mojang.brigadier.exceptions.CommandSyntaxException;
55
import com.mojang.math.Axis;
66
import com.mrbysco.armorposer.Reference;
7-
import com.mrbysco.armorposer.client.GlowHandler;
87
import com.mrbysco.armorposer.client.gui.widgets.NumberFieldBox;
8+
import com.mrbysco.armorposer.client.gui.widgets.SizeSlider;
99
import com.mrbysco.armorposer.client.gui.widgets.ToggleButton;
1010
import com.mrbysco.armorposer.data.SwapData;
1111
import com.mrbysco.armorposer.platform.Services;
1212
import com.mrbysco.armorposer.util.ArmorStandData;
1313
import net.minecraft.ChatFormatting;
14-
import net.minecraft.Util;
1514
import net.minecraft.client.Minecraft;
1615
import net.minecraft.client.gui.GuiGraphics;
1716
import net.minecraft.client.gui.components.Button;
@@ -67,6 +66,7 @@ public class ArmorStandScreen extends Screen {
6766
private NumberFieldBox rotationTextField;
6867
private final ToggleButton[] toggleButtons = new ToggleButton[6];
6968
protected final NumberFieldBox[] poseTextFields = new NumberFieldBox[3 * 7];
69+
private SizeSlider sizeSlider;
7070
private LockIconButton lockButton;
7171
private final boolean allowScrolling;
7272

@@ -122,6 +122,12 @@ public void init() {
122122
this.addWidget(this.rotationTextField);
123123
this.rotationTextField.setTooltip(Tooltip.create(Component.translatable("armorposer.gui.tooltip.rotation")));
124124

125+
// Size slider
126+
this.addRenderableWidget(
127+
this.sizeSlider = new SizeSlider(1 + offsetX, offsetY + ((this.toggleButtons.length + 1) * 22), 38,
128+
(double) this.entityArmorStand.getScale(), 0.01D, 10.0D, this)
129+
);
130+
125131
// pose textboxes
126132
offsetX = this.width - 20 - 100;
127133
for (int i = 0; i < this.poseTextFields.length; i++) {
@@ -698,6 +704,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
698704
return super.mouseClicked(mouseX, mouseY, button);
699705
}
700706

707+
/**
708+
* Update the size of the armor stand
709+
*/
710+
public void updateScale() {
711+
this.textFieldUpdated();
712+
}
713+
701714
protected void textFieldUpdated() {
702715
this.updateEntity(this.writeFieldsToNBT());
703716
}
@@ -712,6 +725,7 @@ protected CompoundTag writeFieldsToNBT() {
712725
compound.putBoolean("CustomNameVisible", this.toggleButtons[5].getValue());
713726
compound.putBoolean("Invulnerable", this.lockButton.isLocked());
714727
compound.putInt("DisabledSlots", this.lockButton.isLocked() ? 4144959 : 0);
728+
compound.putDouble("Scale", this.sizeSlider.getValue());
715729

716730
ListTag rotationTag = new ListTag();
717731
rotationTag.add(FloatTag.valueOf(this.rotationTextField.getFloat()));

common/src/main/java/com/mrbysco/armorposer/client/gui/DeletePoseScreen.java

-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,8 @@
55
import net.minecraft.client.gui.GuiGraphics;
66
import net.minecraft.client.gui.components.Button;
77
import net.minecraft.client.gui.screens.Screen;
8-
import net.minecraft.nbt.CompoundTag;
9-
import net.minecraft.nbt.TagParser;
108
import net.minecraft.network.chat.CommonComponents;
119
import net.minecraft.network.chat.Component;
12-
import net.minecraft.world.entity.EntityType;
13-
import net.minecraft.world.entity.decoration.ArmorStand;
14-
import net.minecraft.world.level.Level;
15-
16-
import java.util.function.Function;
1710

1811
public class DeletePoseScreen extends Screen {
1912
private final ArmorStandScreen parentScreen;

common/src/main/java/com/mrbysco/armorposer/client/gui/widgets/ArmorGlowWidget.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ArmorGlowWidget(ArmorGlowScreen parent, Component title, int listWidth, i
2424
this.title = title;
2525
this.listWidth = listWidth;
2626
this.refreshList();
27-
this.setRenderBackground(false);
27+
// this.setRenderBackground(false);
2828
}
2929

3030
@Override
@@ -58,7 +58,7 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
5858

5959
public class ListEntry extends Entry<ListEntry> {
6060
private final ArmorGlowScreen parent;
61-
private ArmorStand armorStand;
61+
private final ArmorStand armorStand;
6262

6363
ListEntry(ArmorStand armorStand, ArmorGlowScreen parent) {
6464
this.armorStand = armorStand;

common/src/main/java/com/mrbysco/armorposer/client/gui/widgets/PoseListWidget.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public PoseListWidget(ArmorPosesScreen parent, Component title, boolean user, in
3333
this.title = title;
3434
this.listWidth = listWidth;
3535
this.refreshList(user);
36-
this.setRenderBackground(false);
36+
// this.setRenderBackground(false);
3737
}
3838

3939
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package com.mrbysco.armorposer.client.gui.widgets;
2+
3+
import com.mrbysco.armorposer.client.gui.ArmorStandScreen;
4+
import net.minecraft.client.gui.Font;
5+
import net.minecraft.client.gui.GuiGraphics;
6+
import net.minecraft.client.gui.components.AbstractSliderButton;
7+
import net.minecraft.client.gui.screens.Screen;
8+
import net.minecraft.network.chat.CommonComponents;
9+
import net.minecraft.network.chat.Component;
10+
import net.minecraft.util.Mth;
11+
12+
import java.text.DecimalFormat;
13+
14+
public class SizeSlider extends AbstractSliderButton {
15+
private final ArmorStandScreen screen;
16+
private final double minValue;
17+
private final double maxValue;
18+
protected double stepSize;
19+
private final DecimalFormat format = new DecimalFormat("0.00");
20+
21+
public SizeSlider(int x, int y, int width, double value, double minValue, double maxValue, ArmorStandScreen screen) {
22+
super(x, y, width, 16, CommonComponents.EMPTY, 0.0);
23+
this.minValue = minValue;
24+
this.maxValue = maxValue;
25+
this.screen = screen;
26+
this.stepSize = 0.01D;
27+
this.value = (Mth.clamp((float) value, minValue, maxValue) - minValue) / (maxValue - minValue);
28+
29+
this.updateMessage();
30+
}
31+
32+
@Override
33+
protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) {
34+
super.onDrag(mouseX, mouseY, dragX, dragY);
35+
this.setValueFromMouse(mouseX);
36+
}
37+
38+
@Override
39+
public boolean mouseScrolled(double mouseX, double mouseY, double xScroll, double yScroll) {
40+
if (isHovered()) {
41+
double increment = Screen.hasShiftDown() ? 0.01D : 0.001D;
42+
this.setSliderValue(this.value + (yScroll < 0 ? -increment : increment));
43+
}
44+
return super.mouseScrolled(mouseX, mouseY, xScroll, yScroll);
45+
}
46+
47+
private void setValueFromMouse(double mouseX) {
48+
this.setSliderValue((mouseX - (this.getX() + 4)) / (this.width - 8));
49+
}
50+
51+
private void setSliderValue(double value) {
52+
double oldValue = this.value;
53+
this.value = this.snapToNearest(value);
54+
if (!Mth.equal(oldValue, this.value))
55+
this.applyValue();
56+
57+
this.updateMessage();
58+
}
59+
60+
private double snapToNearest(double value) {
61+
if (stepSize <= 0D)
62+
return Mth.clamp(value, 0D, 1D);
63+
64+
value = Mth.lerp(Mth.clamp(value, 0D, 1D), this.minValue, this.maxValue);
65+
66+
value = (stepSize * Math.round(value / stepSize));
67+
68+
if (this.minValue > this.maxValue) {
69+
value = Mth.clamp(value, this.maxValue, this.minValue);
70+
} else {
71+
value = Mth.clamp(value, this.minValue, this.maxValue);
72+
}
73+
74+
return Mth.map(value, this.minValue, this.maxValue, 0D, 1D);
75+
}
76+
77+
@Override
78+
protected void applyValue() {
79+
this.screen.updateScale();
80+
}
81+
82+
@Override
83+
public void onRelease(double d, double e) {
84+
super.onRelease(d, e);
85+
}
86+
87+
@Override
88+
protected void renderScrollingString(GuiGraphics guiGraphics, Font font, int i, int j) {
89+
super.renderScrollingString(guiGraphics, font, i, j);
90+
}
91+
92+
public double getValue() {
93+
return this.value * (maxValue - minValue) + minValue;
94+
}
95+
96+
public String getValueString() {
97+
return this.format.format(this.getValue());
98+
}
99+
100+
@Override
101+
protected void updateMessage() {
102+
this.setMessage(Component.literal("").append(this.getValueString()));
103+
// this.setMessage(
104+
// CommonComponents.optionNameValue(
105+
// RealmsSlotOptionsScreen.SPAWN_PROTECTION_TEXT,
106+
// (Component)(RealmsSlotOptionsScreen.this.spawnProtection == 0
107+
// ? CommonComponents.OPTION_OFF
108+
// : Component.literal(String.valueOf(RealmsSlotOptionsScreen.this.spawnProtection)))
109+
// )
110+
// );
111+
}
112+
113+
}

common/src/main/java/com/mrbysco/armorposer/data/SwapData.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mrbysco.armorposer.data;
22

3+
import com.mrbysco.armorposer.packets.ArmorStandSwapPayload;
34
import net.minecraft.network.FriendlyByteBuf;
45
import net.minecraft.world.InteractionHand;
56
import net.minecraft.world.entity.EquipmentSlot;
@@ -9,12 +10,12 @@
910
import java.util.UUID;
1011

1112
public record SwapData(UUID entityUUID, Action action) {
12-
public void encode(FriendlyByteBuf buf) {
13+
public void write(FriendlyByteBuf buf) {
1314
buf.writeUUID(entityUUID);
1415
buf.writeEnum(action);
1516
}
1617

17-
public static SwapData decode(final FriendlyByteBuf packetBuffer) {
18+
public static SwapData read(final FriendlyByteBuf packetBuffer) {
1819
return new SwapData(packetBuffer.readUUID(), packetBuffer.readEnum(Action.class));
1920
}
2021

@@ -35,8 +36,12 @@ public void handleData(ArmorStand armorStand) {
3536
}
3637
}
3738

39+
public static void write(ArmorStandSwapPayload armorStandSwapPayload, FriendlyByteBuf buf) {
40+
41+
}
42+
3843
public static enum Action {
3944
SWAP_WITH_HEAD,
40-
SWAP_HANDS;
45+
SWAP_HANDS
4146
}
4247
}

common/src/main/java/com/mrbysco/armorposer/data/SyncData.java

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import net.minecraft.nbt.ListTag;
55
import net.minecraft.nbt.Tag;
66
import net.minecraft.network.FriendlyByteBuf;
7+
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
8+
import net.minecraft.world.entity.ai.attributes.Attributes;
79
import net.minecraft.world.entity.decoration.ArmorStand;
810

911
import java.util.UUID;
@@ -35,6 +37,14 @@ public void handleData(ArmorStand armorStand) {
3537
armorStand.setPosRaw(armorStand.getX() + x,
3638
armorStand.getY() + y,
3739
armorStand.getZ() + z);
40+
41+
double scale = tag.getDouble("Scale");
42+
if (scale > 0) {
43+
AttributeInstance attributeInstance = armorStand.getAttributes().getInstance(Attributes.SCALE);
44+
if (attributeInstance != null) {
45+
attributeInstance.setBaseValue(scale);
46+
}
47+
}
3848
}
3949
}
4050
}

forge/src/main/java/com/mrbysco/armorposer/packets/ArmorStandScreenPayload.java common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandScreenPayload.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
import com.mrbysco.armorposer.Reference;
44
import net.minecraft.network.FriendlyByteBuf;
5+
import net.minecraft.network.codec.StreamCodec;
56
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
6-
import net.minecraft.resources.ResourceLocation;
77

88
public record ArmorStandScreenPayload(int entityID) implements CustomPacketPayload {
9+
public static final StreamCodec<FriendlyByteBuf, ArmorStandScreenPayload> CODEC = CustomPacketPayload.codec(
10+
ArmorStandScreenPayload::write,
11+
ArmorStandScreenPayload::new);
12+
public static final Type<ArmorStandScreenPayload> ID = CustomPacketPayload.createType(Reference.SCREEN_PACKET_ID.toString());
13+
914
public ArmorStandScreenPayload(final FriendlyByteBuf packetBuffer) {
1015
this(packetBuffer.readInt());
1116
}
@@ -15,7 +20,7 @@ public void write(FriendlyByteBuf buf) {
1520
}
1621

1722
@Override
18-
public ResourceLocation id() {
19-
return Reference.SCREEN_PACKET_ID;
23+
public Type<? extends CustomPacketPayload> type() {
24+
return ID;
2025
}
2126
}

0 commit comments

Comments
 (0)