aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-07-14 02:20:08 +1000
committerGitHub <noreply@github.com>2024-07-13 18:20:08 +0200
commit1e587bdb6003b0beffa0c554582fbd846c314954 (patch)
treee97c4105a6a027e2e92d12922039c7f320aea8a3
parent821c177944db38d038f635d2ba499392265a02eb (diff)
downloadnotenoughupdates-1e587bdb6003b0beffa0c554582fbd846c314954.tar.gz
notenoughupdates-1e587bdb6003b0beffa0c554582fbd846c314954.tar.bz2
notenoughupdates-1e587bdb6003b0beffa0c554582fbd846c314954.zip
Add support for ah/bz keybind in custom menus (#1241)
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java22
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AhBzKeybind.java61
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java3
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java31
4 files changed, 90 insertions, 27 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
index d5ffc790..35cbf8c6 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
@@ -34,7 +34,7 @@ import io.github.moulberry.notenoughupdates.mbgui.MBAnchorPoint;
import io.github.moulberry.notenoughupdates.mbgui.MBGuiElement;
import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupAligned;
import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupFloating;
-import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning;
+import io.github.moulberry.notenoughupdates.miscfeatures.AhBzKeybind;
import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers;
import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu;
import io.github.moulberry.notenoughupdates.miscgui.NeuSearchCalculator;
@@ -1219,22 +1219,14 @@ public class NEUOverlay extends Gui {
NotEnoughUpdates.INSTANCE.config.ahGraph.graphEnabled) {
NotEnoughUpdates.INSTANCE.openGui = new GuiPriceGraph(internalname.get());
return true;
- } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.openAHKeybind &&
- CookieWarning.hasActiveBoosterCookie()) {
+ } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.openAHKeybind) {
String displayName = item.get("displayname").getAsString();
-
- String cleanName = Utils.cleanColour(displayName).replace("[Lvl {LVL}]", "]").trim();
-
- if (displayName.endsWith("Enchanted Book")) {
- String loreName = Utils.cleanColour(item.getAsJsonArray("lore").get(0).getAsString());
-
- String bookName = loreName.substring(0, loreName.lastIndexOf(' '));
- NotEnoughUpdates.INSTANCE.trySendCommand("/bz " + bookName);
- } else if (NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname.get()) == null) {
- NotEnoughUpdates.INSTANCE.trySendCommand("/ahs " + cleanName);
- } else {
- NotEnoughUpdates.INSTANCE.trySendCommand("/bz " + cleanName);
+ JsonArray lore = item.getAsJsonArray("lore");
+ List<String> loreList = new ArrayList<>();
+ for (int i = 0; i < lore.size(); i++) {
+ loreList.add(lore.get(i).getAsString());
}
+ AhBzKeybind.onKeyPressed(displayName, loreList, internalname.get());
} else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.openSkyBlockRecipeKeybind
&& !item.has("vanilla")
&& StreamExtL.filterIsInstance(
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AhBzKeybind.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AhBzKeybind.java
new file mode 100644
index 00000000..a577f040
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AhBzKeybind.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2024 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.miscfeatures;
+
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery;
+import io.github.moulberry.notenoughupdates.util.ItemUtils;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.item.ItemStack;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public class AhBzKeybind {
+ public static void onKeyPressed(String displayName, List<String> lore, String internalName) {
+ if (!CookieWarning.hasActiveBoosterCookie()) return;
+
+ String cleanName = Utils.cleanColour(displayName).replace("[Lvl {LVL}]", "]").trim();
+
+ if (displayName.endsWith("Enchanted Book") && lore != null) {
+ String loreName = Utils.cleanColour(lore.get(0));
+
+ String bookName = loreName.substring(0, loreName.lastIndexOf(' '));
+ NotEnoughUpdates.INSTANCE.trySendCommand("/bz " + bookName);
+ } else if (NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName) == null) {
+ NotEnoughUpdates.INSTANCE.trySendCommand("/ahs " + cleanName);
+ } else {
+ NotEnoughUpdates.INSTANCE.trySendCommand("/bz " + cleanName);
+ }
+ }
+
+ public static void onKeyPressed(ItemStack hoveredStack) {
+ if (hoveredStack != null) {
+ String displayName = hoveredStack.getDisplayName();
+ List<@NotNull String> lore = ItemUtils.getLore(hoveredStack);
+ ItemResolutionQuery query =
+ NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(hoveredStack);
+ String internalName = query.resolveInternalName();
+ if (displayName != null) {
+ onKeyPressed(displayName, lore, internalName);
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
index dcc6c629..54f46f22 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java
@@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.TooltipTextScrolling;
import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils;
+import io.github.moulberry.notenoughupdates.miscfeatures.AhBzKeybind;
import io.github.moulberry.notenoughupdates.recipes.NeuRecipe;
import io.github.moulberry.notenoughupdates.recipes.RecipeHistory;
import io.github.moulberry.notenoughupdates.recipes.RecipeSlot;
@@ -253,6 +254,8 @@ public class GuiItemRecipe extends GuiScreen {
manager.displayGuiItemRecipe(manager.getInternalNameForItem(itemStack));
} else if (keyPressed == manager.keybindViewUsages.getKeyCode()) {
manager.displayGuiItemUsages(manager.getInternalNameForItem(itemStack));
+ } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.openAHKeybind) {
+ AhBzKeybind.onKeyPressed(itemStack);
}
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java
index 4ca5e764..d56faa63 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java
@@ -30,6 +30,7 @@ import io.github.moulberry.notenoughupdates.core.GuiElement;
import io.github.moulberry.notenoughupdates.core.GuiElementTextField;
import io.github.moulberry.notenoughupdates.core.config.KeybindHelper;
import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger;
+import io.github.moulberry.notenoughupdates.miscfeatures.AhBzKeybind;
import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers;
import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking;
import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager;
@@ -2128,29 +2129,35 @@ public class StorageOverlay extends GuiElement {
if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true;
GuiContainer container = (GuiContainer) Minecraft.getMinecraft().currentScreen;
- if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
+ int keyPressed = Keyboard.getEventKey();
+ if (keyPressed == Keyboard.KEY_ESCAPE) {
clearSearch();
return false;
}
- if (Keyboard.getEventKey() == Minecraft.getMinecraft().gameSettings.keyBindScreenshot.getKeyCode()) {
+ if (keyPressed == Minecraft.getMinecraft().gameSettings.keyBindScreenshot.getKeyCode()) {
return false;
}
- if (Keyboard.getEventKey() == Minecraft.getMinecraft().gameSettings.keyBindFullscreen.getKeyCode()) {
+ if (keyPressed == Minecraft.getMinecraft().gameSettings.keyBindFullscreen.getKeyCode()) {
return false;
}
if (!searchBar.getFocus() && !renameStorageField.getFocus() &&
- (Keyboard.getEventKey() == manager.keybindViewRecipe.getKeyCode() ||
- Keyboard.getEventKey() == manager.keybindViewUsages.getKeyCode())) {
+ (keyPressed == manager.keybindViewRecipe.getKeyCode() ||
+ keyPressed == manager.keybindViewUsages.getKeyCode() ||
+ keyPressed == NotEnoughUpdates.INSTANCE.config.misc.openAHKeybind)) {
for (Slot slot : container.inventorySlots.inventorySlots) {
if (slot != null && ((AccessorGuiContainer) container).doIsMouseOverSlot(slot, mouseX, mouseY)) {
+ ItemStack stack = slot.getStack();
String internalName =
- manager.createItemResolutionQuery().withItemStack(slot.getStack()).resolveInternalName();
+ manager.createItemResolutionQuery().withItemStack(stack).resolveInternalName();
if (internalName == null) continue;
JsonObject item = manager.getItemInformation().get(internalName);
- if (Keyboard.getEventKey() == manager.keybindViewRecipe.getKeyCode()) manager.showRecipe(item);
- if (Keyboard.getEventKey() == manager.keybindViewUsages.getKeyCode()) manager.displayGuiItemUsages(
+ if (keyPressed == manager.keybindViewRecipe.getKeyCode()) manager.showRecipe(item);
+ if (keyPressed == manager.keybindViewUsages.getKeyCode()) manager.displayGuiItemUsages(
internalName);
+ if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.openAHKeybind) {
+ AhBzKeybind.onKeyPressed(stack);
+ }
}
}
}
@@ -2170,7 +2177,7 @@ public class StorageOverlay extends GuiElement {
}
if (editingNameId >= 0) {
- if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) {
+ if (keyPressed == Keyboard.KEY_RETURN) {
editingNameId = -1;
return true;
}
@@ -2178,7 +2185,7 @@ public class StorageOverlay extends GuiElement {
String prevText = renameStorageField.getText();
renameStorageField.setFocus(true);
searchBar.setFocus(false);
- renameStorageField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
+ renameStorageField.keyTyped(Keyboard.getEventCharacter(), keyPressed);
if (!prevText.equals(renameStorageField.getText())) {
StorageManager.StoragePage page = StorageManager.getInstance().getPage(editingNameId, false);
if (page != null) {
@@ -2190,7 +2197,7 @@ public class StorageOverlay extends GuiElement {
String prevText = searchBar.getText();
searchBar.setFocus(true);
renameStorageField.setFocus(false);
- searchBar.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
+ searchBar.keyTyped(Keyboard.getEventCharacter(), keyPressed);
if (!prevText.equals(searchBar.getText())) {
StorageManager.getInstance().searchDisplay(searchBar.getText());
dirty = true;
@@ -2199,7 +2206,7 @@ public class StorageOverlay extends GuiElement {
searchBar.getText().isEmpty()) {
searchBar.setFocus(false);
}
- } else return Keyboard.getEventKey() != Minecraft.getMinecraft().gameSettings.keyBindInventory.getKeyCode();
+ } else return keyPressed != Minecraft.getMinecraft().gameSettings.keyBindInventory.getKeyCode();
}