diff options
author | Lulonaut <lulonaut@tutanota.de> | 2022-05-01 09:18:26 +0200 |
---|---|---|
committer | Lulonaut <lulonaut@tutanota.de> | 2022-05-01 09:18:26 +0200 |
commit | e6bc3c7398fdd019a0562a8ba9cab5ef32bfb08b (patch) | |
tree | cfe5007e203f6ed062d91dc243a5730470c6ffa0 /src/main/java | |
parent | b37133ac63da4bb983b96f3348ede9f3a2aa9e1c (diff) | |
download | NotEnoughUpdates-e6bc3c7398fdd019a0562a8ba9cab5ef32bfb08b.tar.gz NotEnoughUpdates-e6bc3c7398fdd019a0562a8ba9cab5ef32bfb08b.tar.bz2 NotEnoughUpdates-e6bc3c7398fdd019a0562a8ba9cab5ef32bfb08b.zip |
npc parsing
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java | 112 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java | 124 |
2 files changed, 180 insertions, 56 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 0cd55c30..bec3dc36 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1,63 +1,9 @@ package io.github.moulberry.notenoughupdates; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.ascending_overlay; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.close; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.descending_overlay; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.help; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.itemPaneTabArrow; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.item_haschild; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.item_mask; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_alphabetical; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_alphabetical_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_rarity; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_rarity_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_value; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_value_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.quickcommand_background; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.rightarrow; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.rightarrow_overlay; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.settings; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_accessory; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_accessory_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_all; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_all_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_armor; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_armor_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_mob; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_mob_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_pet; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_pet_active; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_tool; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_tool_active; - -import java.awt.Color; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; -import org.lwjgl.util.vector.Vector2f; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; @@ -115,6 +61,60 @@ import net.minecraft.util.Matrix4f; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.ClientCommandHandler; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; +import org.lwjgl.util.vector.Vector2f; + +import java.awt.*; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; + +import static io.github.moulberry.notenoughupdates.util.GuiTextures.ascending_overlay; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.close; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.descending_overlay; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.help; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.itemPaneTabArrow; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.item_haschild; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.item_mask; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_alphabetical; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_alphabetical_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_rarity; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_rarity_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_value; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.order_value_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.quickcommand_background; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.rightarrow; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.rightarrow_overlay; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.settings; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_accessory; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_accessory_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_all; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_all_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_armor; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_armor_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_mob; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_mob_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_pet; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_pet_active; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_tool; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.sort_tool_active; public class NEUOverlay extends Gui { private static final ResourceLocation SUPERGEHEIMNISVERMOGEN = new ResourceLocation( @@ -230,7 +230,7 @@ public class NEUOverlay extends Gui { private boolean redrawItems = false; private boolean searchBarHasFocus = false; - private final GuiTextField textField = new GuiTextField(0, null, 0, 0, 0, 0); + private static final GuiTextField textField = new GuiTextField(0, null, 0, 0, 0, 0); private static final int COMPARE_MODE_ALPHABETICAL = 0; private static final int COMPARE_MODE_RARITY = 1; @@ -996,7 +996,7 @@ public class NEUOverlay extends Gui { return paddingUnscaled; } - public GuiTextField getTextField() { + public static GuiTextField getTextField() { return textField; } 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 54154955..50ab5b66 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -33,6 +33,7 @@ import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.RequestFocusListener; +import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -55,6 +56,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StringUtils; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiScreenEvent; @@ -84,6 +86,7 @@ import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -107,6 +110,10 @@ public class RenderListener { private long buttonHoveredMillis = 0; private int inventoryLoadedTicks = 0; private String loadedInvName = ""; + //NPC parsing + private String correctingItem; + private boolean typing; + private HashMap<String, String> cachedDefinitions; public RenderListener(NotEnoughUpdates neu) { this.neu = neu; @@ -1011,6 +1018,9 @@ public class RenderListener { */ @SubscribeEvent public void onGuiScreenKeyboard(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if (typing) { + event.setCanceled(true); + } if (Keyboard.isKeyDown(Keyboard.KEY_B) && NotEnoughUpdates.INSTANCE.config.hidden.dev) { if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) { GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; @@ -1112,6 +1122,120 @@ public class RenderListener { EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details.")); } } + } else if (Keyboard.isKeyDown(Keyboard.KEY_RETURN) && NotEnoughUpdates.INSTANCE.config.hidden.dev) { + Minecraft mc = Minecraft.getMinecraft(); + + if (typing) { + typing = false; + cachedDefinitions.put(correctingItem, NEUOverlay.getTextField().getText()); + NEUOverlay.getTextField().setText(""); + } + + if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + IInventory lower = cc.getLowerChestInventory(); + + try { + JsonObject newNPC = new JsonObject(); + String displayname = lower.getDisplayName().getUnformattedText(); + newNPC.add("itemid", new JsonPrimitive("minecraft:skull")); + newNPC.add("displayname", new JsonPrimitive("§9" + displayname + " (NPC)")); + newNPC.add("nbttag", new JsonPrimitive("TODO")); + newNPC.add("damage", new JsonPrimitive(3)); + + JsonArray newArray = new JsonArray(); + newArray.add(new JsonPrimitive("")); + newNPC.add("lore", newArray); + newNPC.add("internalname", new JsonPrimitive(displayname.toUpperCase() + "_NPC")); + newNPC.add("clickcommand", new JsonPrimitive("viewrecipe")); + newNPC.add("modver", new JsonPrimitive(NotEnoughUpdates.VERSION)); + newNPC.add("infoType", new JsonPrimitive("WIKI_URL")); + JsonArray emptyInfoArray = new JsonArray(); + emptyInfoArray.add(new JsonPrimitive("TODO")); + newNPC.add("info", emptyInfoArray); + newNPC.add("x", new JsonPrimitive((int) mc.thePlayer.posX)); + newNPC.add("y", new JsonPrimitive((int) mc.thePlayer.posY + 2)); + newNPC.add("z", new JsonPrimitive((int) mc.thePlayer.posZ)); + newNPC.add("island", new JsonPrimitive(SBInfo.getInstance().getLocation())); + + JsonArray recipesArray = new JsonArray(); + + TreeMap<String, JsonObject> itemInformation = NotEnoughUpdates.INSTANCE.manager.getItemInformation(); + for (int i = 0; i < 45; i++) { + ItemStack stack = lower.getStackInSlot(i); + if (stack == null) continue; + if (stack.getDisplayName().isEmpty() || stack.getDisplayName().equals(" ")) continue; + + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(stack.getTagCompound()); + if (internalname == null) continue; + JsonObject currentRecipe = new JsonObject(); + currentRecipe.add("type", new JsonPrimitive("npc_shop")); + JsonArray costArray = new JsonArray(); + boolean inCost = false; + for (String s : NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound())) { + if (s.equals("§7Cost")) { + inCost = true; + continue; + } else if (s.equals("§eClick to trade!")) { + inCost = false; + } + if (!inCost) continue; + String entry = StringUtils.stripControlCodes(s); + if (entry.isEmpty()) continue; + int coinIndex = entry.indexOf(" Coins"); + if (coinIndex != -1) { + String amountString = entry.substring(0, coinIndex).replace(",", ""); + costArray.add(new JsonPrimitive("SKYBLOCK_COIN:" + amountString)); + } else { + if (cachedDefinitions == null) { + cachedDefinitions = new HashMap<>(); + } + + String item; + int amountIndex = entry.lastIndexOf(" x"); + String amountString; + if (amountIndex == -1) { + amountString = "1"; + item = entry.replace(" ", "_").toUpperCase(); + } else { + amountString = entry.substring(amountIndex); + item = entry.substring(0, amountIndex).replace(" ", "_").toUpperCase(); + } + amountString = amountString.replace(",", "").replace("x", "").trim(); + if (itemInformation.containsKey(item)) { + costArray.add(new JsonPrimitive(item + ":" + amountString)); + } else if (cachedDefinitions.containsKey(item)) { + costArray.add(new JsonPrimitive(cachedDefinitions.get(item) + ":" + amountString)); + } else { + mc.thePlayer.addChatMessage(new ChatComponentText( + "Change the item ID of " + item + " to the correct one and press Enter.")); + NEUOverlay.getTextField().setText(item); + event.setCanceled(true); + typing = true; + correctingItem = item; + if (cachedDefinitions == null) { + cachedDefinitions = new HashMap<>(); + } + return; + } + } + } + currentRecipe.add("cost", costArray); + currentRecipe.add("result", new JsonPrimitive(internalname)); + recipesArray.add(currentRecipe); + newNPC.add("recipes", recipesArray); + } + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + System.out.println(gson.toJson(newNPC)); + } catch (Exception e) { + e.printStackTrace(); + mc.thePlayer.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details")); + } + } else { + mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You are not in a valid inventory")); + } } if (AuctionBINWarning.getInstance().shouldShow()) { |