From 6538b081f82ef9c8ba2050fae240dd0bba355461 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Wed, 14 Feb 2024 00:20:10 +0100 Subject: Added Ctrl-Click to open bazaar to the minion helper (#1011) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Ctrl-Click to open bazaar * Use max number of items for minion crafts --------- Co-authored-by: Linnea Gräf --- .../notenoughupdates/auction/APIManager.java | 2 +- .../miscgui/minionhelper/Minion.java | 41 +++++++++++++++++++++- .../render/MinionHelperOverlayHover.java | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 58d8c23b..2e65ead3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -271,7 +271,7 @@ public class APIManager { return e.getAsJsonObject(); } - private static final List hardcodedVanillaItems = Utils.createList( + public static final List hardcodedVanillaItems = Utils.createList( "WOOD_AXE", "WOOD_HOE", "WOOD_PICKAXE", "WOOD_SPADE", "WOOD_SWORD", "GOLD_AXE", "GOLD_HOE", "GOLD_PICKAXE", "GOLD_SPADE", "GOLD_SWORD", "ROOKIE_HOE" diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java index 346fbfe2..4dcb1ec2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/Minion.java @@ -20,13 +20,25 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.auction.APIManager; +import io.github.moulberry.notenoughupdates.core.util.MiscUtils; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.OverviewLine; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CraftingSource; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CustomSource; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource; +import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.item.ItemStack; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; public class Minion extends OverviewLine { private final String internalName; @@ -107,7 +119,34 @@ public class Minion extends OverviewLine { @Override public void onClick() { - NotEnoughUpdates.INSTANCE.manager.displayGuiItemRecipe(internalName); + if (Mouse.getEventButton() != 0 || !Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { + NotEnoughUpdates.INSTANCE.manager.displayGuiItemRecipe(internalName); + } else { + if (minionSource instanceof CraftingSource) { + CraftingSource craftingSource = (CraftingSource) minionSource; + Map counts = new HashMap<>(); + for (Map.Entry entry : craftingSource.getItems().entries()) { + counts.compute(entry.getKey(), (k, v) -> (v == null ? 0 : v) + entry.getValue()); + } + Optional> resource = counts + .entrySet() + .stream() + .filter(it -> !APIManager.hardcodedVanillaItems.contains(it.getKey())) + .max(Comparator.comparingInt(Map.Entry::getValue)); + if (!resource.isPresent()) return; + + String bazaarName = resource.get().getKey(); + int totalAmount = resource.get().getValue(); + + MiscUtils.copyToClipboard(String.valueOf(totalAmount)); + ItemStack itemStack = new ItemResolutionQuery(NotEnoughUpdates.INSTANCE.manager).withKnownInternalName( + bazaarName).resolveToItemStack(); + if (itemStack != null) { + String displayName = Utils.cleanColour(itemStack.getDisplayName()); + NotEnoughUpdates.INSTANCE.trySendCommand("/bz " + displayName); + } + } + } } public void setCustomSource(CustomSource customSource) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java index a3549d51..18b26754 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java @@ -196,6 +196,7 @@ public class MinionHelperOverlayHover { lines.add(""); lines.add("§eClick to view recipe!"); + lines.add("§eCtrl-Click to open bazaar!"); } return lines; } -- cgit