aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2021-08-20 18:59:37 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2021-08-20 18:59:37 +0200
commit0f2be33018c085c11d0f283fe91b291d5a5a197b (patch)
treeee30e1ab8e0bb7f346f59a5e57be57c4fdbd7729 /src/main/java/io
parentc518e81a6e4165c1736414c2cf45a19bb5acb355 (diff)
downloadNotEnoughUpdates-0f2be33018c085c11d0f283fe91b291d5a5a197b.tar.gz
NotEnoughUpdates-0f2be33018c085c11d0f283fe91b291d5a5a197b.tar.bz2
NotEnoughUpdates-0f2be33018c085c11d0f283fe91b291d5a5a197b.zip
cleanup code + allow r to view recipe and u to view usages with virtual items in the crafting overlay
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java12
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java49
3 files changed, 47 insertions, 18 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
index 2e108d21..0f45eb1a 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
@@ -18,10 +18,7 @@ import io.github.moulberry.notenoughupdates.dungeons.DungeonWin;
import io.github.moulberry.notenoughupdates.miscfeatures.*;
import io.github.moulberry.notenoughupdates.miscgui.*;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
-import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay;
-import io.github.moulberry.notenoughupdates.overlays.OverlayManager;
-import io.github.moulberry.notenoughupdates.overlays.RancherBootOverlay;
-import io.github.moulberry.notenoughupdates.overlays.TextOverlay;
+import io.github.moulberry.notenoughupdates.overlays.*;
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
import io.github.moulberry.notenoughupdates.util.*;
import net.minecraft.client.Minecraft;
@@ -570,7 +567,7 @@ public class NEUEventListener {
AtomicBoolean missingRecipe = new AtomicBoolean(false);
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
- neu.manager.craftingOverlay.shouldRender = false;
+ CraftingOverlay.shouldRender = false;
if((Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper ||
Minecraft.getMinecraft().currentScreen instanceof GuiItemRecipe) &&
@@ -1067,7 +1064,7 @@ public class NEUEventListener {
ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
if (containerName.equals("Craft Item")) {
- neu.manager.craftingOverlay.render();
+ CraftingOverlay.render();
}
}
@@ -1503,6 +1500,9 @@ public class NEUEventListener {
GuiChest eventGui = (GuiChest) guiScreen;
ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
+ if(CraftingOverlay.shouldRender && containerName.equals("Craft Item")){
+ CraftingOverlay.keyInput();
+ }
}
if(GuiCustomEnchant.getInstance().shouldOverride(containerName) &&
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index aff030d8..2975115c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -76,8 +76,6 @@ public class NEUManager {
public File repoLocation;
public File configFile;
- public CraftingOverlay craftingOverlay = new CraftingOverlay(this);
-
public NEUManager(NotEnoughUpdates neu, File configLocation) {
this.neu = neu;
this.configLocation = configLocation;
@@ -804,7 +802,7 @@ public class NEUManager {
if (item.has("recipe") && Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerChest) {
ContainerChest container = (ContainerChest) Minecraft.getMinecraft().thePlayer.openContainer;
if (container.getLowerChestInventory().getDisplayName().getUnformattedText().equals("Craft Item")) {
- craftingOverlay.updateItem(item);
+ CraftingOverlay.updateItem(item);
}
} else if(item.has("useneucraft") && item.get("useneucraft").getAsBoolean()) {
displayGuiItemRecipe(item.get("internalname").getAsString(), "");
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java
index 9b555dfd..1ddb25fd 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java
@@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.overlays;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NEUManager;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@@ -10,21 +11,20 @@ import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
+import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
+import java.io.File;
import java.util.List;
public class CraftingOverlay {
- private ItemStack[] items = new ItemStack[9];
- private final NEUManager manager;
- public boolean shouldRender = false;
- private String text = null;
+ private static ItemStack[] items = new ItemStack[9];
+ private static final NEUManager manager = NotEnoughUpdates.INSTANCE.manager;
+ public static boolean shouldRender = false;
+ private static String text = null;
- public CraftingOverlay(NEUManager manager) {
- this.manager = manager;
- }
- public void render() {
+ public static void render() {
if (shouldRender) {
ContainerChest container = (ContainerChest) Minecraft.getMinecraft().thePlayer.openContainer;
GuiChest gc = (GuiChest) Minecraft.getMinecraft().currentScreen;
@@ -58,7 +58,7 @@ public class CraftingOverlay {
}
}
- public void updateItem(JsonObject item) {
+ public static void updateItem(JsonObject item) {
items = new ItemStack[9];
text = null;
String[] x = {"1", "2", "3"};
@@ -85,4 +85,35 @@ public class CraftingOverlay {
}
shouldRender = true;
}
+
+ public static void keyInput() {
+ if (!Keyboard.getEventKeyState() || Keyboard.getEventKey() != Keyboard.KEY_U && Keyboard.getEventKey() != Keyboard.KEY_R)
+ return;
+ int width = Utils.peekGuiScale().getScaledWidth();
+ int height = Utils.peekGuiScale().getScaledHeight();
+ int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth;
+ int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1;
+ ContainerChest container = (ContainerChest) Minecraft.getMinecraft().thePlayer.openContainer;
+ GuiChest gc = (GuiChest) Minecraft.getMinecraft().currentScreen;
+ for (int i = 0; i < 9; i++) {
+ if (items[i] != null) {
+ int slotIndex = (int) (10 + 9 * Math.floor(i / 3f) + (i % 3));
+ Slot slot = container.inventorySlots.get(slotIndex);
+ int x = slot.xDisplayPosition + gc.guiLeft;
+ int y = slot.yDisplayPosition + gc.guiTop;
+ if (mouseX >= x && mouseX < x + 16 && mouseY >= y && mouseY < y + 16) {
+ if (!slot.getHasStack()) {
+ String internalName = manager.getInternalNameForItem(items[i]);
+ if (Keyboard.getEventKey() == Keyboard.KEY_U && internalName != null) {
+ manager.displayGuiItemUsages(internalName);
+ } else if (Keyboard.getEventKey() == Keyboard.KEY_R && internalName != null && manager.getItemInformation().containsKey(internalName)) {
+ JsonObject item = manager.getItemInformation().get(internalName);
+ manager.showRecipe(item);
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
}