aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java339
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/dev/RepoExporters.java482
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java9
4 files changed, 504 insertions, 328 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java
index 27e7cfc6..dd3f5efd 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java
@@ -957,7 +957,7 @@ public static class EnchantLine {
if (Keyboard.isKeyDown(Keyboard.KEY_H)) {
if (!copied) {
copied = true;
- StringSelection selection = new StringSelection(sb.toString());
+ StringSelection selection = new StringSelection(sb.toString().replace("§r§7", ""));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
}
} else {
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 191567a1..9bd1e272 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -20,13 +20,8 @@
package io.github.moulberry.notenoughupdates.listener;
import com.google.common.collect.Lists;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
import io.github.moulberry.notenoughupdates.NEUApi;
import io.github.moulberry.notenoughupdates.NEUOverlay;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
@@ -34,7 +29,6 @@ import io.github.moulberry.notenoughupdates.auction.CustomAHGui;
import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand;
import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper;
import io.github.moulberry.notenoughupdates.dungeons.DungeonWin;
-import io.github.moulberry.notenoughupdates.itemeditor.NEUItemEditor;
import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning;
import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning;
import io.github.moulberry.notenoughupdates.miscfeatures.AuctionProfit;
@@ -43,6 +37,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSol
import io.github.moulberry.notenoughupdates.miscfeatures.DungeonNpcProfitOverlay;
import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers;
import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager;
+import io.github.moulberry.notenoughupdates.miscfeatures.dev.RepoExporters;
import io.github.moulberry.notenoughupdates.miscgui.AccessoryBagOverlay;
import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay;
import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant;
@@ -51,8 +46,8 @@ import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay;
import io.github.moulberry.notenoughupdates.miscgui.TradeWindow;
import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay;
-import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex;
+import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay;
@@ -76,18 +71,14 @@ import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.init.Blocks;
-import net.minecraft.init.Items;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
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;
@@ -103,30 +94,20 @@ import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import javax.swing.*;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
-import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.List;
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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import static io.github.moulberry.notenoughupdates.util.GuiTextures.dungeon_chest_worth;
@@ -149,9 +130,9 @@ public class RenderListener {
private int inventoryLoadedTicks = 0;
private String loadedInvName = "";
//NPC parsing
- private String correctingItem;
- private boolean typing;
- private HashMap<String, String> cachedDefinitions;
+
+ public static boolean typing;
+
private boolean inDungeonPage = false;
public RenderListener(NotEnoughUpdates neu) {
@@ -1235,274 +1216,14 @@ public class RenderListener {
ItemStack backArrow = lower.getStackInSlot(48);
List<String> tooltip = backArrow != null ? backArrow.getTooltip(Minecraft.getMinecraft().thePlayer, false) : null;
if (tooltip != null && tooltip.size() >= 2 && tooltip.get(1).endsWith("Essence")) {
-
- try {
- File file = new File(
- Minecraft.getMinecraft().mcDataDir.getAbsolutePath(),
- "config/notenoughupdates/repo/constants/essencecosts.json"
- );
- String fileContent;
- fileContent = new BufferedReader(new InputStreamReader(
- Files.newInputStream(file.toPath()),
- StandardCharsets.UTF_8
- ))
- .lines()
- .collect(Collectors.joining(System.lineSeparator()));
- String id = null;
- JsonObject jsonObject = new JsonParser().parse(fileContent).getAsJsonObject();
- JsonObject newEntry = new JsonObject();
- for (int i = 0; i < 54; i++) {
- ItemStack stack = lower.getStackInSlot(i);
- if (!stack.getDisplayName().isEmpty() && stack.getItem() != Item.getItemFromBlock(Blocks.barrier) &&
- stack.getItem() != Items.arrow) {
- if (stack.getTagCompound().getCompoundTag("display").hasKey("Lore", 9)) {
- int stars = Utils.getNumberOfStars(stack);
- if (stars == 0) continue;
-
- NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8);
- int costIndex = 10000;
- id = NotEnoughUpdates.INSTANCE.manager
- .createItemResolutionQuery()
- .withItemStack(stack)
- .resolveInternalName();
- if (jsonObject.has(id)) {
- jsonObject.remove(id);
- }
- for (int j = 0; j < lore.tagCount(); j++) {
- String entry = lore.getStringTagAt(j);
- if (entry.equals("§7Cost")) {
- costIndex = j;
- }
- if (j > costIndex) {
- entry = entry.trim();
- int index = entry.lastIndexOf('x');
- String item, amountString;
- if (index < 0) {
- item = entry.trim() + " x1";
- amountString = "x1";
- } else {
- amountString = entry.substring(index);
- item = entry.substring(0, index).trim();
- }
- item = item.substring(0, item.length() - 3);
- int amount = Integer.parseInt(amountString.trim().replace("x", "").replace(",", ""));
- if (item.endsWith("Essence")) {
- int index2 = entry.indexOf("Essence");
- String typeAndAmount = item.substring(0, index2).trim().substring(2);
- int whitespaceIndex = typeAndAmount.indexOf(' ');
- int essenceAmount = Integer.parseInt(typeAndAmount
- .substring(0, whitespaceIndex)
- .replace(",", ""));
- newEntry.add("type", new JsonPrimitive(typeAndAmount.substring(whitespaceIndex + 1)));
- if (stars == -1) {
- newEntry.add("dungeonize", new JsonPrimitive(essenceAmount));
- } else {
- newEntry.add(String.valueOf(stars), new JsonPrimitive(essenceAmount));
- }
- } else if (item.endsWith("Coins")) {
- int index2 = entry.indexOf("Coins");
- String coinsAmount = item.substring(0, index2).trim().substring(2);
- if (!newEntry.has("items")) {
- newEntry.add("items", new JsonObject());
- }
- if (!newEntry.get("items").getAsJsonObject().has(String.valueOf(stars))) {
- newEntry.get("items").getAsJsonObject().add(String.valueOf(stars), new JsonArray());
- }
- newEntry
- .get("items")
- .getAsJsonObject()
- .get(String.valueOf(stars))
- .getAsJsonArray()
- .add(new JsonPrimitive("SKYBLOCK_COIN:" + coinsAmount.replace(",", "")));
- } else {
- String itemString = "_";
- for (Map.Entry<String, JsonObject> itemEntry : NotEnoughUpdates.INSTANCE.manager
- .getItemInformation()
- .entrySet()) {
-
- if (itemEntry.getValue().has("displayname")) {
- String name = itemEntry.getValue().get("displayname").getAsString();
- if (name.equals(item)) {
- itemString = itemEntry.getKey() + ":" + amount;
- }
- }
- }
- if (!newEntry.has("items")) {
- newEntry.add("items", new JsonObject());
- }
- if (!newEntry.get("items").getAsJsonObject().has(String.valueOf(stars))) {
- newEntry.get("items").getAsJsonObject().add(String.valueOf(stars), new JsonArray());
- }
- newEntry
- .get("items")
- .getAsJsonObject()
- .get(String.valueOf(stars))
- .getAsJsonArray()
- .add(new JsonPrimitive(itemString));
- }
- }
- }
- jsonObject.add(id, newEntry);
- }
- }
- }
- if (jsonObject.get(id).getAsJsonObject().has("items")) {
- JsonObject itemsObj = jsonObject.get(id).getAsJsonObject().get("items").getAsJsonObject();
- jsonObject.get(id).getAsJsonObject().remove("items");
- jsonObject.get(id).getAsJsonObject().add("items", itemsObj);
- }
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- try {
- try (
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- Files.newOutputStream(file.toPath()),
- StandardCharsets.UTF_8
- ))
- ) {
- writer.write(gson.toJson(jsonObject));
- Utils.addChatMessage(EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + id);
- }
- } catch (IOException ignored) {
- Utils.addChatMessage(EnumChatFormatting.RED + "Error while writing file.");
- }
- } catch (Exception e) {
- e.printStackTrace();
- Utils.addChatMessage(
- EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details.");
- }
+ RepoExporters.getInstance().essenceExporter();
+ } else if (lower.getName().contains("Draconic Altar Guide")) {
+ RepoExporters.getInstance().draconicAlterExporter();
}
} 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();
- File file = new File(
- Minecraft.getMinecraft().mcDataDir.getAbsolutePath(),
- "config" + File.separator + "notenoughupdates" +
- File.separator + "repo" + File.separator + "npc" + File.separator +
- displayName.toUpperCase().replace(" ", "_") + ".json"
- );
- 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().replace(" ", "_") + "_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 {
- Utils.addChatMessage("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));
- try {
- //noinspection ResultOfMethodCallIgnored
- file.createNewFile();
- try (
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- Files.newOutputStream(file.toPath()),
- StandardCharsets.UTF_8
- ))
- ) {
- writer.write(gson.toJson(newNPC));
- Utils.addChatMessage(
- EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + displayName);
- }
- } catch (IOException ignored) {
- Utils.addChatMessage(EnumChatFormatting.RED + "Error while writing file.");
- }
- } catch (Exception e) {
- e.printStackTrace();
- Utils.addChatMessage(
- EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details");
- }
+ if (RepoExporters.getInstance().npcExporter()) {
+ event.setCanceled(true);
+ return;
}
} else if (NotEnoughUpdates.INSTANCE.config.hidden.dev && Keyboard.isKeyDown(Keyboard.KEY_B) &&
Minecraft.getMinecraft().currentScreen instanceof GuiChest &&
@@ -1511,43 +1232,7 @@ public class RenderListener {
.getDisplayName()
.getUnformattedText()
.endsWith("Essence")))) {
- GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen;
- ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
- IInventory lower = cc.getLowerChestInventory();
-
- for (int i = 9; 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.getInternalNameForItem(stack);
- if (internalName == null) {
- Utils.addChatMessage(
- EnumChatFormatting.RED + "ERROR: Could not get internal name for: " + EnumChatFormatting.AQUA +
- stack.getDisplayName());
- continue;
- }
- JsonObject itemObject = NotEnoughUpdates.INSTANCE.manager.getJsonForItem(stack);
- JsonArray lore = itemObject.get("lore").getAsJsonArray();
- List<String> loreList = new ArrayList<>();
- for (int j = 0; j < lore.size(); j++) loreList.add(lore.get(j).getAsString());
- if (loreList.get(loreList.size() - 1).equals("§7§eClick to view upgrades!")) {
- loreList.remove(loreList.size() - 1);
- loreList.remove(loreList.size() - 1);
- }
-
- JsonArray newLore = new JsonArray();
- for (String s : loreList) {
- newLore.add(new JsonPrimitive(s));
- }
- itemObject.remove("lore");
- itemObject.add("lore", newLore);
-
- if (!NEUItemEditor.saveOnly(internalName, itemObject)) {
- Utils.addChatMessage(
- EnumChatFormatting.RED + "ERROR: Failed to save item: " + EnumChatFormatting.AQUA + stack.getDisplayName());
- }
- }
- Utils.addChatMessage(EnumChatFormatting.AQUA + "Parsed page: " + lower.getDisplayName().getUnformattedText());
+ RepoExporters.getInstance().essenceExporter2();
event.setCanceled(true);
return;
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/dev/RepoExporters.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/dev/RepoExporters.java
new file mode 100644
index 00000000..ecd7a203
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/dev/RepoExporters.java
@@ -0,0 +1,482 @@
+/*
+ * Copyright (C) 2022 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.miscfeatures.dev;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import io.github.moulberry.notenoughupdates.NEUOverlay;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.itemeditor.NEUItemEditor;
+import io.github.moulberry.notenoughupdates.listener.RenderListener;
+import io.github.moulberry.notenoughupdates.util.ItemUtils;
+import io.github.moulberry.notenoughupdates.util.SBInfo;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.inventory.GuiChest;
+import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
+import net.minecraft.inventory.ContainerChest;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StringUtils;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+
+public class RepoExporters {
+
+ private static final RepoExporters INSTANCE = new RepoExporters();
+
+ public static RepoExporters getInstance() {
+ return INSTANCE;
+ }
+
+ public void essenceExporter() {
+ try {
+ GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen;
+ ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
+ IInventory lower = cc.getLowerChestInventory();
+ File file = new File(
+ Minecraft.getMinecraft().mcDataDir.getAbsolutePath(),
+ "config/notenoughupdates/repo/constants/essencecosts.json"
+ );
+ String fileContent;
+ fileContent = new BufferedReader(new InputStreamReader(
+ Files.newInputStream(file.toPath()),
+ StandardCharsets.UTF_8
+ ))
+ .lines()
+ .collect(Collectors.joining(System.lineSeparator()));
+ String id = null;
+ JsonObject jsonObject = new JsonParser().parse(fileContent).getAsJsonObject();
+ JsonObject newEntry = new JsonObject();
+ for (int i = 0; i < 54; i++) {
+ ItemStack stack = lower.getStackInSlot(i);
+ if (!stack.getDisplayName().isEmpty() && stack.getItem() != Item.getItemFromBlock(Blocks.barrier) &&
+ stack.getItem() != Items.arrow) {
+ if (stack.getTagCompound().getCompoundTag("display").hasKey("Lore", 9)) {
+ int stars = Utils.getNumberOfStars(stack);
+ if (stars == 0) continue;
+
+ NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8);
+ int costIndex = 10000;
+ id = NotEnoughUpdates.INSTANCE.manager
+ .createItemResolutionQuery()
+ .withItemStack(stack)
+ .resolveInternalName();
+ if (jsonObject.has(id)) {
+ jsonObject.remove(id);
+ }
+ for (int j = 0; j < lore.tagCount(); j++) {
+ String entry = lore.getStringTagAt(j);
+ if (entry.equals("§7Cost")) {
+ costIndex = j;
+ }
+ if (j > costIndex) {
+ entry = entry.trim();
+ int index = entry.lastIndexOf('x');
+ String item, amountString;
+ if (index < 0) {
+ item = entry.trim() + " x1";
+ amountString = "x1";
+ } else {
+ amountString = entry.substring(index);
+ item = entry.substring(0, index).trim();
+ }
+ item = item.substring(0, item.length() - 3);
+ int amount = Integer.parseInt(amountString.trim().replace("x", "").replace(",", ""));
+ if (item.endsWith("Essence")) {
+ int index2 = entry.indexOf("Essence");
+ String typeAndAmount = item.substring(0, index2).trim().substring(2);
+ int whitespaceIndex = typeAndAmount.indexOf(' ');
+ int essenceAmount = Integer.parseInt(typeAndAmount
+ .substring(0, whitespaceIndex)
+ .replace(",", ""));
+ newEntry.add("type", new JsonPrimitive(typeAndAmount.substring(whitespaceIndex + 1)));
+ if (stars == -1) {
+ newEntry.add("dungeonize", new JsonPrimitive(essenceAmount));
+ } else {
+ newEntry.add(String.valueOf(stars), new JsonPrimitive(essenceAmount));
+ }
+ } else if (item.endsWith("Coins")) {
+ int index2 = entry.indexOf("Coins");
+ String coinsAmount = item.substring(0, index2).trim().substring(2);
+ if (!newEntry.has("items")) {
+ newEntry.add("items", new JsonObject());
+ }
+ if (!newEntry.get("items").getAsJsonObject().has(String.valueOf(stars))) {
+ newEntry.get("items").getAsJsonObject().add(String.valueOf(stars), new JsonArray());
+ }
+ newEntry
+ .get("items")
+ .getAsJsonObject()
+ .get(String.valueOf(stars))
+ .getAsJsonArray()
+ .add(new JsonPrimitive("SKYBLOCK_COIN:" + coinsAmount.replace(",", "")));
+ } else {
+ String itemString = "_";
+ for (Map.Entry<String, JsonObject> itemEntry : NotEnoughUpdates.INSTANCE.manager
+ .getItemInformation()
+ .entrySet()) {
+
+ if (itemEntry.getValue().has("displayname")) {
+ String name = itemEntry.getValue().get("displayname").getAsString();
+ if (name.equals(item)) {
+ itemString = itemEntry.getKey() + ":" + amount;
+ }
+ }
+ }
+ if (!newEntry.has("items")) {
+ newEntry.add("items", new JsonObject());
+ }
+ if (!newEntry.get("items").getAsJsonObject().has(String.valueOf(stars))) {
+ newEntry.get("items").getAsJsonObject().add(String.valueOf(stars), new JsonArray());
+ }
+ newEntry
+ .get("items")
+ .getAsJsonObject()
+ .get(String.valueOf(stars))
+ .getAsJsonArray()
+ .add(new JsonPrimitive(itemString));
+ }
+ }
+ }
+ jsonObject.add(id, newEntry);
+ }
+ }
+ }
+ if (jsonObject.get(id).getAsJsonObject().has("items")) {
+ JsonObject itemsObj = jsonObject.get(id).getAsJsonObject().get("items").getAsJsonObject();
+ jsonObject.get(id).getAsJsonObject().remove("items");
+ jsonObject.get(id).getAsJsonObject().add("items", itemsObj);
+ }
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ try {
+ try (
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(file.toPath()),
+ StandardCharsets.UTF_8
+ ))
+ ) {
+ writer.write(gson.toJson(jsonObject));
+ Utils.addChatMessage(EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + id);
+ }
+ } catch (IOException ignored) {
+ Utils.addChatMessage(EnumChatFormatting.RED + "Error while writing file.");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Utils.addChatMessage(
+ EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details.");
+ }
+ }
+
+ public void draconicAlterExporter() {
+ try {
+ for (int i = 0; i < 54; i++) {
+ File file = null;
+ String fileContent = null;
+ JsonObject newEntry = new JsonObject();
+ JsonObject jsonObject = null;
+ String id = null;
+ GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen;
+ ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
+ IInventory lower = cc.getLowerChestInventory();
+ ItemStack stack = lower.getStackInSlot(i);
+ if (stack == null) continue;
+ if (!stack.getDisplayName().isEmpty() && stack.getItem() != Item.getItemFromBlock(Blocks.barrier) &&
+ stack.getItem() != Items.arrow) {
+ if (stack.getTagCompound().getCompoundTag("display").hasKey("Lore", 9)) {
+
+ NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8);
+ int costIndex = 10000;
+ id = StringUtils.stripControlCodes(stack.getDisplayName().replace(" ", "_").toUpperCase(Locale.US));
+ id = ItemUtils.fixDraconicId(id);
+ if (!NotEnoughUpdates.INSTANCE.manager.isValidInternalName(id)) continue;
+
+ file = new File(
+ Minecraft.getMinecraft().mcDataDir.getAbsolutePath(),
+ "config/notenoughupdates/repo/items/" + id + ".json"
+ );
+ fileContent = new BufferedReader(new InputStreamReader(
+ Files.newInputStream(file.toPath()),
+ StandardCharsets.UTF_8
+ ))
+ .lines()
+ .collect(Collectors.joining(System.lineSeparator()));
+ jsonObject = new JsonParser().parse(fileContent).getAsJsonObject();
+
+ int essence = -1;
+ boolean funny = true;
+ for (int j = 0; j < lore.tagCount(); j++) {
+ String entry = lore.getStringTagAt(j);
+ if (entry.equals("§8§m-----------------")) {
+ costIndex = j;
+ }
+ if (j > costIndex) {
+ if (j == costIndex + 1) {
+ if (entry.startsWith("§7Dragon Essence: §d")) {
+ essence = Integer.parseInt(entry.substring("§7Dragon Essence: §d".length()));
+ } else {
+ funny = false;
+ }
+ continue;
+ } else if (j == costIndex + 2 && funny) continue;
+ entry = entry.trim();
+ if (!newEntry.has("dragon_items")) {
+ newEntry.add("dragon_items", new JsonArray());
+ }
+ newEntry
+ .get("dragon_items")
+ .getAsJsonArray()
+ .add(new JsonPrimitive(entry.trim()));
+ }
+ }
+ if (essence != -1) jsonObject.add("dragon_essence", new JsonPrimitive(essence));
+ jsonObject.add("dragon_items", newEntry.get("dragon_items"));
+ }
+ }
+ if (jsonObject == null) continue;
+ if (jsonObject.has("dragon_items")) {
+ JsonArray itemsObj = jsonObject.get("dragon_items").getAsJsonArray();
+ jsonObject.remove("dragon_items");
+ jsonObject.add("dragon_items", itemsObj);
+ }
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ try {
+ try (
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(file.toPath()),
+ StandardCharsets.UTF_8
+ ))
+ ) {
+ writer.write(gson.toJson(jsonObject));
+ Utils.addChatMessage(
+ EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + id);
+ }
+ } catch (IOException ignored) {
+ Utils.addChatMessage(
+ EnumChatFormatting.RED + "Error while writing file.");
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
+ EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details."));
+ }
+ }
+
+ private HashMap<String, String> cachedDefinitions;
+ private String correctingItem;
+
+ public boolean npcExporter() {
+ if (RenderListener.typing) {
+ RenderListener.typing = false;
+ cachedDefinitions.put(correctingItem, NEUOverlay.getTextField().getText());
+ NEUOverlay.getTextField().setText("");
+ }
+ if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) {
+ Minecraft mc = Minecraft.getMinecraft();
+ 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();
+ File file = new File(
+ Minecraft.getMinecraft().mcDataDir.getAbsolutePath(),
+ "config" + File.separator + "notenoughupdates" +
+ File.separator + "repo" + File.separator + "npc" + File.separator +
+ displayName.toUpperCase().replace(" ", "_") + ".json"
+ );
+ 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().replace(" ", "_") + "_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 {
+ Utils.addChatMessage("Change the item ID of " + item + " to the correct one and press Enter.");
+ NEUOverlay.getTextField().setText(item);
+ RenderListener.typing = true;
+ correctingItem = item;
+ if (cachedDefinitions == null) {
+ cachedDefinitions = new HashMap<>();
+ }
+ return true;
+ }
+ }
+ }
+ 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));
+ try {
+ //noinspection ResultOfMethodCallIgnored
+ file.createNewFile();
+ try (
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(file.toPath()),
+ StandardCharsets.UTF_8
+ ))
+ ) {
+ writer.write(gson.toJson(newNPC));
+ Utils.addChatMessage(
+ EnumChatFormatting.AQUA + "Parsed and saved: " + EnumChatFormatting.WHITE + displayName);
+ }
+ } catch (IOException ignored) {
+ Utils.addChatMessage(EnumChatFormatting.RED + "Error while writing file.");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Utils.addChatMessage(
+ EnumChatFormatting.RED + "Error while parsing inventory. Try again or check logs for details");
+ }
+ }
+ return false;
+ }
+
+ public void essenceExporter2() {
+ GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen;
+ ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
+ IInventory lower = cc.getLowerChestInventory();
+
+ for (int i = 9; 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.getInternalNameForItem(stack);
+ if (internalName == null) {
+ Utils.addChatMessage(
+ EnumChatFormatting.RED + "ERROR: Could not get internal name for: " + EnumChatFormatting.AQUA +
+ stack.getDisplayName());
+ continue;
+ }
+ JsonObject itemObject = NotEnoughUpdates.INSTANCE.manager.getJsonForItem(stack);
+ JsonArray lore = itemObject.get("lore").getAsJsonArray();
+ List<String> loreList = new ArrayList<>();
+ for (int j = 0; j < lore.size(); j++) loreList.add(lore.get(j).getAsString());
+ if (loreList.get(loreList.size() - 1).equals("§7§eClick to view upgrades!")) {
+ loreList.remove(loreList.size() - 1);
+ loreList.remove(loreList.size() - 1);
+ }
+
+ JsonArray newLore = new JsonArray();
+ for (String s : loreList) {
+ newLore.add(new JsonPrimitive(s));
+ }
+ itemObject.remove("lore");
+ itemObject.add("lore", newLore);
+
+ if (!NEUItemEditor.saveOnly(internalName, itemObject)) {
+ Utils.addChatMessage(
+ EnumChatFormatting.RED + "ERROR: Failed to save item: " + EnumChatFormatting.AQUA + stack.getDisplayName());
+ }
+ }
+ Utils.addChatMessage(EnumChatFormatting.AQUA + "Parsed page: " + lower.getDisplayName().getUnformattedText());
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java
index 6cc1bbe7..3e2dd465 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java
@@ -417,4 +417,13 @@ public class ItemUtils {
line.equals("§8§l* Soulbound §8§l*"));
}
+ public static String fixDraconicId(String id) {
+ if (id.equals("ASPECT_OF_THE_DRAGONS")) return "ASPECT_OF_THE_DRAGON";
+ if (id.equals("ENDER_HELMET")) return "END_HELMET";
+ if (id.equals("ENDER_CHESTPLATE")) return "END_CHESTPLATE";
+ if (id.equals("ENDER_LEGGINGS")) return "END_LEGGINGS";
+ if (id.equals("ENDER_BOOTS")) return "END_BOOTS";
+ return id;
+ }
+
}