diff --git a/src/main/java/com/cleanroommc/neverenoughanimations/animations/OpeningAnimation.java b/src/main/java/com/cleanroommc/neverenoughanimations/animations/OpeningAnimation.java index 0a3fada..30145e2 100644 --- a/src/main/java/com/cleanroommc/neverenoughanimations/animations/OpeningAnimation.java +++ b/src/main/java/com/cleanroommc/neverenoughanimations/animations/OpeningAnimation.java @@ -1,6 +1,7 @@ package com.cleanroommc.neverenoughanimations.animations; import com.cleanroommc.neverenoughanimations.NEAConfig; +import com.cleanroommc.neverenoughanimations.util.Interpolations; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; @@ -34,23 +35,27 @@ public static void animate(GuiContainer container, boolean open) { } public static float getScale(GuiContainer container) { + float min = 0.75f, max = 1f; + return Interpolations.lerp(min, max, getValue(container)); + } + + public static float getValue(GuiContainer container) { if (shouldCloseLast) return 0.001f; if (animatedGui != container) return 1f; float val = (Minecraft.getSystemTime() - Math.abs(startTime)) / (float) NEAConfig.openingAnimationTime; - float min = 0.75f, max = 1f; if (startTime < 0) { val = 1f - val; if (val <= 0) { animatedGui = null; shouldCloseLast = true; - return min; + return 0f; } } else if (val >= 1f) { animatedGui = null; return 1f; } - return NEAConfig.openingAnimationCurve.interpolate(min, max, val); + return NEAConfig.openingAnimationCurve.interpolate(0f, 1f, val); } public static boolean handleScale(GuiContainer container, boolean translateToPanel) { diff --git a/src/main/java/com/cleanroommc/neverenoughanimations/core/LateMixin.java b/src/main/java/com/cleanroommc/neverenoughanimations/core/LateMixin.java index 0a87f09..5395dba 100644 --- a/src/main/java/com/cleanroommc/neverenoughanimations/core/LateMixin.java +++ b/src/main/java/com/cleanroommc/neverenoughanimations/core/LateMixin.java @@ -11,7 +11,8 @@ public class LateMixin implements ILateMixinLoader { private static final String[] mods = { - "trashslot" + "trashslot", + "jei" }; @Override diff --git a/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/jei/IngredientListOverlayMixin.java b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/jei/IngredientListOverlayMixin.java new file mode 100644 index 0000000..8590b46 --- /dev/null +++ b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/jei/IngredientListOverlayMixin.java @@ -0,0 +1,47 @@ +package com.cleanroommc.neverenoughanimations.core.mixin.jei; + +import com.cleanroommc.neverenoughanimations.animations.OpeningAnimation; +import mezz.jei.api.gui.IGuiProperties; +import mezz.jei.gui.overlay.IngredientListOverlay; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; +import java.awt.*; + +@Mixin(value = IngredientListOverlay.class, remap = false) +public class IngredientListOverlayMixin { + + @Shadow + @Nullable + private IGuiProperties guiProperties; + + @Shadow private Rectangle displayArea; + + @Inject(method = "drawScreen", at = @At("HEAD")) + public void drawScreenPre(Minecraft minecraft, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + if (guiProperties != null) { + GlStateManager.pushMatrix(); + GuiScreen screen = Minecraft.getMinecraft().currentScreen; + if (screen instanceof GuiContainer container) { + float val = 1f - OpeningAnimation.getValue(container); + if (val <= 0f) return; + GlStateManager.translate(displayArea.width * val, 0, 0); + } + } + } + + @Inject(method = "drawScreen", at = @At("TAIL")) + public void drawScreenPost(Minecraft minecraft, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + if (guiProperties != null) { + GlStateManager.popMatrix(); + } + } +} diff --git a/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/jei/LeftAreaDispatcherMixin.java b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/jei/LeftAreaDispatcherMixin.java new file mode 100644 index 0000000..31cf8cc --- /dev/null +++ b/src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/jei/LeftAreaDispatcherMixin.java @@ -0,0 +1,45 @@ +package com.cleanroommc.neverenoughanimations.core.mixin.jei; + +import com.cleanroommc.neverenoughanimations.animations.OpeningAnimation; +import mezz.jei.gui.overlay.bookmarks.LeftAreaDispatcher; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.awt.*; + +@Mixin(value = LeftAreaDispatcher.class, remap = false) +public abstract class LeftAreaDispatcherMixin { + + @Shadow private Rectangle displayArea; + + @Shadow private boolean canShow; + + @Shadow protected abstract boolean hasContent(); + + @Inject(method = "drawScreen", at = @At("HEAD")) + public void drawScreenPre(Minecraft minecraft, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + if (canShow && hasContent()) { + GlStateManager.pushMatrix(); + GuiScreen screen = Minecraft.getMinecraft().currentScreen; + if (screen instanceof GuiContainer container) { + float val = 1f - OpeningAnimation.getValue(container); + if (val <= 0f) return; + GlStateManager.translate(-displayArea.width * val, 0, 0); + } + } + } + + @Inject(method = "drawScreen", at = @At("TAIL")) + public void drawScreenPost(Minecraft minecraft, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + if (canShow && hasContent()) { + GlStateManager.popMatrix(); + } + } +} diff --git a/src/main/resources/mixin.neverenoughanimations.jei.json b/src/main/resources/mixin.neverenoughanimations.jei.json new file mode 100644 index 0000000..8f0d279 --- /dev/null +++ b/src/main/resources/mixin.neverenoughanimations.jei.json @@ -0,0 +1,13 @@ +{ + "package": "com.cleanroommc.neverenoughanimations.core.mixin.jei", + "refmap": "mixins.neverenoughanimations.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "client": [ + ], + "mixins": [ + "IngredientListOverlayMixin", + "LeftAreaDispatcherMixin" + ] +} \ No newline at end of file