11package com .cleanroommc .neverenoughanimations .animations ;
22
3- import com .cleanroommc .neverenoughanimations .IItemLocation ;
43import com .cleanroommc .neverenoughanimations .NEAConfig ;
5- import it .unimi .dsi .fastutil .longs . LongArrayList ;
4+ import it .unimi .dsi .fastutil .objects . Object2LongOpenHashMap ;
65import net .minecraft .client .Minecraft ;
76import net .minecraft .client .gui .inventory .GuiContainer ;
7+ import net .minecraft .inventory .Slot ;
88import net .minecraftforge .client .event .GuiOpenEvent ;
99import net .minecraftforge .fml .relauncher .Side ;
1010import net .minecraftforge .fml .relauncher .SideOnly ;
1414public 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 ) {
0 commit comments