Skip to content

Commit

Permalink
dont scale borders of itemborders mod
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Jul 18, 2024
1 parent f799520 commit 428187a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/cleanroommc/neverenoughanimations/NEA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -134,4 +137,8 @@ public static void drawScreenDebug(GuiContainer container, int mouseX, int mouse
GlStateManager.enableRescaleNormal();
RenderHelper.enableStandardItemLighting();
}

public static boolean isItemBordersLoaded() {
return itemBordersLoaded;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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> itemStack) {
if (NEAConfig.moveAnimationTime > 0) {
ItemStack virtualStack = ItemMoveAnimation.getVirtualStack((GuiContainer) (Object) this, slotIn);
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 428187a

Please sign in to comment.