diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2021-06-05 00:13:59 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2021-06-05 00:14:22 +0300 |
commit | a1bb6316f2d6ecc0019e00438b4cf724dde68f73 (patch) | |
tree | 05edeedca30fa5a5a50085b594244aa66ef569cc | |
parent | 1aba27451ce4b95dc7a832938998c9d1581eee97 (diff) | |
download | LibGui-a1bb6316f2d6ecc0019e00438b4cf724dde68f73.tar.gz LibGui-a1bb6316f2d6ecc0019e00438b4cf724dde68f73.tar.bz2 LibGui-a1bb6316f2d6ecc0019e00438b4cf724dde68f73.zip |
Switch from accessor to AW, fixes #113
Accessors would be preferred but there is a mixin bug/regression
that prevents me from modifying final fields with accessors unless I do
some concerning hacky code.
8 files changed, 25 insertions, 44 deletions
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java b/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java index e0602be..e6c3564 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java @@ -18,8 +18,9 @@ public class TestDescription extends SyncedGuiDescription { super(type, syncId, playerInventory, getBlockInventory(context, GuiBlockEntity.INVENTORY_SIZE), null); WGridPanel root = (WGridPanel)this.getRootPanel(); - - root.add(WItemSlot.of(blockInventory, 0, 4, 1), 0, 1); + + WItemSlot slot = WItemSlot.of(blockInventory, 0, 4, 1); + root.add(slot, 0, 1); WButton buttonA = new WButton(new LiteralText("Button A")); @@ -45,5 +46,12 @@ public class TestDescription extends SyncedGuiDescription { ScreenNetworking.of(this, NetworkSide.SERVER).receive(TEST_MESSAGE, buf -> { System.out.println("Received on the server!"); }); + + try { + slot.onHidden(); + slot.onShown(); + } catch (Throwable t) { + throw new AssertionError("ValidatedSlot.setVisible crashed", t); + } } } diff --git a/build.gradle b/build.gradle index cfd528e..cb215c6 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,10 @@ repositories { } } +loom { + accessWidener = file('src/main/resources/libgui.accesswidener') +} + dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" diff --git a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java index aa6ae36..f51bcad 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java @@ -7,7 +7,6 @@ import net.minecraft.screen.slot.Slot; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import io.github.cottonmc.cotton.gui.impl.access.SlotAccessor; import io.github.cottonmc.cotton.gui.widget.WItemSlot; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -170,13 +169,12 @@ public class ValidatedSlot extends Slot { if (this.visible != visible) { this.visible = visible; - SlotAccessor accessor = (SlotAccessor) this; if (visible) { - accessor.setX(originalX); - accessor.setY(originalY); + x = originalX; + y = originalY; } else { - accessor.setX(-100000); - accessor.setY(-100000); + x = -100000; + y = -100000; } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/SlotAccessor.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/SlotAccessor.java deleted file mode 100644 index 4b4644c..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/SlotAccessor.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.cottonmc.cotton.gui.impl.access; - -import net.minecraft.screen.slot.Slot; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(Slot.class) -public interface SlotAccessor { - @Accessor("x") - void setX(int x); - - @Accessor("y") - void setY(int y); -} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java deleted file mode 100644 index 8f391fd..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Internal implementation classes. - */ -package io.github.cottonmc.cotton.gui.impl.access; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c6e1b4d..9431237 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,9 +22,7 @@ "client": ["io.github.cottonmc.cotton.gui.impl.client.LibGuiClient"], "modmenu": ["io.github.cottonmc.cotton.gui.impl.modmenu.ModMenuSupport"] }, - "mixins": [ - "mixins.libgui.accessors.json" - ], + "accessWidener": "libgui.accesswidener", "depends": { "fabricloader": ">=0.11.0", "fabric": "*", diff --git a/src/main/resources/libgui.accesswidener b/src/main/resources/libgui.accesswidener new file mode 100644 index 0000000..c290bc6 --- /dev/null +++ b/src/main/resources/libgui.accesswidener @@ -0,0 +1,6 @@ +accessWidener v1 named + +accessible field net/minecraft/screen/slot/Slot x I +accessible field net/minecraft/screen/slot/Slot y I +mutable field net/minecraft/screen/slot/Slot x I +mutable field net/minecraft/screen/slot/Slot y I diff --git a/src/main/resources/mixins.libgui.accessors.json b/src/main/resources/mixins.libgui.accessors.json deleted file mode 100644 index 9ec55f2..0000000 --- a/src/main/resources/mixins.libgui.accessors.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compatibilityLevel": "JAVA_8", - "minVersion": "0.7.11", - "package": "io.github.cottonmc.cotton.gui.impl.access", - "required": true, - - "mixins": [ - "SlotAccessor" - ], - - "injectors": { - "defaultRequire": 1 - } -} |