aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-08-04 00:23:44 +1000
committerGitHub <noreply@github.com>2024-08-04 00:23:44 +1000
commite41c1694d0c6bd47f35ebcb8bdd3492d686559bc (patch)
tree1b88addb0c5b50162300690ed712261002836bd8
parentd8e03fcbf5ae144f62c376a838a06b21afe2365c (diff)
downloadnotenoughupdates-e41c1694d0c6bd47f35ebcb8bdd3492d686559bc.tar.gz
notenoughupdates-e41c1694d0c6bd47f35ebcb8bdd3492d686559bc.tar.bz2
notenoughupdates-e41c1694d0c6bd47f35ebcb8bdd3492d686559bc.zip
Add client side ah/bz search guis (#1248)
Co-authored-by: Lulonaut <lulonaut@lulonaut.dev>
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java34
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/AHTweaks.java8
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java136
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java137
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SearchCommand.kt74
5 files changed, 178 insertions, 211 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
index 4794b6e7..4e743b50 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -45,8 +45,6 @@ import io.github.moulberry.notenoughupdates.miscgui.TradeWindow;
import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
-import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay;
-import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay;
import io.github.moulberry.notenoughupdates.overlays.OverlayManager;
import io.github.moulberry.notenoughupdates.overlays.TextOverlay;
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
@@ -390,17 +388,6 @@ public class RenderListener {
public void onGuiScreenDrawPre(GuiScreenEvent.DrawScreenEvent.Pre event) {
doInventoryButtons = false;
- if (AuctionSearchOverlay.shouldReplace()) {
- AuctionSearchOverlay.render();
- event.setCanceled(true);
- return;
- }
- if (BazaarSearchOverlay.shouldReplace()) {
- BazaarSearchOverlay.render();
- event.setCanceled(true);
- return;
- }
-
String containerName = null;
GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen;
if (guiScreen instanceof GuiChest) {
@@ -942,16 +929,6 @@ public class RenderListener {
if (!event.isCanceled()) {
Utils.scrollTooltip(Mouse.getEventDWheel());
}
- if (AuctionSearchOverlay.shouldReplace()) {
- AuctionSearchOverlay.mouseEvent();
- event.setCanceled(true);
- return;
- }
- if (BazaarSearchOverlay.shouldReplace()) {
- BazaarSearchOverlay.mouseEvent();
- event.setCanceled(true);
- return;
- }
String containerName = null;
GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen;
@@ -1113,17 +1090,6 @@ public class RenderListener {
return;
}
- if (AuctionSearchOverlay.shouldReplace()) {
- AuctionSearchOverlay.keyEvent();
- event.setCanceled(true);
- return;
- }
- if (BazaarSearchOverlay.shouldReplace()) {
- BazaarSearchOverlay.keyEvent();
- event.setCanceled(true);
- return;
- }
-
String containerName = null;
GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/AHTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/AHTweaks.java
index 1c9971a8..3f869298 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/AHTweaks.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/AHTweaks.java
@@ -166,4 +166,12 @@ public class AHTweaks {
)
@ConfigEditorBoolean()
public boolean ctrlFSearch = true;
+
+ @Expose
+ @ConfigOption(
+ name = "Convert Search Command",
+ desc = "Converts §e/ah arg arg2 §rinto §e/ahs arg arg2"
+ )
+ @ConfigEditorBoolean()
+ public boolean convertSearchCommand = true;
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java
index 7f633ca1..8c55e8da 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/AuctionSearchOverlay.java
@@ -22,26 +22,27 @@ package io.github.moulberry.notenoughupdates.overlays;
import com.google.common.base.Splitter;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
import io.github.moulberry.notenoughupdates.commands.help.SettingsCommand;
import io.github.moulberry.notenoughupdates.core.GuiElementTextField;
-import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign;
+import io.github.moulberry.notenoughupdates.events.SlotClickEvent;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
-import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
-import net.minecraft.network.play.client.C0DPacketCloseWindow;
-import net.minecraft.tileentity.TileEntitySign;
-import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.lang3.StringUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashSet;
@@ -51,7 +52,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
-public class AuctionSearchOverlay {
+@NEUAutoSubscribe
+public class AuctionSearchOverlay extends GuiScreen {
private static final ResourceLocation SEARCH_OVERLAY_TEXTURE = new ResourceLocation(
"notenoughupdates:auc_search/ah_search_overlay.png");
private static final ResourceLocation SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED = new ResourceLocation(
@@ -96,34 +98,24 @@ public class AuctionSearchOverlay {
return 1;
};
- public static boolean shouldReplace() {
- if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return false;
- if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.enableSearchOverlay) return false;
-
- if (!(Minecraft.getMinecraft().currentScreen instanceof GuiEditSign)) {
- if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.keepPreviousSearch) searchString = "";
- return false;
- }
-
- String lastContainer = Utils.getLastOpenChestName();
- if (!lastContainer.equals("Auctions Browser") && !lastContainer.startsWith("Auctions: ")) return false;
-
- TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign();
+ public AuctionSearchOverlay() {
+ super();
+ }
- if (tes == null) return false;
- if (tes.getPos().getY() != 0) return false;
- if (!tes.signText[2].getUnformattedText().equals("^^^^^^^^^^^^^^^")) return false;
- return tes.signText[3].getUnformattedText().equals("Enter query");
+ static boolean isGuiOpen = false;
+ public static boolean shouldReplace() {
+ return isGuiOpen; //💀
}
- public static void render() {
+ @Override
+ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
+ isGuiOpen = true;
+ super.drawScreen(mouseX, mouseY, partialTicks);
+ super.drawDefaultBackground();
+
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
int width = scaledResolution.getScaledWidth();
int height = scaledResolution.getScaledHeight();
- int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth;
- int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1;
-
- Utils.drawGradientRect(0, 0, width, height, -1072689136, -804253680);
int h = NotEnoughUpdates.INSTANCE.config.ahTweaks.showPastSearches ? 219 : 145;
@@ -308,6 +300,7 @@ public class AuctionSearchOverlay {
}
public static void close() {
+ isGuiOpen = false;
if (tabCompleted) {
tabCompletionIndex = -1;
tabCompleted = false;
@@ -320,8 +313,6 @@ public class AuctionSearchOverlay {
}
}
- TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign();
-
StringBuilder stringBuilder = new StringBuilder(searchString.trim());
if (!searchStringExtra.isEmpty()) {
stringBuilder.append(searchStringExtra);
@@ -332,49 +323,6 @@ public class AuctionSearchOverlay {
String search = stringBuilder.toString();
- if (search.length() <= 15) {
- tes.signText[0] = new ChatComponentText(search.substring(0, Math.min(search.length(), 15)));
- } else {
- List<String> words = SPACE_SPLITTER.splitToList(search);
-
- StringBuilder line0 = new StringBuilder();
- StringBuilder line1 = new StringBuilder();
-
- int currentLine = 0;
- for (String word : words) {
- if (currentLine == 0) {
- if (line0.length() + word.length() > 15) {
- currentLine++;
- } else {
- line0.append(word);
- if (line0.length() >= 15) {
- currentLine++;
- continue;
- } else {
- line0.append(" ");
- }
- }
- }
- if (currentLine == 1) {
- if (line1.length() + word.length() > 15) {
- line1.append(word, 0, 15 - line1.length());
- break;
- } else {
- line1.append(word);
- if (line1.length() >= 15) {
- break;
- } else {
- line1.append(" ");
- }
- }
- }
- if (line1.length() >= 15) break;
- }
-
- tes.signText[0] = new ChatComponentText(line0.toString().trim());
- tes.signText[1] = new ChatComponentText(line1.toString().trim());
- }
-
if (!searchString.trim().isEmpty()) {
List<String> previousAuctionSearches = NotEnoughUpdates.INSTANCE.config.hidden.previousAuctionSearches;
previousAuctionSearches.remove(searchString);
@@ -385,11 +333,8 @@ public class AuctionSearchOverlay {
}
}
- Minecraft.getMinecraft().displayGuiScreen(null);
-
- if (Minecraft.getMinecraft().currentScreen == null) {
- Minecraft.getMinecraft().setIngameFocus();
- }
+ if (!search.isEmpty()) NotEnoughUpdates.INSTANCE.sendChatMessage("/ahs " + search);
+ if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.keepPreviousSearch) searchString = "";
}
private static boolean updateTabCompletedSearch(int key) {
@@ -483,21 +428,24 @@ public class AuctionSearchOverlay {
});
}
- public static void keyEvent() {
+ @Override
+ protected void keyTyped(char typedChar, int keyCode) throws IOException {
+ super.keyTyped(typedChar, keyCode);
boolean ignoreKey = false;
- if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
+ if (keyCode == Keyboard.KEY_ESCAPE) {
searchStringExtra = "";
- close();
if (NotEnoughUpdates.INSTANCE.config.ahTweaks.escFullClose) {
- Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId));
+ Minecraft.getMinecraft().displayGuiScreen(null);
+ } else {
+ close();
}
return;
- } else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) {
+ } else if (keyCode == Keyboard.KEY_RETURN) {
searchStringExtra = "";
close();
return;
- } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) {
+ } else if (keyCode == Keyboard.KEY_TAB) {
//autocomplete to first item in the list
if (!tabCompleted) {
tabCompleted = true;
@@ -517,7 +465,7 @@ public class AuctionSearchOverlay {
if (Keyboard.getEventKeyState()) {
if (tabCompleted) {
if (!ignoreKey) {
- boolean success = updateTabCompletedSearch(Keyboard.getEventKey());
+ boolean success = updateTabCompletedSearch(keyCode);
if (success) return;
textField.setFocus(true);
textField.setText(searchString);
@@ -528,14 +476,15 @@ public class AuctionSearchOverlay {
}
textField.setFocus(true);
textField.setText(searchString);
- textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
+ textField.keyTyped(Keyboard.getEventCharacter(), keyCode);
searchString = textField.getText();
search();
}
}
- public static void mouseEvent() {
+ @Override
+ public void handleMouseInput() throws IOException {
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
int width = scaledResolution.getScaledWidth();
int height = scaledResolution.getScaledHeight();
@@ -603,9 +552,9 @@ public class AuctionSearchOverlay {
searchStringExtra = "";
close();
} else if (mouseX < width / 2 + 100) {
+ searchString = "";
searchStringExtra = "";
close();
- Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId));
NotEnoughUpdates.INSTANCE.openGui = SettingsCommand.INSTANCE.createConfigScreen("AH Tweaks");
}
}
@@ -684,4 +633,15 @@ public class AuctionSearchOverlay {
}
}
}
+
+ @SubscribeEvent
+ public void onSlotClick(SlotClickEvent event) {
+ if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.enableSearchOverlay) return;
+ if (!Utils.getOpenChestName().startsWith("Auctions")) return;
+ ItemStack stack = event.slot.getStack();
+ if (event.slot.slotNumber == 48 && stack.hasDisplayName() && stack.getItem() == Items.sign && stack.getDisplayName().equals("§aSearch")) {
+ event.setCanceled(true);
+ NotEnoughUpdates.INSTANCE.openGui = new AuctionSearchOverlay();
+ }
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java
index 00203bcd..b292b883 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/BazaarSearchOverlay.java
@@ -22,23 +22,24 @@ package io.github.moulberry.notenoughupdates.overlays;
import com.google.common.base.Splitter;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
import io.github.moulberry.notenoughupdates.commands.help.SettingsCommand;
import io.github.moulberry.notenoughupdates.core.GuiElementTextField;
-import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign;
+import io.github.moulberry.notenoughupdates.events.SlotClickEvent;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
-import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
-import net.minecraft.network.play.client.C0DPacketCloseWindow;
-import net.minecraft.tileentity.TileEntitySign;
-import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashSet;
@@ -48,7 +49,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
-public class BazaarSearchOverlay {
+@NEUAutoSubscribe
+public class BazaarSearchOverlay extends GuiScreen {
private static final ResourceLocation SEARCH_OVERLAY_TEXTURE = new ResourceLocation(
"notenoughupdates:auc_search/ah_search_overlay.png");
private static final ResourceLocation SEARCH_OVERLAY_TEXTURE_TAB_COMPLETED = new ResourceLocation(
@@ -85,34 +87,24 @@ public class BazaarSearchOverlay {
return 1;
};
- public static boolean shouldReplace() {
- if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return false;
- if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.enableSearchOverlay) return false;
-
- if (!(Minecraft.getMinecraft().currentScreen instanceof GuiEditSign)) {
- if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.keepPreviousSearch) searchString = "";
- return false;
- }
-
- String lastContainer = Utils.getLastOpenChestName();
- if (!lastContainer.startsWith("Bazaar ➜ ")) return false;
-
- TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign();
+ public BazaarSearchOverlay() {
+ super();
+ }
- if (tes == null) return false;
- if (tes.getPos().getY() != 0) return false;
- if (!tes.signText[2].getUnformattedText().equals("^^^^^^^^^^^^^^^")) return false;
- return tes.signText[3].getUnformattedText().equals("Enter query");
+ static boolean isGuiOpen = false;
+ public static boolean shouldReplace() {
+ return isGuiOpen; //this whole method is just so skyhanni doesnt crash 💀
}
- public static void render() {
+ @Override
+ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
+ isGuiOpen = true;
+ super.drawScreen(mouseX, mouseY, partialTicks);
+ super.drawDefaultBackground();
+
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
int width = scaledResolution.getScaledWidth();
int height = scaledResolution.getScaledHeight();
- int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth;
- int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1;
-
- Utils.drawGradientRect(0, 0, width, height, -1072689136, -804253680);
int h = NotEnoughUpdates.INSTANCE.config.bazaarTweaks.showPastSearches ? 219 : 145;
@@ -235,7 +227,6 @@ public class BazaarSearchOverlay {
Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1);
}
}
-
}
private static final ExecutorService searchES = Executors.newSingleThreadExecutor();
@@ -258,6 +249,7 @@ public class BazaarSearchOverlay {
}
public static void close() {
+ isGuiOpen = false;
if (tabCompleted) {
tabCompletionIndex = -1;
tabCompleted = false;
@@ -270,8 +262,6 @@ public class BazaarSearchOverlay {
}
}
- TileEntitySign tes = ((AccessorGuiEditSign) Minecraft.getMinecraft().currentScreen).getTileSign();
-
StringBuilder stringBuilder = new StringBuilder(searchString.trim());
if (!searchStringExtra.isEmpty()) {
stringBuilder.append(searchStringExtra);
@@ -279,49 +269,6 @@ public class BazaarSearchOverlay {
String search = stringBuilder.toString();
- if (search.length() <= 15) {
- tes.signText[0] = new ChatComponentText(search.substring(0, Math.min(search.length(), 15)));
- } else {
- List<String> words = SPACE_SPLITTER.splitToList(search);
-
- StringBuilder line0 = new StringBuilder();
- StringBuilder line1 = new StringBuilder();
-
- int currentLine = 0;
- for (String word : words) {
- if (currentLine == 0) {
- if (line0.length() + word.length() > 15) {
- currentLine++;
- } else {
- line0.append(word);
- if (line0.length() >= 15) {
- currentLine++;
- continue;
- } else {
- line0.append(" ");
- }
- }
- }
- if (currentLine == 1) {
- if (line1.length() + word.length() > 15) {
- line1.append(word, 0, 15 - line1.length());
- break;
- } else {
- line1.append(word);
- if (line1.length() >= 15) {
- break;
- } else {
- line1.append(" ");
- }
- }
- }
- if (line1.length() >= 15) break;
- }
-
- tes.signText[0] = new ChatComponentText(line0.toString().trim());
- tes.signText[1] = new ChatComponentText(line1.toString().trim());
- }
-
if (!searchString.trim().isEmpty()) {
List<String> previousBazaarSearches = NotEnoughUpdates.INSTANCE.config.hidden.previousBazaarSearches;
previousBazaarSearches.remove(searchString);
@@ -332,11 +279,8 @@ public class BazaarSearchOverlay {
}
}
- Minecraft.getMinecraft().displayGuiScreen(null);
-
- if (Minecraft.getMinecraft().currentScreen == null) {
- Minecraft.getMinecraft().setIngameFocus();
- }
+ if (!search.isEmpty()) NotEnoughUpdates.INSTANCE.sendChatMessage("/bz " + search);
+ if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.keepPreviousSearch) searchString = "";
}
private static boolean updateTabCompletedSearch(int key) {
@@ -424,21 +368,24 @@ public class BazaarSearchOverlay {
});
}
- public static void keyEvent() {
+ @Override
+ protected void keyTyped(char typedChar, int keyCode) throws IOException {
+ super.keyTyped(typedChar, keyCode);
boolean ignoreKey = false;
- if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
+ if (keyCode == Keyboard.KEY_ESCAPE) {
searchStringExtra = "";
- close();
if (NotEnoughUpdates.INSTANCE.config.bazaarTweaks.escFullClose) {
- Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId));
+ Minecraft.getMinecraft().displayGuiScreen(null);
+ } else {
+ close();
}
return;
- } else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) {
+ } else if (keyCode == Keyboard.KEY_RETURN) {
searchStringExtra = "";
close();
return;
- } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) {
+ } else if (keyCode == Keyboard.KEY_TAB) {
//autocomplete to first item in the list
if (!tabCompleted) {
tabCompleted = true;
@@ -458,7 +405,7 @@ public class BazaarSearchOverlay {
if (Keyboard.getEventKeyState()) {
if (tabCompleted) {
if (!ignoreKey) {
- boolean success = updateTabCompletedSearch(Keyboard.getEventKey());
+ boolean success = updateTabCompletedSearch(keyCode);
if (success) return;
textField.setFocus(true);
textField.setText(searchString);
@@ -469,14 +416,15 @@ public class BazaarSearchOverlay {
}
textField.setFocus(true);
textField.setText(searchString);
- textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
+ textField.keyTyped(Keyboard.getEventCharacter(), keyCode);
searchString = textField.getText();
search();
}
}
- public static void mouseEvent() {
+ @Override
+ public void handleMouseInput() throws IOException {
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
int width = scaledResolution.getScaledWidth();
int height = scaledResolution.getScaledHeight();
@@ -515,9 +463,9 @@ public class BazaarSearchOverlay {
searchStringExtra = "";
close();
} else if (mouseX < width / 2 + 100) {
+ searchString = "";
searchStringExtra = "";
close();
- Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(Minecraft.getMinecraft().thePlayer.openContainer.windowId));
NotEnoughUpdates.INSTANCE.openGui = SettingsCommand.INSTANCE.createConfigScreen("Bazaar Tweaks");
}
}
@@ -567,4 +515,15 @@ public class BazaarSearchOverlay {
}
}
}
+
+ @SubscribeEvent
+ public void onSlotClick(SlotClickEvent event) {
+ if (!NotEnoughUpdates.INSTANCE.config.bazaarTweaks.enableSearchOverlay) return;
+ if (!Utils.getOpenChestName().startsWith("Bazaar ➜")) return;
+ ItemStack stack = event.slot.getStack();
+ if (event.slot.slotNumber == 45 && stack.hasDisplayName() && stack.getItem() == Items.sign && stack.getDisplayName().equals("§aSearch")) {
+ event.setCanceled(true);
+ NotEnoughUpdates.INSTANCE.openGui = new BazaarSearchOverlay();
+ }
+ }
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SearchCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SearchCommand.kt
new file mode 100644
index 00000000..9af9a097
--- /dev/null
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SearchCommand.kt
@@ -0,0 +1,74 @@
+/*
+ * 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.commands.misc
+
+import com.mojang.brigadier.arguments.StringArgumentType
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates
+import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
+import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
+import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay
+import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay
+import io.github.moulberry.notenoughupdates.util.brigadier.RestArgumentType
+import io.github.moulberry.notenoughupdates.util.brigadier.get
+import io.github.moulberry.notenoughupdates.util.brigadier.thenArgumentExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.withHelp
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+@NEUAutoSubscribe
+class SearchCommand {
+ @SubscribeEvent
+ fun onCommands(event: RegisterBrigadierCommandEvent) {
+ event.command("bzs") {
+ thenArgumentExecute("search", StringArgumentType.string()) { search ->
+ NotEnoughUpdates.INSTANCE.sendChatMessage("/bz ${this[search]}")
+ }.withHelp("Search directly without opening the GUI")
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.openGui = BazaarSearchOverlay()
+ }
+ }.withHelp("Search the bazaar directly with a custom search GUI")
+ event.command("ahs") {
+ thenArgumentExecute("search", StringArgumentType.string()) { search ->
+ NotEnoughUpdates.INSTANCE.sendChatMessage("/ahs ${this[search]}")
+ }.withHelp("Search directly without opening the GUI")
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.openGui = AuctionSearchOverlay()
+ }
+ }.withHelp("Search the auction house directly with a custom search GUI")
+ event.command("ah") {
+ thenArgumentExecute("search", RestArgumentType) { search ->
+ val searchString = this[search]
+ if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.convertSearchCommand) {
+ NotEnoughUpdates.INSTANCE.sendChatMessage("/ah $searchString")
+ return@thenArgumentExecute
+ }
+ val split = searchString.split(" ")
+ if (split.size > 1) {
+ NotEnoughUpdates.INSTANCE.sendChatMessage("/ahs $searchString")
+ } else {
+ NotEnoughUpdates.INSTANCE.sendChatMessage("/ah $searchString")
+ }
+ }
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.sendChatMessage("/ah")
+ }
+ }
+ }
+}