From 428187a03cdf84756e86f3af2edd5955a0d4eea2 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Thu, 18 Jul 2024 17:12:38 +0200 Subject: [PATCH] dont scale borders of itemborders mod --- .../neverenoughanimations/NEA.java | 7 ++ .../core/mixin/GuiContainerMixin.java | 67 +++++++++++++++---- .../core/mixin/GuiIngameMixin.java | 4 +- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/cleanroommc/neverenoughanimations/NEA.java b/src/main/java/com/cleanroommc/neverenoughanimations/NEA.java index 6c902f6..e33ed9f 100644 --- a/src/main/java/com/cleanroommc/neverenoughanimations/NEA.java +++ b/src/main/java/com/cleanroommc/neverenoughanimations/NEA.java @@ -16,6 +16,7 @@ import net.minecraftforge.common.config.Config; import net.minecraftforge.common.config.ConfigManager; import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -33,11 +34,13 @@ public class NEA { public static final Logger LOGGER = LogManager.getLogger(Tags.MODID); + public static boolean itemBordersLoaded = false; private static int mouseX, mouseY; @EventHandler public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(this); + itemBordersLoaded = Loader.isModLoaded("itemborders"); } @SubscribeEvent @@ -134,4 +137,8 @@ public static void drawScreenDebug(GuiContainer container, int mouseX, int mouse GlStateManager.enableRescaleNormal(); RenderHelper.enableStandardItemLighting(); } + + public static boolean isItemBordersLoaded() { + return itemBordersLoaded; + } } diff --git a/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiContainerMixin.java b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiContainerMixin.java index 72a9688..72ec151 100644 --- a/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiContainerMixin.java +++ b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiContainerMixin.java @@ -1,11 +1,14 @@ package com.cleanroommc.neverenoughanimations.core.mixin; import com.cleanroommc.neverenoughanimations.IItemLocation; +import com.cleanroommc.neverenoughanimations.NEA; import com.cleanroommc.neverenoughanimations.NEAConfig; import com.cleanroommc.neverenoughanimations.animations.ItemHoverAnimation; import com.cleanroommc.neverenoughanimations.animations.ItemMoveAnimation; import com.cleanroommc.neverenoughanimations.animations.ItemPickupThrowAnimation; import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; import com.llamalad7.mixinextras.sugar.ref.LocalRef; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; @@ -19,10 +22,11 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(GuiContainer.class) +@Mixin(value = GuiContainer.class, priority = 950) public class GuiContainerMixin extends GuiScreen { - @Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 5, shift = At.Shift.BEFORE)) + @Inject(method = "drawSlot", + at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 5, shift = At.Shift.BEFORE)) public void injectVirtualStack(Slot slotIn, CallbackInfo ci, @Local(ordinal = 0) LocalRef itemStack) { if (NEAConfig.moveAnimationTime > 0) { ItemStack virtualStack = ItemMoveAnimation.getVirtualStack((GuiContainer) (Object) this, slotIn); @@ -32,35 +36,68 @@ public void injectVirtualStack(Slot slotIn, CallbackInfo ci, @Local(ordinal = 0) } } - @Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderItem;renderItemAndEffectIntoGUI(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;II)V", shift = At.Shift.BEFORE)) - public void injectHoverScale(Slot slotIn, CallbackInfo ci) { + @Inject(method = "drawSlot", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/renderer/RenderItem;renderItemAndEffectIntoGUI(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;II)V", + shift = At.Shift.BEFORE)) + public void injectHoverScale(Slot slotIn, CallbackInfo ci, @Share("scale") LocalFloatRef scaleRef) { if (NEAConfig.hoverAnimationTime > 0) { GlStateManager.pushMatrix(); float scale = ItemHoverAnimation.getRenderScale((GuiContainer) (Object) this, slotIn); + scaleRef.set(scale); if (scale > 1f) { - int x = slotIn.xPos; - int y = slotIn.yPos; - GlStateManager.translate(x + 8, y + 8, 0); + int x = slotIn.xPos + 8; + int y = slotIn.yPos + 8; + GlStateManager.translate(x, y, 0); GlStateManager.scale(scale, scale, 1); - GlStateManager.translate(-x - 8, -y - 8, 0); + GlStateManager.translate(-x, -y, 0); } } } - @Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderItem;renderItemOverlayIntoGUI(Lnet/minecraft/client/gui/FontRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", shift = At.Shift.AFTER)) - public void endHoverScale(Slot slotIn, CallbackInfo ci) { + @Inject(method = "drawSlot", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/renderer/RenderItem;renderItemAndEffectIntoGUI(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;II)V", + shift = At.Shift.AFTER)) + public void midHoverScale(Slot slotIn, CallbackInfo ci) { + if (NEA.isItemBordersLoaded() && NEAConfig.hoverAnimationTime > 0) { + // itemborders wants to draw the borders now -> undo scale + GlStateManager.popMatrix(); + } + } + + + @Inject(method = "drawSlot", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/renderer/RenderItem;renderItemOverlayIntoGUI(Lnet/minecraft/client/gui/FontRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", + shift = At.Shift.AFTER)) + public void endHoverScale(Slot slotIn, CallbackInfo ci, @Share("scale") LocalFloatRef scaleRef) { if (NEAConfig.hoverAnimationTime == 0) return; + if (NEA.isItemBordersLoaded()) { + // itemborders did draw its borders -> reapply scale + GlStateManager.pushMatrix(); + float scale = scaleRef.get(); + if (scale > 1f) { + int x = slotIn.xPos + 8; + int y = slotIn.yPos + 8; + GlStateManager.translate(x, y, 0); + GlStateManager.scale(scale, scale, 1); + GlStateManager.translate(-x, -y, 0); + } + } GlStateManager.popMatrix(); } - @Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawGradientRect(IIIIII)V")) + @Redirect(method = "drawScreen", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawGradientRect(IIIIII)V")) public void dontDrawOverlay(GuiContainer instance, int i1, int i2, int i3, int i4, int i5, int i6) { if (NEAConfig.itemHoverOverlay) { drawGradientRect(i1, i2, i3, i4, i5, i6); } } - @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V", shift = At.Shift.BEFORE)) + @Inject(method = "drawScreen", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V", shift = At.Shift.BEFORE)) public void drawMovingItems(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { zLevel = 200; itemRender.zLevel = 200; @@ -70,7 +107,11 @@ public void drawMovingItems(int mouseX, int mouseY, float partialTicks, Callback zLevel = 0; } - @ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawItemStack(Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", ordinal = 0), index = 0) + @ModifyArg(method = "drawScreen", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawItemStack(Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", + ordinal = 0), + index = 0) public ItemStack injectVirtualCursorStack(ItemStack stack) { if (NEAConfig.moveAnimationTime > 0) { ItemStack virtual = ItemMoveAnimation.getVirtualStack((GuiContainer) (Object) this, IItemLocation.CURSOR); diff --git a/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiIngameMixin.java b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiIngameMixin.java index f6d4811..5d802d8 100644 --- a/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiIngameMixin.java +++ b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiIngameMixin.java @@ -12,7 +12,9 @@ @Mixin(GuiIngame.class) public class GuiIngameMixin extends Gui { - @ModifyArg(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiIngame;drawTexturedModalRect(IIIIII)V", ordinal = 1), index = 0) + @ModifyArg(method = "renderHotbar", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiIngame;drawTexturedModalRect(IIIIII)V", ordinal = 1), + index = 0) public int renderCurrentItemMarker(int x, @Local(ordinal = 0, argsOnly = true) ScaledResolution sr) { return HotbarAnimation.getX(sr); }