diff options
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java | 42 |
1 files changed, 22 insertions, 20 deletions
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 6460e1ed..a49b9e6d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -1239,6 +1239,7 @@ public class RenderListener { if (stack.getTagCompound().getCompoundTag("display").hasKey("Lore", 9)) { int stars = Utils.getNumberOfStars(stack); if (stars == 0) continue; + String starsStr = "" + stars; NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8); int costIndex = 10000; @@ -1251,38 +1252,39 @@ public class RenderListener { 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(); + + int countIndex = entry.lastIndexOf(" §8x"); + + String upgradeName = entry; + String amount = "1"; + if (countIndex != -1) { + upgradeName = entry.substring(0, countIndex); + // +4 to account for " §8x" + amount = entry.substring(countIndex + 4); } - 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 type = item.substring(0, index2).trim().substring(2); - newEntry.add("type", new JsonPrimitive(type)); - newEntry.add(String.valueOf(stars), new JsonPrimitive(amount)); + + if (upgradeName.endsWith(" Essence")) { + // First 2 chars are control code + // [EssenceCount, EssenceType, "Essence"] + String[] upgradeNameSplit = upgradeName.substring(2).split(" "); + newEntry.addProperty("type", upgradeNameSplit[1]); + newEntry.addProperty(starsStr, Integer.parseInt(upgradeNameSplit[0].replace(",", ""))); } else { - String itemString = item + " §8x" + 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()); + if (!newEntry.get("items").getAsJsonObject().has(starsStr)) { + newEntry.get("items").getAsJsonObject().add(starsStr, new JsonArray()); } newEntry .get("items") .getAsJsonObject() - .get(String.valueOf(stars)) + .get(starsStr) .getAsJsonArray() - .add(new JsonPrimitive(itemString)); + .add(new JsonPrimitive(upgradeName + (upgradeName.contains("Coins") ? "" : (" §8x" + amount)))); } } } |