From 9696338aa62f5eb4a1cecdcb99dd720c0839c417 Mon Sep 17 00:00:00 2001 From: viciscat <51047087+viciscat@users.noreply.github.com> Date: Wed, 31 Jul 2024 20:18:20 +0200 Subject: รน MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../de/hysky/skyblocker/skyblock/ChestValue.java | 38 ++++++++++------------ 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java b/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java index 861bf0c4..0c908b5f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java @@ -26,6 +26,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Util; import net.minecraft.util.math.MathHelper; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -166,34 +167,21 @@ public class ChestValue { try { double value = 0; boolean hasIncompleteData = false; - List slots; - if (minion) { - slots = handler.slots.subList(0, handler.getRows() * 9).stream().filter(slot -> { - int x = slot.id % 9; - int y = slot.id / 9; - return x > 2 && x < 8 && y > 1 && y < 5; - }).toList(); - ItemStack stack; - String coinsLine; - if (handler.slots.size() > 28 && - (stack = handler.slots.get(28).getStack()).isOf(Items.HOPPER) && - (coinsLine = ItemUtils.getLoreLineIf(stack, s -> s.contains("Held Coins:"))) != null) { + List slots = minion ? getMinionSlots(handler) : handler.slots.subList(0, handler.getRows() * 9); + for (Slot slot : slots) { + ItemStack stack = slot.getStack(); + if (stack.isEmpty()) { + continue; + } + String coinsLine; + if (minion && slot.id == 28 && stack.isOf(Items.HOPPER) && (coinsLine = ItemUtils.getLoreLineIf(stack, s -> s.contains("Held Coins:"))) != null) { String source = coinsLine.split(":")[1]; try { value += DecimalFormat.getNumberInstance(java.util.Locale.US).parse(source.trim()).doubleValue(); } catch (ParseException e) { LOGGER.warn("[Skyblocker] Failed to parse {}", source); } - - } - } else { - slots = handler.slots.subList(0, handler.getRows() * 9); - } - - for (Slot slot : slots) { - ItemStack stack = slot.getStack(); - if (stack.isEmpty()) { continue; } @@ -216,6 +204,14 @@ public class ChestValue { return null; } + private static @NotNull List getMinionSlots(GenericContainerScreenHandler handler) { + return handler.slots.subList(0, handler.getRows() * 9).stream().filter(slot -> { + int x = slot.id % 9; + int y = slot.id / 9; + return x > 2 && x < 8 && y > 1 && y < 5 || slot.id == 28; + }).toList(); + } + /** * Searches for a specific string of characters in the name and lore of an item */ -- cgit