Skip to content

Commit

Permalink
change hovered list to map -> fix ae2 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Jul 14, 2024
1 parent be9a84a commit 87af024
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.cleanroommc.neverenoughanimations.animations;

import com.cleanroommc.neverenoughanimations.IItemLocation;
import com.cleanroommc.neverenoughanimations.NEAConfig;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -14,61 +14,57 @@
public class ItemHoverAnimation {

private static GuiContainer lastHoveredGui = null;
private static int lastHoveredSlot = -1;
private static final LongArrayList hoveredSlots = new LongArrayList(256);
private static Slot lastHoveredSlot = null;
private static final Object2LongOpenHashMap<Slot> hoveredSlots = new Object2LongOpenHashMap<>(32);

@ApiStatus.Internal
public static void onGuiOpen(GuiOpenEvent event) {
if (NEAConfig.hoverAnimationTime > 0) {
if (!(event.getGui() instanceof GuiContainer)) {
if (lastHoveredGui != null) {
lastHoveredGui = null;
lastHoveredSlot = -1;
lastHoveredSlot = null;
hoveredSlots.clear();
}
return;
}
if (!NEAConfig.isBlacklisted(event.getGui())) {
lastHoveredGui = (GuiContainer) event.getGui();
lastHoveredSlot = -1;
lastHoveredSlot = null;
hoveredSlots.clear();
}
}
}

private static void startAnimation(int slot, boolean grow) {
while (hoveredSlots.size() <= slot) {
hoveredSlots.add(0);
}
hoveredSlots.set(slot, Minecraft.getSystemTime() * (grow ? 1 : -1));
private static void startAnimation(Slot slot, boolean grow) {
hoveredSlots.put(slot, Minecraft.getSystemTime() * (grow ? 1 : -1));
}

public static boolean isAnimating(int slot) {
return hoveredSlots.size() > slot && hoveredSlots.getLong(slot) != 0;
public static boolean isAnimating(Slot slot) {
return hoveredSlots.containsKey(slot);
}

@ApiStatus.Internal
public static void onGuiTick() {
if (NEAConfig.hoverAnimationTime == 0 || lastHoveredGui == null) return;
IItemLocation hoveredSlot = IItemLocation.of(lastHoveredGui.getSlotUnderMouse());
if (lastHoveredSlot >= 0 && (hoveredSlot == null || hoveredSlot.nea$getSlotNumber() != lastHoveredSlot)) {
Slot hoveredSlot = lastHoveredGui.getSlotUnderMouse();
if (lastHoveredSlot != null && (hoveredSlot == null || hoveredSlot != lastHoveredSlot)) {
// last slot is no longer hovered
startAnimation(lastHoveredSlot, false);
}
if (hoveredSlot != null) {
lastHoveredSlot = hoveredSlot.nea$getSlotNumber();
if (!isAnimating(hoveredSlot.nea$getSlotNumber())) {
lastHoveredSlot = hoveredSlot;
if (!isAnimating(hoveredSlot)) {
// started hovering
startAnimation(hoveredSlot.nea$getSlotNumber(), true);
startAnimation(hoveredSlot, true);
}
} else {
lastHoveredSlot = -1;
lastHoveredSlot = null;
}
}

public static float getRenderScale(GuiContainer gui, int slot) {
public static float getRenderScale(GuiContainer gui, Slot slot) {
if (lastHoveredGui != gui ||
slot >= hoveredSlots.size() ||
!isAnimating(slot) ||
NEAConfig.isBlacklisted(gui)) return 1f;
float min = 1f, max = 1.25f;
Expand All @@ -79,7 +75,7 @@ public static float getRenderScale(GuiContainer gui, int slot) {
val = 1f - val;
if (val <= 0) {
// animation ended
hoveredSlots.set(slot, 0);
hoveredSlots.removeLong(slot);
return 1f;
}
} else if (val >= 1f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void injectVirtualStack(Slot slotIn, CallbackInfo ci, @Local(ordinal = 0)
public void injectHoverScale(Slot slotIn, CallbackInfo ci) {
if (NEAConfig.hoverAnimationTime > 0) {
GlStateManager.pushMatrix();
float scale = ItemHoverAnimation.getRenderScale((GuiContainer) (Object) this, IItemLocation.of(slotIn).nea$getSlotNumber());
float scale = ItemHoverAnimation.getRenderScale((GuiContainer) (Object) this, slotIn);
if (scale > 1f) {
int x = slotIn.xPos;
int y = slotIn.yPos;
Expand Down

0 comments on commit 87af024

Please sign in to comment.