diff options
author | Roman / Linnea Gräf <roman.graef@gmail.com> | 2023-03-13 23:43:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 23:43:40 +0100 |
commit | 86cd165c1ad9a72567cf5d033a8ff92779f72b30 (patch) | |
tree | 55960f96bd155aaa29ca03c5f79e61f830aa0ae0 /src/main/java/io | |
parent | d249bbdc8e99bfdab81aa6b215e70c4f21def91e (diff) | |
download | NotEnoughUpdates-86cd165c1ad9a72567cf5d033a8ff92779f72b30.tar.gz NotEnoughUpdates-86cd165c1ad9a72567cf5d033a8ff92779f72b30.tar.bz2 NotEnoughUpdates-86cd165c1ad9a72567cf5d033a8ff92779f72b30.zip |
Improve NPC shop generator (#650)
Diffstat (limited to 'src/main/java/io')
4 files changed, 16 insertions, 151 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 5eab77f9..0281d95b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -1193,6 +1193,19 @@ public class NEUManager { json.addProperty("crafttext", crafttext); json.addProperty("clickcommand", clickcommand); json.addProperty("damage", damage); + nbttag.setInteger("HideFlags", 254); + NBTTagCompound display = nbttag.getCompoundTag("display"); + nbttag.setTag("display", display); + display.setString("Name", displayName); + NBTTagList loreList = new NBTTagList(); + for (String loreLine : lore) { + loreList.appendTag(new NBTTagString(loreLine)); + } + display.setTag("Lore", loreList); + NBTTagCompound extraAttributes = nbttag.getCompoundTag("ExtraAttributes"); + nbttag.setTag("ExtraAttributes", extraAttributes); + extraAttributes.setString("id", internalname); + json.addProperty("nbttag", nbttag.toString()); json.addProperty("modver", NotEnoughUpdates.VERSION); json.addProperty("infoType", infoType); @@ -1265,6 +1278,7 @@ public class NEUManager { } public void writeJson(JsonObject json, File file) throws IOException { + file.getParentFile().mkdirs(); file.createNewFile(); try ( 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 5e39aa45..d324184f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -128,8 +128,6 @@ public class RenderListener { private String loadedInvName = ""; //NPC parsing - public static boolean typing; - private boolean inDungeonPage = false; public RenderListener(NotEnoughUpdates neu) { @@ -1075,9 +1073,6 @@ public class RenderListener { event.setCanceled(true); return; } - if (typing) { - event.setCanceled(true); - } if (NotEnoughUpdates.INSTANCE.config.hidden.dev && Keyboard.isKeyDown(Keyboard.KEY_B) && Minecraft.getMinecraft().currentScreen instanceof GuiChest ) { @@ -1092,11 +1087,6 @@ public class RenderListener { } else if (lower.getName().contains("Draconic Altar Guide")) { RepoExporters.getInstance().draconicAlterExporter(); } - } else if (Keyboard.isKeyDown(Keyboard.KEY_RETURN) && NotEnoughUpdates.INSTANCE.config.hidden.dev) { - 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 && ((((ContainerChest) ((GuiChest) Minecraft.getMinecraft().currentScreen).inventorySlots) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java index 9bdc4608..86e49aec 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java @@ -111,7 +111,8 @@ public class Navigation { private Teleporter nextTeleporter = null; public boolean isValidWaypoint(JsonObject object) { - return object.has("x") + return object != null + && object.has("x") && object.has("y") && object.has("z") && object.has("island") 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 index ecd7a203..259aadc0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/dev/RepoExporters.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/dev/RepoExporters.java @@ -25,12 +25,9 @@ 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; @@ -54,11 +51,9 @@ 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 { @@ -304,141 +299,6 @@ public class RepoExporters { } } - 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; |