From cd8a9514e0e3ef336e9e18c8a5f0d8a147310955 Mon Sep 17 00:00:00 2001 From: glowredman <35727266+glowredman@users.noreply.github.com> Date: Sun, 13 Oct 2024 09:51:08 +0200 Subject: [PATCH] Rework `GuiScreenMixin` (#31) * Update deps * Remove unnecessary call to `ObfuscationReflectionHelper.remapFieldNames` * Rework `GuiScreenMixin` * Apply spotless --- dependencies.gradle | 6 ++-- .../client/TooltipOverlayHandler.java | 11 ++---- .../early/minecraft/GuiScreenMixin.java | 35 +++++++++---------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 72d7249..4db340b 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,9 +1,9 @@ // Add your dependencies here dependencies { - compileOnly("com.github.GTNewHorizons:CodeChickenCore:1.3.7:dev") - compileOnly("com.github.GTNewHorizons:Natura:2.7.1:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:CodeChickenCore:1.3.9:dev") + compileOnly("com.github.GTNewHorizons:Natura:2.7.4:dev") { transitive = false } compileOnly(deobfCurse("pams-harvestcraft-221857:2270206")) - runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.34-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.42-GTNH:dev") } diff --git a/src/main/java/squeek/applecore/client/TooltipOverlayHandler.java b/src/main/java/squeek/applecore/client/TooltipOverlayHandler.java index 68de33d..af86547 100644 --- a/src/main/java/squeek/applecore/client/TooltipOverlayHandler.java +++ b/src/main/java/squeek/applecore/client/TooltipOverlayHandler.java @@ -17,7 +17,6 @@ import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ObfuscationReflectionHelper; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent; @@ -35,14 +34,8 @@ public class TooltipOverlayHandler { private static final ResourceLocation modIcons = new ResourceLocation(ModInfo.MODID_LOWER, "textures/icons.png"); - // private static final Field guiLeft = ReflectionHelper.findField(GuiContainer.class, - // ObfuscationReflectionHelper.remapFieldNames(GuiContainer.class.getName(), "guiLeft", "field_147003_i", "i")); - // private static final Field guiTop = ReflectionHelper.findField(GuiContainer.class, - // ObfuscationReflectionHelper.remapFieldNames(GuiContainer.class.getName(), "guiTop", "field_147009_r", "r")); - public static final Field theSlot = ReflectionHelper.findField( - GuiContainer.class, - ObfuscationReflectionHelper - .remapFieldNames(GuiContainer.class.getName(), "theSlot", "field_147006_u", "u")); + public static final Field theSlot = ReflectionHelper + .findField(GuiContainer.class, "theSlot", "field_147006_u", "u"); private static Method getStackMouseOver = null; private static Method isNEIHidden = null; private static Field itemPanel = null; diff --git a/src/main/java/squeek/applecore/mixins/early/minecraft/GuiScreenMixin.java b/src/main/java/squeek/applecore/mixins/early/minecraft/GuiScreenMixin.java index 82ae2c5..5a086bd 100644 --- a/src/main/java/squeek/applecore/mixins/early/minecraft/GuiScreenMixin.java +++ b/src/main/java/squeek/applecore/mixins/early/minecraft/GuiScreenMixin.java @@ -1,17 +1,14 @@ package squeek.applecore.mixins.early.minecraft; -import java.util.Iterator; -import java.util.List; - -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; +import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.llamalad7.mixinextras.sugar.Local; import squeek.applecore.client.TooltipOverlayHandler; @@ -19,19 +16,19 @@ public class GuiScreenMixin { @Inject( + at = @At( + opcode = Opcodes.PUTFIELD, + ordinal = 0, + remap = true, + target = "Lnet/minecraft/client/gui/GuiScreen;zLevel:F", + value = "FIELD"), method = "drawHoveringText", - at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", shift = At.Shift.BEFORE), - slice = @Slice( - from = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/gui/GuiScreen;drawGradientRect(IIIIII)V", - ordinal = 0)), - locals = LocalCapture.CAPTURE_FAILHARD) - private void onDrawHoveringText(List textLines, int x, int y, FontRenderer font, CallbackInfo ci, int k, - Iterator iterator, int j2, int k2, int i1, int j1, int k1, int l1, int i2) { - TooltipOverlayHandler.toolTipX = j2; - TooltipOverlayHandler.toolTipY = k2; - TooltipOverlayHandler.toolTipW = k; - TooltipOverlayHandler.toolTipH = i1; + remap = false) + private void onDrawHoveringText(CallbackInfo ci, @Local(ordinal = 3) int x, @Local(ordinal = 4) int y, + @Local(ordinal = 2) int w, @Local(ordinal = 5) int h) { + TooltipOverlayHandler.toolTipX = x; + TooltipOverlayHandler.toolTipY = y; + TooltipOverlayHandler.toolTipW = w; + TooltipOverlayHandler.toolTipH = h; } }