aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorDoKM <54663875+DoKM@users.noreply.github.com>2021-08-17 17:37:58 +0200
committerGitHub <noreply@github.com>2021-08-17 17:37:58 +0200
commitfbcfe79f1d0ce4f691af310d2a0cbc86824965d5 (patch)
tree228e51f24e36812c60592fd7807ee744a5cddc95 /src/main
parent63ae2fa539ff608f07350fad7235234ef26828a8 (diff)
parent46df5e8f55ae1147bae9ecba3447605729b3d9f4 (diff)
downloadNotEnoughUpdates-fbcfe79f1d0ce4f691af310d2a0cbc86824965d5.tar.gz
NotEnoughUpdates-fbcfe79f1d0ce4f691af310d2a0cbc86824965d5.tar.bz2
NotEnoughUpdates-fbcfe79f1d0ce4f691af310d2a0cbc86824965d5.zip
Merge pull request #18 from DeDiamondPro/master
Crafting overlay
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java11
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java88
3 files changed, 103 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
index 6ebcc04f..610d6931 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java
@@ -15,7 +15,6 @@ import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils;
import io.github.moulberry.notenoughupdates.cosmetics.CapeManager;
import io.github.moulberry.notenoughupdates.dungeons.DungeonBlocks;
import io.github.moulberry.notenoughupdates.dungeons.DungeonWin;
-import io.github.moulberry.notenoughupdates.gamemodes.SBGamemodes;
import io.github.moulberry.notenoughupdates.miscfeatures.*;
import io.github.moulberry.notenoughupdates.miscgui.*;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
@@ -570,6 +569,8 @@ public class NEUEventListener {
AtomicBoolean missingRecipe = new AtomicBoolean(false);
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
+ neu.manager.craftingOverlay.shouldRender = false;
+
if((Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper ||
Minecraft.getMinecraft().currentScreen instanceof GuiItemRecipe) &&
event.gui == null && !(Keyboard.getEventKeyState() && Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) &&
@@ -1060,6 +1061,9 @@ public class NEUEventListener {
GuiChest eventGui = (GuiChest) guiScreen;
ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
+ if (containerName.equals("Craft Item")) {
+ neu.manager.craftingOverlay.render();
+ }
}
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 967ef903..aff030d8 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.google.gson.*;
import io.github.moulberry.notenoughupdates.auction.APIManager;
import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
+import io.github.moulberry.notenoughupdates.overlays.CraftingOverlay;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.HypixelApi;
import io.github.moulberry.notenoughupdates.util.SBInfo;
@@ -12,6 +13,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
+import net.minecraft.inventory.ContainerChest;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
@@ -74,6 +76,8 @@ 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;
@@ -797,7 +801,12 @@ public class NEUManager {
}
public void showRecipe(JsonObject item) {
- if(item.has("useneucraft") && item.get("useneucraft").getAsBoolean()) {
+ 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);
+ }
+ } else if(item.has("useneucraft") && item.get("useneucraft").getAsBoolean()) {
displayGuiItemRecipe(item.get("internalname").getAsString(), "");
} else if(item.has("clickcommand")) {
String clickcommand = item.get("clickcommand").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
new file mode 100644
index 00000000..9b555dfd
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CraftingOverlay.java
@@ -0,0 +1,88 @@
+package io.github.moulberry.notenoughupdates.overlays;
+
+import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NEUManager;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
+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.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;
+
+ public CraftingOverlay(NEUManager manager) {
+ this.manager = manager;
+ }
+
+ public void render() {
+ if (shouldRender) {
+ ContainerChest container = (ContainerChest) Minecraft.getMinecraft().thePlayer.openContainer;
+ GuiChest gc = (GuiChest) Minecraft.getMinecraft().currentScreen;
+ FontRenderer ft = Minecraft.getMinecraft().fontRendererObj;
+ 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;
+ List<String> tooltip = null;
+ 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 (!slot.getHasStack() || !manager.getInternalNameForItem(items[i]).equals(manager.getInternalNameForItem(slot.getStack())) ||
+ slot.getStack().stackSize < items[i].stackSize)
+ Gui.drawRect(x, y, x + 16, y + 16, 0x64ff0000);
+ if (!slot.getHasStack())
+ Utils.drawItemStack(items[i], x, y);
+ if (!slot.getHasStack() && mouseX >= x && mouseX < x + 16 && mouseY >= y && mouseY < y + 16)
+ tooltip = items[i].getTooltip(Minecraft.getMinecraft().thePlayer, false);
+ }
+ }
+ if (text != null)
+ ft.drawStringWithShadow(text,
+ Utils.peekGuiScale().getScaledWidth() / 2f - ft.getStringWidth(text) / 2f,
+ gc.guiTop - 15f, 0x808080);
+ if (tooltip != null)
+ Utils.drawHoveringText(tooltip, mouseX, mouseY, width, height, -1, ft);
+ }
+ }
+
+ public void updateItem(JsonObject item) {
+ items = new ItemStack[9];
+ text = null;
+ String[] x = {"1", "2", "3"};
+ String[] y = {"A", "B", "C"};
+ for (int i = 0; i < 9; i++) {
+ String name = y[i / 3] + x[i % 3];
+ String itemS = item.getAsJsonObject("recipe").get(name).getAsString();
+ if (itemS != null && !itemS.equals("")) {
+ int count = 1;
+ if (itemS.split(":").length == 2) {
+ count = Integer.parseInt(itemS.split(":")[1]);
+ itemS = itemS.split(":")[0];
+ }
+ JsonObject craft = manager.getItemInformation().get(itemS);
+ if (craft != null) {
+ ItemStack stack = manager.jsonToStack(craft);
+ stack.stackSize = count;
+ items[i] = stack;
+ }
+ }
+ }
+ if (item.has("crafttext")) {
+ text = item.get("crafttext").getAsString();
+ }
+ shouldRender = true;
+ }
+}