Skip to content

Commit

Permalink
jei animation
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Jul 14, 2024
1 parent 0176648 commit f2e2f3d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
public class LateMixin implements ILateMixinLoader {

private static final String[] mods = {
"trashslot"
"trashslot",
"jei"
};

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
13 changes: 13 additions & 0 deletions src/main/resources/mixin.neverenoughanimations.jei.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit f2e2f3d

Please sign in to comment.