aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorDoKM <54663875+DoKM@users.noreply.github.com>2021-08-20 19:08:34 +0200
committerGitHub <noreply@github.com>2021-08-20 19:08:34 +0200
commitf70f4bf3391376bbd29bcb53213326c17a52bc23 (patch)
tree6384c0dbb1f35a0dedac34482aa9da754cfb88e0 /src/main
parent1f0af827fe5e89f40a3e052b60d93bae116f8b2d (diff)
parent8c6d02fc0f14b84fa69bfbe697ba00a53fbc19a3 (diff)
downloadNotEnoughUpdates-f70f4bf3391376bbd29bcb53213326c17a52bc23.tar.gz
NotEnoughUpdates-f70f4bf3391376bbd29bcb53213326c17a52bc23.tar.bz2
NotEnoughUpdates-f70f4bf3391376bbd29bcb53213326c17a52bc23.zip
Merge pull request #20 from DeDiamondPro/master
cleanup code + allow r to view recipe and u to view usages with virtual items in the crafting overlay
Diffstat (limited to 'src/main')
-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.java48
3 files changed, 46 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..eb4749db 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,19 @@ 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.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 +57,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 +84,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;
+ }
+ }
+ }
+ }
}