Skip to content

Commit 87af024

Browse files
committed
change hovered list to map -> fix ae2 issue
1 parent be9a84a commit 87af024

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/main/java/com/cleanroommc/neverenoughanimations/animations/ItemHoverAnimation.java

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.cleanroommc.neverenoughanimations.animations;
22

3-
import com.cleanroommc.neverenoughanimations.IItemLocation;
43
import com.cleanroommc.neverenoughanimations.NEAConfig;
5-
import it.unimi.dsi.fastutil.longs.LongArrayList;
4+
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
65
import net.minecraft.client.Minecraft;
76
import net.minecraft.client.gui.inventory.GuiContainer;
7+
import net.minecraft.inventory.Slot;
88
import net.minecraftforge.client.event.GuiOpenEvent;
99
import net.minecraftforge.fml.relauncher.Side;
1010
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -14,61 +14,57 @@
1414
public class ItemHoverAnimation {
1515

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

2020
@ApiStatus.Internal
2121
public static void onGuiOpen(GuiOpenEvent event) {
2222
if (NEAConfig.hoverAnimationTime > 0) {
2323
if (!(event.getGui() instanceof GuiContainer)) {
2424
if (lastHoveredGui != null) {
2525
lastHoveredGui = null;
26-
lastHoveredSlot = -1;
26+
lastHoveredSlot = null;
2727
hoveredSlots.clear();
2828
}
2929
return;
3030
}
3131
if (!NEAConfig.isBlacklisted(event.getGui())) {
3232
lastHoveredGui = (GuiContainer) event.getGui();
33-
lastHoveredSlot = -1;
33+
lastHoveredSlot = null;
3434
hoveredSlots.clear();
3535
}
3636
}
3737
}
3838

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

46-
public static boolean isAnimating(int slot) {
47-
return hoveredSlots.size() > slot && hoveredSlots.getLong(slot) != 0;
43+
public static boolean isAnimating(Slot slot) {
44+
return hoveredSlots.containsKey(slot);
4845
}
4946

5047
@ApiStatus.Internal
5148
public static void onGuiTick() {
5249
if (NEAConfig.hoverAnimationTime == 0 || lastHoveredGui == null) return;
53-
IItemLocation hoveredSlot = IItemLocation.of(lastHoveredGui.getSlotUnderMouse());
54-
if (lastHoveredSlot >= 0 && (hoveredSlot == null || hoveredSlot.nea$getSlotNumber() != lastHoveredSlot)) {
50+
Slot hoveredSlot = lastHoveredGui.getSlotUnderMouse();
51+
if (lastHoveredSlot != null && (hoveredSlot == null || hoveredSlot != lastHoveredSlot)) {
5552
// last slot is no longer hovered
5653
startAnimation(lastHoveredSlot, false);
5754
}
5855
if (hoveredSlot != null) {
59-
lastHoveredSlot = hoveredSlot.nea$getSlotNumber();
60-
if (!isAnimating(hoveredSlot.nea$getSlotNumber())) {
56+
lastHoveredSlot = hoveredSlot;
57+
if (!isAnimating(hoveredSlot)) {
6158
// started hovering
62-
startAnimation(hoveredSlot.nea$getSlotNumber(), true);
59+
startAnimation(hoveredSlot, true);
6360
}
6461
} else {
65-
lastHoveredSlot = -1;
62+
lastHoveredSlot = null;
6663
}
6764
}
6865

69-
public static float getRenderScale(GuiContainer gui, int slot) {
66+
public static float getRenderScale(GuiContainer gui, Slot slot) {
7067
if (lastHoveredGui != gui ||
71-
slot >= hoveredSlots.size() ||
7268
!isAnimating(slot) ||
7369
NEAConfig.isBlacklisted(gui)) return 1f;
7470
float min = 1f, max = 1.25f;
@@ -79,7 +75,7 @@ public static float getRenderScale(GuiContainer gui, int slot) {
7975
val = 1f - val;
8076
if (val <= 0) {
8177
// animation ended
82-
hoveredSlots.set(slot, 0);
78+
hoveredSlots.removeLong(slot);
8379
return 1f;
8480
}
8581
} else if (val >= 1f) {

src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/GuiContainerMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void injectVirtualStack(Slot slotIn, CallbackInfo ci, @Local(ordinal = 0)
3535
public void injectHoverScale(Slot slotIn, CallbackInfo ci) {
3636
if (NEAConfig.hoverAnimationTime > 0) {
3737
GlStateManager.pushMatrix();
38-
float scale = ItemHoverAnimation.getRenderScale((GuiContainer) (Object) this, IItemLocation.of(slotIn).nea$getSlotNumber());
38+
float scale = ItemHoverAnimation.getRenderScale((GuiContainer) (Object) this, slotIn);
3939
if (scale > 1f) {
4040
int x = slotIn.xPos;
4141
int y = slotIn.yPos;

0 commit comments

Comments
 (0)