From 4c24769b971cb9ed6d6edf267aeebf1a8fe45766 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Wed, 6 Mar 2024 21:05:18 +0100 Subject: Made shift in sacks show the stored amount as the price (#1037) --- .../notenoughupdates/ItemPriceInformation.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java index c149cfe2..cd756a88 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java @@ -28,6 +28,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumTooltip import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.hypixelapi.HypixelItemAPI; +import lombok.val; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import org.lwjgl.input.Keyboard; @@ -48,6 +49,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.regex.Pattern; public class ItemPriceInformation { private static File file; @@ -56,6 +58,9 @@ public class ItemPriceInformation { private static final NumberFormat format = new DecimalFormat("#,##0.#", new DecimalFormatSymbols(Locale.US)); public static String STACKSIZE_OVERRIDE = "NEU_STACKSIZE_OVERRIDE"; + private static final Pattern SACK_STORED_AMOUNT = Pattern.compile( + ".*Stored: §.(?[\\d,]+)§.\\/.*"); + public static void addToTooltip(List tooltip, String internalName, ItemStack stack) { addToTooltip(tooltip, internalName, stack, true); } @@ -130,6 +135,20 @@ public class ItemPriceInformation { shiftStackMultiplier = stack.getTagCompound().getInteger(STACKSIZE_OVERRIDE); } int stackMultiplier = 1; + for (int i = 3; i < tooltip.size(); i++) { + val matcher = SACK_STORED_AMOUNT.matcher(tooltip.get(i)); + if (matcher.matches()) { + String amountString = matcher.group("amount").replace(",", ""); + try { + int parsedValue = Integer.parseInt(amountString); + if (parsedValue != 0) { + shiftStackMultiplier = parsedValue; + } + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } boolean shiftPressed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); if (shiftPressed) { stackMultiplier = shiftStackMultiplier; -- cgit