From 4656db6f9eeb7912715fbae25384af2add19f622 Mon Sep 17 00:00:00 2001 From: heyngra Date: Mon, 10 Jul 2023 16:29:21 +0200 Subject: Add garden copper to coins tooltip (#756) * Add copper to coins converter * i accidentally ctrl+z'd a bit too much * Fix bug with ignoring AH * make it compatibile with skyhanni * use repo instead of enum requires https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO/pull/952 * Change isWorthless to cost threshold * change return type, use repositoryreloadevent and also change variable names --- .../miscfeatures/GardenNpcPrices.java | 60 ++++++++++++++++++++-- .../options/seperateSections/TooltipTweaks.java | 39 ++++++++++++++ 2 files changed, 95 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/GardenNpcPrices.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/GardenNpcPrices.java index 294194b9..d08cb1a5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/GardenNpcPrices.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/GardenNpcPrices.java @@ -19,10 +19,16 @@ package io.github.moulberry.notenoughupdates.miscfeatures; +import com.google.common.reflect.TypeToken; +import com.google.gson.GsonBuilder; +import com.google.gson.Gson; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; +import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent; import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery; import io.github.moulberry.notenoughupdates.util.Utils; +import lombok.Data; +import lombok.NoArgsConstructor; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraftforge.event.entity.player.ItemTooltipEvent; @@ -30,22 +36,41 @@ import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; + @NEUAutoSubscribe public class GardenNpcPrices { - private final Pattern itemRegex = Pattern.compile("§5§o §.([a-zA-Z \\-]+)(?:§8x(\\d+))?"); + private final Gson gson = new GsonBuilder().create(); + @Data @NoArgsConstructor public class SkyMartItem { + String currency; + double price; + String display; + } //§5§o §aEnchanted Cactus Green §8x421 //§5§o §aEnchanted Hay Bale §8x62 //§5§o §9Enchanted Cookie §8x4 //§5§o §9Tightly-Tied Hay Bale - + private final Pattern copperRegex = Pattern.compile(".* §8\\+§c(\\d+) Copper.*"); + //§5§o §8+§c24 Copper + //§5§o §8+§c69 Copper + //§5§o §8+§cNaN Copper private Map, List> prices = new HashMap<>(); + private Map skymart = null; + @SubscribeEvent + public void onRepoReload(RepositoryReloadEvent reload) { + skymart = gson.fromJson( + Utils.getConstant("skymart", NotEnoughUpdates.INSTANCE.manager.gson), + new TypeToken>() {}.getType() + ); + } @SubscribeEvent public void onGardenNpcPrices(ItemTooltipEvent event) { @@ -60,10 +85,20 @@ public class GardenNpcPrices { if (matcher.matches()) { int amount = 1; if (matcher.group(2) != null) amount = Integer.parseInt(matcher.group(2)); - double cost = calculateCost(ItemResolutionQuery.findInternalNameByDisplayName(matcher.group(1).trim(), false), amount); event.toolTip.set(i, event.toolTip.get(i) + " §7(§6" + (cost == 0 ? "?" : Utils.shortNumberFormat(cost, 0)) + "§7 coins)"); - } else { + } + + else if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.copperCoins) { + Matcher copperMatcher = copperRegex.matcher(event.toolTip.get(i)); + if (copperMatcher.matches()) { + int amount = Integer.parseInt(copperMatcher.group(1)); + net.minecraft.util.Tuple copperMax = calculateCopper(amount); + event.toolTip.set(i, event.toolTip.get(i) + " §7(§6" + Utils.shortNumberFormat((Double) copperMax.getSecond(), 0) + "§7 selling "+copperMax.getFirst()+"§7)"); + } + } + + else { prices.put(tooltipCopy, event.toolTip); } } @@ -72,6 +107,23 @@ public class GardenNpcPrices { event.toolTip.addAll(prices.get(tooltipCopy)); } } + + public net.minecraft.util.Tuple calculateCopper(int amount) { + if (skymart == null) {return new net.minecraft.util.Tuple("NEU REPO error", 0d);}; + Map prices = new HashMap<>(); + for (Map.Entry entry : skymart.entrySet()) { + String internalName = entry.getKey(); + SkyMartItem item = entry.getValue(); + if (!Objects.equals(item.currency, "copper")) continue; + boolean isBazaar = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName)!=null; + if (!isBazaar&&(NotEnoughUpdates.INSTANCE.config.tooltipTweaks.ignoreAllAHItems||item.price<=NotEnoughUpdates.INSTANCE.config.tooltipTweaks.AHPriceIgnoreThreshold)) continue; + double price = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarOrBin(internalName, false) /item.price*amount; + prices.put(item.display, price); + } + Map.Entry maxPrice = Collections.max(prices.entrySet(), Map.Entry.comparingByValue()); + return new net.minecraft.util.Tuple(maxPrice.getKey(), maxPrice.getValue()); + } + public double calculateCost(String internalName, int amount) { double price = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarOrBin(internalName, false); if (price != -1) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java index a3e0adb5..078a8a90 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java @@ -306,11 +306,50 @@ public class TooltipTweaks { @ConfigEditorBoolean public boolean essencePriceInEssenceShop = true; + @ConfigOption( + name = "Garden Visitors", + desc = "" + ) + @ConfigEditorAccordion(id = 2) + public boolean gardenVisitors = false; + @Expose @ConfigOption( name = "Item Cost in Garden NPC", desc = "Show the item cost in garden NPC shop" ) @ConfigEditorBoolean + @ConfigAccordionId(id = 2) public boolean gardenNpcPrice = true; + + @Expose + @ConfigOption( + name = "Copper value", + desc = "Calculate how much coins is a copper worth" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 2) + public boolean copperCoins = true; + + + @Expose + @ConfigOption( + name = "AH items cost threshold", + desc = "Ignore AH items that cost less or equal copper than" + ) + @ConfigEditorSlider( + minValue = 0f, + maxValue = 500f, + minStep = 5f + ) + @ConfigAccordionId(id = 2) + public double AHPriceIgnoreThreshold = 0; + @Expose + @ConfigOption( + name = "Ignore AH items", + desc = "Ignore ALL items that can be sold to AH" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 2) + public boolean ignoreAllAHItems = true; } -- cgit