From c9ddb1bc0a23cf8dea4bb4af216b39a3323a1ceb Mon Sep 17 00:00:00 2001 From: viciscat <51047087+viciscat@users.noreply.github.com> Date: Thu, 24 Jul 2025 21:19:08 +0200 Subject: use longs to prevent overflow (#1527) --- .../hysky/skyblocker/skyblock/garden/FarmingHud.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java index 3d831f66..d5946166 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java @@ -9,8 +9,8 @@ import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; import it.unimi.dsi.fastutil.floats.FloatLongPair; -import it.unimi.dsi.fastutil.ints.IntLongPair; import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue; +import it.unimi.dsi.fastutil.longs.LongLongPair; import it.unimi.dsi.fastutil.longs.LongPriorityQueue; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; @@ -44,7 +44,7 @@ public class FarmingHud { private static final Pattern FARMING_XP = Pattern.compile("\\+(?\\d+(?:\\.\\d+)?) Farming \\((?[\\d,]+(?:\\.\\d+)?%|[\\d,]+/[\\d,]+)\\)"); private static final MinecraftClient client = MinecraftClient.getInstance(); private static CounterType counterType = CounterType.NONE; - private static final Deque counter = new ArrayDeque<>(); + private static final Deque counter = new ArrayDeque<>(); private static final LongPriorityQueue blockBreaks = new LongArrayFIFOQueue(); private static final Queue farmingXp = new ArrayDeque<>(); private static float farmingXpPercentProgress; @@ -97,13 +97,13 @@ public class FarmingHud { private static boolean tryGetCounter(ItemStack stack, CounterType counterType) { NbtCompound customData = ItemUtils.getCustomData(stack); if (customData.isEmpty() || !(customData.get(counterType.nbtKey) instanceof AbstractNbtNumber)) return true; - int count = customData.getInt(counterType.nbtKey, 0); + long count = customData.getLong(counterType.nbtKey, 0); if (FarmingHud.counterType != counterType) { counter.clear(); FarmingHud.counterType = counterType; } - if (counter.isEmpty() || counter.peekLast().leftInt() != count) { - counter.offer(IntLongPair.of(count, System.currentTimeMillis())); + if (counter.isEmpty() || counter.peekLast().leftLong() != count) { + counter.offer(LongLongPair.of(count, System.currentTimeMillis())); } return false; } @@ -116,17 +116,17 @@ public class FarmingHud { return counterType.text; } - public static int counter() { - return counter.isEmpty() ? 0 : counter.peekLast().leftInt(); + public static long counter() { + return counter.isEmpty() ? 0 : counter.peekLast().leftLong(); } public static float cropsPerMinute() { if (counter.isEmpty()) { return 0; } - IntLongPair first = counter.peek(); - IntLongPair last = counter.peekLast(); - return (float) (last.leftInt() - first.leftInt()) / (last.rightLong() - first.rightLong()) * 60_000f; + LongLongPair first = counter.peek(); + LongLongPair last = counter.peekLast(); + return (float) (last.leftLong() - first.leftLong()) / (last.rightLong() - first.rightLong()) * 60_000f; } public static double blockBreaks() { -- cgit