From 94054563ff1d595253a4e50cf48b22fc77a05515 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Tue, 13 Sep 2022 02:31:56 +1000 Subject: Fix enchantment table overlay (#238) Co-authored-by: nea --- .../listener/ItemTooltipListener.java | 7 +- .../listener/NEUEventListener.java | 4 + .../notenoughupdates/listener/RenderListener.java | 22 + .../notenoughupdates/miscgui/CalendarOverlay.java | 5 +- .../notenoughupdates/miscgui/GuiCustomEnchant.java | 309 +- .../notenoughupdates/miscgui/hex/EnchantState.java | 37 + .../notenoughupdates/miscgui/hex/GuiCustomHex.java | 4794 ++++++++++++++++++++ .../notenoughupdates/miscgui/hex/HexItem.java | 264 ++ .../notenoughupdates/miscgui/hex/ItemType.java | 84 + .../miscgui/util/ExperienceOrb.java | 32 + .../notenoughupdates/miscgui/util/OrbDisplay.java | 142 + .../notenoughupdates/mixins/MixinGuiContainer.java | 2 + 12 files changed, 5519 insertions(+), 183 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/EnchantState.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/HexItem.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/ItemType.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/ExperienceOrb.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/OrbDisplay.java (limited to 'src') 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 3936ad74..d4e0becd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java @@ -906,11 +906,16 @@ public class ItemTooltipListener { boolean m = Keyboard.isKeyDown(Keyboard.KEY_M); boolean n = Keyboard.isKeyDown(Keyboard.KEY_N); boolean f = Keyboard.isKeyDown(Keyboard.KEY_F); + boolean l = Keyboard.isKeyDown(Keyboard.KEY_L); if (!copied && f && NotEnoughUpdates.INSTANCE.config.hidden.dev) { MiscUtils.copyToClipboard(NotEnoughUpdates.INSTANCE.manager.getSkullValueForItem(event.itemStack)); } + if (!copied && l) { + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableTableGUI = !NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableTableGUI; + } + event.toolTip.add( EnumChatFormatting.AQUA + "Internal Name: " + EnumChatFormatting.GRAY + internal + EnumChatFormatting.GOLD + " [K]"); @@ -948,7 +953,7 @@ public class ItemTooltipListener { } } - copied = k || m || n || f; + copied = k || m || n || f || l; } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java index 305135fc..e202b828 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java @@ -34,6 +34,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.miscfeatures.NPCRetexturing; import io.github.moulberry.notenoughupdates.miscgui.AccessoryBagOverlay; import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; +import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; @@ -144,6 +145,9 @@ public class NEUEventListener { if (GuiCustomEnchant.getInstance().shouldOverride(containerName)) { GuiCustomEnchant.getInstance().tick(); } + if (GuiCustomHex.getInstance().shouldOverride(containerName)) { + GuiCustomHex.getInstance().tick(containerName); + } } //MiningOverlay and TimersOverlay need real tick speed 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 a8d69c87..c822a51d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -45,6 +45,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.miscgui.AccessoryBagOverlay; import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay; import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; +import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; @@ -445,12 +446,19 @@ public class RenderListener { containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); } + if (GuiCustomHex.getInstance().shouldOverride(containerName)) { + GuiCustomHex.getInstance().render(event.renderPartialTicks, containerName); + event.setCanceled(true); + return; + } + if (GuiCustomEnchant.getInstance().shouldOverride(containerName)) { GuiCustomEnchant.getInstance().render(event.renderPartialTicks); event.setCanceled(true); return; } + boolean tradeWindowActive = TradeWindow.tradeWindowActive(containerName); boolean storageOverlayActive = StorageManager.getInstance().shouldRenderStorageOverlay(containerName); boolean customAhActive = @@ -595,6 +603,7 @@ public class RenderListener { ContainerChest cc = (ContainerChest) eventGui.inventorySlots; containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if (GuiCustomHex.getInstance().shouldOverride(containerName)) return; if (GuiCustomEnchant.getInstance().shouldOverride(containerName)) return; } @@ -1050,12 +1059,18 @@ public class RenderListener { } } + if (GuiCustomHex.getInstance().shouldOverride(containerName) && + GuiCustomHex.getInstance().mouseInput(mouseX, mouseY)) { + event.setCanceled(true); + return; + } if (GuiCustomEnchant.getInstance().shouldOverride(containerName) && GuiCustomEnchant.getInstance().mouseInput(mouseX, mouseY)) { event.setCanceled(true); return; } + boolean tradeWindowActive = TradeWindow.tradeWindowActive(containerName); boolean storageOverlayActive = StorageManager.getInstance().shouldRenderStorageOverlay(containerName); boolean customAhActive = @@ -1519,12 +1534,19 @@ public class RenderListener { .getUnformattedText(); } + if (GuiCustomHex.getInstance().shouldOverride(containerName) && + GuiCustomHex.getInstance().keyboardInput()) { + event.setCanceled(true); + return; + } + if (GuiCustomEnchant.getInstance().shouldOverride(containerName) && GuiCustomEnchant.getInstance().keyboardInput()) { event.setCanceled(true); return; } + boolean tradeWindowActive = TradeWindow.tradeWindowActive(containerName); boolean storageOverlayActive = StorageManager.getInstance().shouldRenderStorageOverlay(containerName); boolean customAhActive = diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java index 2905a941..b1a3dca9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java @@ -75,6 +75,8 @@ public class CalendarOverlay { private static boolean enabled = false; + public static boolean ableToClickCalendar = true; + public static void setEnabled(boolean enabled) { CalendarOverlay.enabled = enabled; } @@ -479,8 +481,7 @@ public class CalendarOverlay { guiLeft = (width - xSize) / 2; guiTop = 5; - - if (mouseX >= guiLeft && mouseX <= guiLeft + xSize) { + if (mouseX >= guiLeft && mouseX <= guiLeft + xSize && ableToClickCalendar) { if (mouseY >= guiTop && mouseY <= guiTop + ySize) { ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/neucalendar"); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java index 8ba3a98a..cbf98290 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java @@ -28,6 +28,7 @@ import io.github.moulberry.notenoughupdates.core.GuiElementTextField; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingFloat; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; +import io.github.moulberry.notenoughupdates.miscgui.util.OrbDisplay; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.Constants; @@ -74,9 +75,9 @@ public class GuiCustomEnchant extends Gui { "textures/entity/enchanting_table_book.png"); private static final ModelBook MODEL_BOOK = new ModelBook(); - private static final int EXPERIENCE_ORB_COUNT = 30; - private static final Pattern XP_COST_PATTERN = Pattern.compile("\\u00a73(\\d+) Exp Levels"); + private static final Pattern ENCHANT_LEVEL_PATTERN = Pattern.compile("(.*)_(.*)"); + private static final Pattern ENCHANT_NAME_PATTERN = Pattern.compile("([^IVX]*) ([IVX]*)"); private enum EnchantState { NO_ITEM, @@ -105,6 +106,10 @@ public class GuiCustomEnchant extends Gui { this.enchId = enchId; this.displayLore = displayLore; this.level = level; + if (this.enchId.equals("prosecute")) { + this.enchId = "PROSECUTE"; + } + if (Constants.ENCHANTS != null) { if (checkConflicts && Constants.ENCHANTS.has("enchant_pools")) { @@ -133,12 +138,18 @@ public class GuiCustomEnchant extends Gui { if (level >= 1 && Constants.ENCHANTS.has("enchants_xp_cost")) { JsonObject allCosts = Constants.ENCHANTS.getAsJsonObject("enchants_xp_cost"); + JsonObject maxLevel = null; + if (Constants.ENCHANTS.has("max_xp_table_levels")) { + maxLevel = Constants.ENCHANTS.getAsJsonObject("max_xp_table_levels"); + } + if (allCosts.has(enchId)) { JsonArray costs = allCosts.getAsJsonArray(enchId); if (costs.size() >= 1) { if (useMaxLevelForCost) { - this.xpCost = costs.get(costs.size() - 1).getAsInt(); + int cost = (maxLevel != null && maxLevel.has(enchId) ? maxLevel.get(enchId).getAsInt() : costs.size()); + this.xpCost = costs.get(cost - 1).getAsInt(); } else if (level - 1 < costs.size()) { this.xpCost = costs.get(level - 1).getAsInt(); } else { @@ -152,21 +163,7 @@ public class GuiCustomEnchant extends Gui { } } - public static class ExperienceOrb { - public float x; - public float y; - public float xLast; - public float yLast; - public float xVel; - public float yVel; - - public int type; - public int rotationDeg; - } - - private final List orbs = new ArrayList<>(); - private int orbTargetX = 0; - private int orbTargetY = 0; + public OrbDisplay orbDisplay = new OrbDisplay(); private int guiLeft; private int guiTop; @@ -226,8 +223,15 @@ public class GuiCustomEnchant extends Gui { } public boolean shouldOverride(String containerName) { + if (containerName == null) { + shouldOverrideFast = false; + return false; + } shouldOverrideFast = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableTableGUI && - Objects.equals("Enchant Item", containerName) && + (containerName.length() >= 12 && Objects.equals( + "Enchant Item", + containerName.substring(0, "Enchant Item".length()) + )) && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard(); if (!shouldOverrideFast) { currentState = EnchantState.NO_ITEM; @@ -235,6 +239,10 @@ public class GuiCustomEnchant extends Gui { removable.clear(); expectedMaxPage = 1; } + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + ItemStack hexStack = cc.getLowerChestInventory().getStackInSlot(50); + if (hexStack != null && hexStack.getItem() == Items.experience_bottle) return false; return shouldOverrideFast; } @@ -245,13 +253,15 @@ public class GuiCustomEnchant extends Gui { ContainerChest cc = (ContainerChest) chest.inventorySlots; ItemStack stack = cc.getLowerChestInventory().getStackInSlot(23); - ItemStack enchantGuideStack = cc.getLowerChestInventory().getStackInSlot(50); + ItemStack arrowStack = cc.getLowerChestInventory().getStackInSlot(45); ItemStack enchantingItemStack = cc.getLowerChestInventory().getStackInSlot(19); + ItemStack hexStack = cc.getLowerChestInventory().getStackInSlot(50); int lastPage = currentPage; this.lastState = currentState; - if (enchantGuideStack != null && enchantGuideStack.getItem() != Items.book && enchantingItem != null) { + if (hexStack != null && hexStack.getItem() == Items.experience_bottle) return; + if (arrowStack != null && arrowStack.getItem() == Items.arrow && enchantingItem != null) { currentState = EnchantState.ADDING_ENCHANT; } else if (stack == null || enchantingItemStack == null) { if (currentState == EnchantState.SWITCHING_DONT_UPDATE || currentState == EnchantState.NO_ITEM) { @@ -305,30 +315,7 @@ public class GuiCustomEnchant extends Gui { } } - List toRemove = new ArrayList<>(); - for (ExperienceOrb orb : orbs) { - float targetDeltaX = guiLeft + orbTargetX - orb.x; - float targetDeltaY = guiTop + orbTargetY - orb.y; - - float length = (float) Math.sqrt(targetDeltaX * targetDeltaX + targetDeltaY * targetDeltaY); - - if (length < 8 && orb.xVel * orb.xVel + orb.yVel * orb.yVel < 20) { - toRemove.add(orb); - continue; - } - - orb.xVel += targetDeltaX * 2 / length; - orb.yVel += targetDeltaY * 2 / length; - - orb.xVel *= 0.90; - orb.yVel *= 0.90; - - orb.xLast = orb.x; - orb.yLast = orb.y; - orb.x += orb.xVel; - orb.y += orb.yVel; - } - orbs.removeAll(toRemove); + orbDisplay.physicsTickOrbs(); if (++tickCounter >= 20) { tickCounter = 0; @@ -389,40 +376,48 @@ public class GuiCustomEnchant extends Gui { if (ea != null) { NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); if (enchantments != null) { - for (String enchId : enchantments.getKeySet()) { - String name = Utils.cleanColour(book.getDisplayName()); - if (name.equalsIgnoreCase("Bane of Arthropods")) { - name = "Bane of Arth."; - } else if (name.equalsIgnoreCase("Projectile Protection")) { - name = "Projectile Prot"; - } else if (name.equalsIgnoreCase("Blast Protection")) { - name = "Blast Prot"; - } - Enchantment enchantment = new Enchantment(slotIndex, name, enchId, - Utils.getRawTooltip(book), enchantments.getInteger(enchId), false, true - ); - enchantment.displayLore.remove(0); + String enchId = Utils.cleanColour(book.getDisplayName()).toLowerCase().replace(" ", "_").replace( + "-", + "_" + ); + String name = Utils.cleanColour(book.getDisplayName()); + int enchLevel = -1; + if (name.equalsIgnoreCase("Bane of Arthropods")) { + name = "Bane of Arth."; + } else if (name.equalsIgnoreCase("Projectile Protection")) { + name = "Projectile Prot"; + } else if (name.equalsIgnoreCase("Blast Protection")) { + name = "Blast Prot"; + } + Matcher levelMatcher = ENCHANT_LEVEL_PATTERN.matcher(enchId); + if (levelMatcher.matches()) { + enchLevel = Utils.parseRomanNumeral(levelMatcher.group(2).toUpperCase()); + enchId = levelMatcher.group(1); + } + Enchantment enchantment = new Enchantment(slotIndex, name, enchId, + Utils.getRawTooltip(book), enchLevel, false, true + ); + enchantment.displayLore.remove(0); - if (removingEnchantPlayerLevel == -1 && playerEnchantIds.containsKey(enchId)) { - removingEnchantPlayerLevel = playerEnchantIds.get(enchId); - } + if (removingEnchantPlayerLevel == -1 && playerEnchantIds.containsKey(enchId)) { + removingEnchantPlayerLevel = playerEnchantIds.get(enchId); + } - if (removingEnchantPlayerLevel >= 0 && enchantment.level < removingEnchantPlayerLevel) { - continue; - } + if (removingEnchantPlayerLevel >= 0 && enchantment.level < removingEnchantPlayerLevel) { + continue; + } - if (enchanterCurrentEnch == null) { + if (enchanterCurrentEnch == null) { + enchanterCurrentEnch = enchantment; + } else if (updateLevel) { + if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level) { + enchanterCurrentEnch = enchantment; + } else if (removingEnchantPlayerLevel >= 0 && enchantment.level < enchanterCurrentEnch.level) { enchanterCurrentEnch = enchantment; - } else if (updateLevel) { - if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level) { - enchanterCurrentEnch = enchantment; - } else if (removingEnchantPlayerLevel >= 0 && enchantment.level < enchanterCurrentEnch.level) { - enchanterCurrentEnch = enchantment; - } } - - enchanterEnchLevels.put(enchantment.level, enchantment); } + + enchanterEnchLevels.put(enchantment.level, enchantment); } } } @@ -455,43 +450,54 @@ public class GuiCustomEnchant extends Gui { if (ea != null) { NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); if (enchantments != null) { - for (String enchId : enchantments.getKeySet()) { - String name = Utils.cleanColour(book.getDisplayName()); - - if (searchField.getText().trim().isEmpty() || - name.toLowerCase().contains(searchField.getText().trim().toLowerCase())) { - if (name.equalsIgnoreCase("Bane of Arthropods")) { - name = "Bane of Arth."; - } else if (name.equalsIgnoreCase("Projectile Protection")) { - name = "Projectile Prot"; - } else if (name.equalsIgnoreCase("Blast Protection")) { - name = "Blast Prot"; - } else if (name.equalsIgnoreCase("Luck of the Sea")) { - name = "Luck of Sea"; - } + String enchId = Utils + .cleanColour(book.getDisplayName()) + .toLowerCase() + .replace(" ", "_") + .replace("-", "_"); + if (enchId.equalsIgnoreCase("_")) continue; + if (enchId.equals("prosecute")) { + enchId = "PROSECUTE"; + } + String name = Utils.cleanColour(book.getDisplayName()); + + if (searchField.getText().trim().isEmpty() || + name.toLowerCase().contains(searchField.getText().trim().toLowerCase())) { + if (name.equalsIgnoreCase("Bane of Arthropods")) { + name = "Bane of Arth."; + } else if (name.equalsIgnoreCase("Projectile Protection")) { + name = "Projectile Prot"; + } else if (name.equalsIgnoreCase("Blast Protection")) { + name = "Blast Prot"; + } else if (name.equalsIgnoreCase("Luck of the Sea")) { + name = "Luck of Sea"; + } + Matcher nameMatcher = ENCHANT_NAME_PATTERN.matcher(name); + if (nameMatcher.matches()) { + name = nameMatcher.group(1); + } - if (playerEnchantIds.containsKey(enchId)) { - Enchantment enchantment = new Enchantment(slotIndex, name, enchId, - Utils.getRawTooltip(book), playerEnchantIds.get(enchId), false, false - ); - if (!enchantment.overMaxLevel) { - removable.add(enchantment); - } - } else { - Enchantment enchantment = new Enchantment(slotIndex, name, enchId, - Utils.getRawTooltip(book), enchantments.getInteger(enchId), true, true - ); - applicable.add(enchantment); + if (playerEnchantIds.containsKey(enchId)) { + Enchantment enchantment = new Enchantment(slotIndex, name, enchId, + Utils.getRawTooltip(book), playerEnchantIds.get(enchId), false, false + ); + if (!enchantment.overMaxLevel) { + removable.add(enchantment); } } else { - if (playerEnchantIds.containsKey(enchId)) { - searchRemovedFromRemovable = true; - } else { - searchRemovedFromApplicable = true; - } + Enchantment enchantment = new Enchantment(slotIndex, name, enchId, + Utils.getRawTooltip(book), 1, true, true + ); + applicable.add(enchantment); + } + } else { + if (playerEnchantIds.containsKey(enchId)) { + searchRemovedFromRemovable = true; + } else { + searchRemovedFromApplicable = true; } - } + } } } @@ -1356,37 +1362,11 @@ public class GuiCustomEnchant extends Gui { //Orb animation Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); - GlStateManager.color(1, 1, 1, 1); GlStateManager.disableDepth(); - for (ExperienceOrb orb : orbs) { - int orbX = Math.round(orb.xLast + (orb.x - orb.xLast) * partialTicks); - int orbY = Math.round(orb.yLast + (orb.y - orb.yLast) * partialTicks); - GlStateManager.pushMatrix(); - GlStateManager.translate(orbX, orbY, 0); - GlStateManager.rotate(orb.rotationDeg, 0, 0, 1); - - float targetDeltaX = guiLeft + orbTargetX - orb.x; - float targetDeltaY = guiTop + orbTargetY - orb.y; - float length = (float) Math.sqrt(targetDeltaX * targetDeltaX + targetDeltaY * targetDeltaY); - float velSq = orb.xVel * orb.xVel + orb.yVel * orb.yVel; - float opacity = Math.min(2, Math.max(0.5f, length / 16)) * Math.min(2, Math.max(0.5f, velSq / 40)); - if (opacity > 1) opacity = 1; - opacity = (float) Math.sqrt(opacity); - GlStateManager.color(1, 1, 1, opacity); - - Utils.drawTexturedRect( - -8, - -8, - 16, - 16, - ((orb.type % 3) * 16) / 512f, - (16 + (orb.type % 3) * 16) / 512f, - (217 + orb.type / 3 * 16) / 512f, - (217 + 16 + orb.type / 3 * 16) / 512f, - GL11.GL_NEAREST - ); - GlStateManager.popMatrix(); - } + GlStateManager.pushMatrix(); + GlStateManager.translate(guiLeft, guiTop, 0); + orbDisplay.renderOrbs(partialTicks); + GlStateManager.popMatrix(); GlStateManager.enableDepth(); if (stackOnMouse != null) { @@ -1403,37 +1383,6 @@ public class GuiCustomEnchant extends Gui { GlStateManager.translate(0, 0, -300); } - private void spawnExperienceOrbs(int startX, int startY, int targetX, int targetY, int baseType) { - orbs.clear(); - - this.orbTargetX = targetX; - this.orbTargetY = targetY; - - Random rand = new Random(); - for (int i = 0; i < EXPERIENCE_ORB_COUNT; i++) { - ExperienceOrb orb = new ExperienceOrb(); - orb.x = startX; - orb.y = startY; - orb.xLast = startX; - orb.yLast = startY; - orb.xVel = rand.nextFloat() * 20 - 10; - orb.yVel = rand.nextFloat() * 20 - 10; - orb.type = baseType; - - float typeRand = rand.nextFloat(); - if (typeRand < 0.6) { - orb.type += 0; - } else if (typeRand < 0.9) { - orb.type += 1; - } else { - orb.type += 2; - } - orb.rotationDeg = rand.nextInt(4) * 90; - - orbs.add(orb); - } - } - private void renderEnchantBook(ScaledResolution scaledresolution, float partialTicks) { GlStateManager.enableDepth(); @@ -1540,9 +1489,9 @@ public class GuiCustomEnchant extends Gui { EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); - ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(48); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( - chest.inventorySlots.windowId, 48, 0, 0, stack, transactionID)); + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); cancelButtonAnimTime = System.currentTimeMillis(); } @@ -1592,9 +1541,9 @@ public class GuiCustomEnchant extends Gui { EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); - ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(48); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( - chest.inventorySlots.windowId, 48, 0, 0, stack, transactionID)); + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); cancelButtonAnimTime = System.currentTimeMillis(); } else if (!isChangingEnchLevel && enchanterCurrentEnch != null && @@ -1617,9 +1566,9 @@ public class GuiCustomEnchant extends Gui { int playerXpLevel = Minecraft.getMinecraft().thePlayer.experienceLevel; if (playerXpLevel >= enchanterCurrentEnch.xpCost) { if (removingEnchantPlayerLevel >= 0 && enchanterCurrentEnch.level == removingEnchantPlayerLevel) { - spawnExperienceOrbs(guiLeft + X_SIZE / 2, guiTop + 66, X_SIZE / 2, 36, 3); + orbDisplay.spawnExperienceOrbs(X_SIZE / 2, 66, X_SIZE / 2, 36, 3); } else { - spawnExperienceOrbs(mouseX, mouseY, X_SIZE / 2, 66, 0); + orbDisplay.spawnExperienceOrbs(mouseX - guiLeft, mouseY - guiTop, X_SIZE / 2, 66, 0); } } @@ -1790,9 +1739,9 @@ public class GuiCustomEnchant extends Gui { } else if (currentState == EnchantState.ADDING_ENCHANT) { EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); - ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(48); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( - chest.inventorySlots.windowId, 48, 0, 0, stack, transactionID)); + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); cancelButtonAnimTime = System.currentTimeMillis(); } @@ -1830,9 +1779,9 @@ public class GuiCustomEnchant extends Gui { } else if (currentState == EnchantState.ADDING_ENCHANT) { EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); - ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(48); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( - chest.inventorySlots.windowId, 48, 0, 0, stack, transactionID)); + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); cancelButtonAnimTime = System.currentTimeMillis(); } @@ -1877,9 +1826,9 @@ public class GuiCustomEnchant extends Gui { EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); - ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(48); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( - chest.inventorySlots.windowId, 48, 0, 0, stack, transactionID)); + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); cancelButtonAnimTime = System.currentTimeMillis(); } @@ -1898,9 +1847,9 @@ public class GuiCustomEnchant extends Gui { EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); - ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(48); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( - chest.inventorySlots.windowId, 48, 0, 0, stack, transactionID)); + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); cancelButtonAnimTime = System.currentTimeMillis(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/EnchantState.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/EnchantState.java new file mode 100644 index 00000000..08e720a2 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/EnchantState.java @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.hex; + +enum EnchantState { + NO_ITEM, + ADDING_ENCHANT, + SWITCHING_DONT_UPDATE, + INVALID_ITEM, + HAS_ITEM, + HAS_ITEM_IN_HEX, + HAS_ITEM_IN_BOOKS, + ADDING_BOOK, + NO_ITEM_IN_HEX, + INVALID_ITEM_HEX, + HAS_ITEM_IN_GEMSTONE, + ADDING_GEMSTONE, + APPLYING_GEMSTONE + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java new file mode 100644 index 00000000..39374f9d --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java @@ -0,0 +1,4794 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.hex; + +import com.google.common.collect.Lists; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.GlScissorStack; +import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingFloat; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; +import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; +import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay; +import io.github.moulberry.notenoughupdates.miscgui.util.OrbDisplay; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; +import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.model.ModelBook; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.ContainerChest; +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.network.play.client.C0EPacketClickWindow; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.lang3.text.WordUtils; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.glu.Project; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Objects; +import java.util.Random; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class GuiCustomHex extends Gui { + private static final GuiCustomHex INSTANCE = new GuiCustomHex(); + private static final ResourceLocation TEXTURE = new ResourceLocation("notenoughupdates:custom_enchant_gui.png"); + private static final ResourceLocation ENCHANTMENT_TABLE_BOOK_TEXTURE = new ResourceLocation( + "textures/entity/enchanting_table_book.png"); + private static final ModelBook MODEL_BOOK = new ModelBook(); + + private static final int EXPERIENCE_ORB_COUNT = 30; + + private static final Pattern XP_COST_PATTERN = Pattern.compile("\\u00a73(\\d+) Exp Levels"); + private static final Pattern ENCHANT_LEVEL_PATTERN = Pattern.compile("(.*)_(.*)"); + private static final Pattern ENCHANT_NAME_PATTERN = Pattern.compile("([^IVX]*) ([IVX]*)"); + + public static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); + + public class Enchantment { + public int slotIndex; + public String enchantName; + public String enchId; + public List displayLore; + public int level; + public int xpCost = -1; + public boolean overMaxLevel = false; + public boolean conflicts = false; + public int price = -1; + + public Enchantment( + int slotIndex, String enchantName, String enchId, List displayLore, int level, + boolean useMaxLevelForCost, boolean checkConflicts + ) { + this.slotIndex = slotIndex; + this.enchantName = enchantName; + this.enchId = enchId; + this.displayLore = displayLore; + this.level = level; + boolean isUlt = false; + for (String lore : displayLore) { + if (lore.contains("§l")) isUlt = true; + break; + } + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo( + (isUlt ? "ULTIMATE_" : "") + enchId.toUpperCase() + ";" + level); + if (bazaarInfo != null && bazaarInfo.get("curr_buy") != null) { + this.price = bazaarInfo.get("curr_buy").getAsInt(); + } + if (this.enchId.equals("prosecute")) { + this.enchId = "PROSECUTE"; + } + + if (Constants.ENCHANTS != null) { + if (checkConflicts && Constants.ENCHANTS.has("enchant_pools")) { + JsonArray pools = Constants.ENCHANTS.getAsJsonArray("enchant_pools"); + out: + for (int i = 0; i < pools.size(); i++) { + JsonArray pool = pools.get(i).getAsJsonArray(); + + boolean hasThis = false; + boolean hasApplied = false; + + for (int j = 0; j < pool.size(); j++) { + String enchIdPoolElement = pool.get(j).getAsString(); + if (enchId.equalsIgnoreCase(enchIdPoolElement)) { + hasThis = true; + } else if (playerEnchantIds.containsKey(enchIdPoolElement)) { + hasApplied = true; + } + if (hasThis && hasApplied) { + this.conflicts = true; + break out; + } + } + } + } + + if (level >= 1 && Constants.ENCHANTS.has("enchants_xp_cost")) { + JsonObject allCosts = Constants.ENCHANTS.getAsJsonObject("enchants_xp_cost"); + if (allCosts.has(enchId)) { + JsonArray costs = allCosts.getAsJsonArray(enchId); + + if (costs.size() >= 1) { + if (useMaxLevelForCost) { + this.xpCost = costs.get(costs.size() - 1).getAsInt(); + } else if (level - 1 < costs.size()) { + this.xpCost = costs.get(level - 1).getAsInt(); + } else { + overMaxLevel = true; + } + } + } + + } + } + } + } + + public OrbDisplay orbDisplay = new OrbDisplay(); + + private int guiLeft; + private int guiTop; + private boolean shouldOverrideFast = false; + private boolean shouldOverrideET = false; + private boolean shouldOverrideGemstones = false; + private boolean shouldOverrideXp = false; + public float pageOpen; + public float pageOpenLast; + public float pageOpenRandom; + public float pageOpenVelocity; + public float bookOpen; + public float bookOpenLast; + + private int currentPage; + private int expectedMaxPage; + + private boolean isScrollingLeft = true; + + private ItemStack enchantingItem = null; + + private int removingEnchantPlayerLevel = -1; + + private final GuiElementTextField searchField = new GuiElementTextField("", GuiElementTextField.SCISSOR_TEXT); + + private final HashMap playerEnchantIds = new HashMap<>(); + + private boolean searchRemovedFromApplicable = false; + private boolean searchRemovedFromRemovable = false; + private final List applicable = new ArrayList<>(); + private final List removable = new ArrayList<>(); + + private final List applicableItem = new ArrayList<>(); + private final List removableItem = new ArrayList<>(); + private final HashMap enchanterEnchLevels = new HashMap<>(); + private final HashMap enchanterItemLevels = new HashMap<>(); + private Enchantment enchanterCurrentEnch = null; + private HexItem enchanterCurrentItem = null; + + public Random random = new Random(); + + private EnchantState currentState = EnchantState.NO_ITEM; + private EnchantState lastState = EnchantState.NO_ITEM; + + private final LerpingInteger leftScroll = new LerpingInteger(0, 150); + private final LerpingInteger rightScroll = new LerpingInteger(0, 150); + + private final LerpingFloat arrowAmount = new LerpingFloat(0, 100); + + private static final int X_SIZE = 364; + private static final int Y_SIZE = 215; + + private int clickedScrollOffset = -1; + private boolean isClickedScrollLeft = true; + + private boolean isChangingEnchLevel = false; + + private long cancelButtonAnimTime = 0; + private long confirmButtonAnimTime = 0; + + public static GuiCustomHex getInstance() { + return INSTANCE; + } + + public boolean shouldOverride(String containerName) { + CalendarOverlay.ableToClickCalendar = true; + if (containerName == null) { + shouldOverrideET = false; + shouldOverrideFast = false; + shouldOverrideGemstones = false; + shouldOverrideXp = false; + searchField.setText(""); + return false; + } + boolean config = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableTableGUI; + final List gemList = new ArrayList<>(Arrays.asList( + "\u2764", + "\u2748", + "\u270e", + "\u2618", + "\u2e15", + "\u2727", + "\u2741", + "\u2742" + )); + shouldOverrideFast = config && + (containerName.length() >= 7 && Objects.equals("The Hex", containerName.substring(0, "The Hex".length()))) && + NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard(); + + shouldOverrideET = config && + (containerName.length() >= 12 && Objects.equals( + "Enchant Item", + containerName.substring(0, "Enchant Item".length()) + )) && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard(); + + shouldOverrideGemstones = config && + (containerName.length() >= 12 && Objects.equals( + "Gemstones ➜", + containerName.substring(0, "Gemstones ➜".length()) + )) && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard(); + if (shouldOverrideGemstones) { + for (String string : gemList) { + if (containerName.contains(string)) { + shouldOverrideGemstones = false; + break; + } + } + } + + shouldOverrideXp = config && + (containerName.length() >= 21 && Objects.equals("Bottles of Enchanting", containerName.substring(0, "Bottles of Enchanting".length()))) && + NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard(); + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + ItemStack hexStack = cc.getLowerChestInventory().getStackInSlot(50); + CalendarOverlay.ableToClickCalendar = !(shouldOverrideET || shouldOverrideFast || shouldOverrideGemstones || shouldOverrideXp); + if (hexStack != null && hexStack.getItem() == Items.experience_bottle) + return (shouldOverrideET || shouldOverrideFast); + if (!shouldOverrideFast && !shouldOverrideET && !shouldOverrideGemstones && !shouldOverrideXp) { + currentState = EnchantState.NO_ITEM; + applicable.clear(); + removable.clear(); + applicableItem.clear(); + removableItem.clear(); + expectedMaxPage = 1; + enchanterCurrentItem = null; + searchField.setText(""); + } + return (shouldOverrideFast || shouldOverrideGemstones || shouldOverrideXp); + } + + private int tickCounter = 0; + + public void tick(String containerName) { + if (containerName.equals("The Hex")) { + currentState = EnchantState.HAS_ITEM_IN_HEX; + tickHex(); + } else if (containerName.contains("Enchant Item")) { + tickEnchants(); + } else if (containerName.contains("Books") || containerName.contains("Modifiers") || containerName.contains( + "Reforges") || containerName.contains("Item Upgrades") || containerName.equals("Bottles of Enchanting")) { + tickBooks(); + } else if (containerName.contains("Gemstones")) { + tickGemstones(); + } else { + tickBooks(); + } + } + + private void tickEnchants() { + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + + //ItemStack hexStack = cc.getLowerChestInventory().getStackInSlot(12); + ItemStack enchantingItemStack = cc.getLowerChestInventory().getStackInSlot(19); + //ItemStack stack = cc.getLowerChestInventory().getStackInSlot(23); + ItemStack hopperStack = cc.getLowerChestInventory().getStackInSlot(51); + + int lastPage = currentPage; + + this.lastState = currentState; + + if (hopperStack != null && hopperStack.getItem() != Item.getItemFromBlock(Blocks.hopper) && + enchantingItem != null) { + currentState = EnchantState.ADDING_ENCHANT; + } else if (enchantingItemStack == null) { + if (currentState == EnchantState.SWITCHING_DONT_UPDATE || currentState == EnchantState.NO_ITEM) { + currentState = EnchantState.NO_ITEM; + } else { + currentState = EnchantState.SWITCHING_DONT_UPDATE; + } + } else { + ItemStack sanityCheckStack = cc.getLowerChestInventory().getStackInSlot(12); + if (sanityCheckStack == null || sanityCheckStack.getItem() == Items.enchanted_book) { + currentState = EnchantState.HAS_ITEM; + enchantingItem = enchantingItemStack; + } else { + currentState = EnchantState.SWITCHING_DONT_UPDATE; + } + } + + if (currentState == EnchantState.HAS_ITEM) { + ItemStack pageUpStack = cc.getLowerChestInventory().getStackInSlot(17); + ItemStack pageDownStack = cc.getLowerChestInventory().getStackInSlot(35); + if (pageUpStack != null && pageDownStack != null) { + currentPage = 0; + boolean upIsGlass = pageUpStack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane); + boolean downIsGlass = pageDownStack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane); + int page = -1; + + expectedMaxPage = 1; + if (!downIsGlass) { + try { + page = Integer.parseInt(Utils.getRawTooltip(pageDownStack).get(1).substring(11)) - 1; + expectedMaxPage = page + 1; + } catch (Exception ignored) { + } + } + if (page == -1 && !upIsGlass) { + try { + page = Integer.parseInt(Utils.getRawTooltip(pageUpStack).get(1).substring(11)) + 1; + expectedMaxPage = page; + } catch (Exception ignored) { + } + } + if (page == -1) { + currentPage = 1; + } else { + currentPage = page; + } + } + } + + orbDisplay.physicsTickOrbs(); + + if (++tickCounter >= 20) { + tickCounter = 0; + } + + boolean updateItems = tickCounter == 0; + + if (currentState == EnchantState.ADDING_ENCHANT) { + if (arrowAmount.getTarget() != 1) { + arrowAmount.setTarget(1); + arrowAmount.resetTimer(); + } + } else { + if (arrowAmount.getTarget() != 0) { + arrowAmount.setTarget(0); + arrowAmount.resetTimer(); + } + } + + // Set allowedSwitchStates = Sets.newHashSet(EnchantState.ADDING_ENCHANT, EnchantState.HAS_ITEM, EnchantState.SWITCHING_DONT_UPDATE); + if (lastState != currentState || lastPage != currentPage) { + // if (!allowedSwitchStates.contains(lastState) || !allowedSwitchStates.contains(currentState)) { + leftScroll.setValue(0); + rightScroll.setValue(0); + // } + updateItems = true; + } + + if (updateItems && currentState != EnchantState.SWITCHING_DONT_UPDATE) { + enchanterEnchLevels.clear(); + + if (enchantingItem != null) { + playerEnchantIds.clear(); + NBTTagCompound tag = enchantingItem.getTagCompound(); + if (tag != null) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + if (ea != null) { + NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); + if (enchantments != null) { + for (String enchId : enchantments.getKeySet()) { + playerEnchantIds.put(enchId, enchantments.getInteger(enchId)); + } + } + } + } + } + + if (currentState == EnchantState.ADDING_ENCHANT) { + removingEnchantPlayerLevel = -1; + boolean updateLevel = enchanterCurrentEnch == null; + boolean hasXpBottle = false; + for (int i = 0; i < 27; i++) { + int slotIndex = 9 + i; + ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex); + ItemStack xpBottle = cc.getLowerChestInventory().getStackInSlot(50); + if (!hasXpBottle && xpBottle != null && + xpBottle.getItem() == Items.experience_bottle) { //Make show when in dungeon screen + String name = "Buy Xp Bottles"; + String id = "XP_BOTTLE"; + Enchantment xpBottleEnch = new Enchantment(50, name, id, + Utils.getRawTooltip(xpBottle), 1, true, false + ); + boolean hasHasXpBottle = false; + for (Enchantment ench : applicable) { + if (ench.enchId.equals("XP_BOTTLE")) { + hasHasXpBottle = true; + break; + } + } + if (!hasHasXpBottle) applicable.add(xpBottleEnch); + hasXpBottle = true; + } + if (book != null && book.getItem() == Items.enchanted_book) { + NBTTagCompound tagBook = book.getTagCompound(); + if (tagBook != null) { + NBTTagCompound ea = tagBook.getCompoundTag("ExtraAttributes"); + if (ea != null) { + NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); + if (enchantments != null) { + String enchId = Utils.cleanColour(book.getDisplayName()).toLowerCase().replace(" ", "_").replace( + "-", + "_" + ); + String name = Utils.cleanColour(book.getDisplayName()); + int enchLevel = -1; + if (name.equalsIgnoreCase("Bane of Arthropods")) { + name = "Bane of Arth."; + } else if (name.equalsIgnoreCase("Projectile Protection")) { + name = "Projectile Prot"; + } else if (name.equalsIgnoreCase("Blast Protection")) { + name = "Blast Prot"; + } else if (name.equalsIgnoreCase("Turbo-Mushrooms")) { + name = "Turbo-Mush"; + } + Matcher levelMatcher = ENCHANT_LEVEL_PATTERN.matcher(enchId); + if (levelMatcher.matches()) { + enchLevel = Utils.parseRomanNumeral(levelMatcher.group(2).toUpperCase()); + enchId = levelMatcher.group(1); + } + Enchantment enchantment = new Enchantment(slotIndex, name, enchId, + Utils.getRawTooltip(book), enchLevel, false, true + ); + int index = 0; + for (String lore : enchantment.displayLore) { + if (lore.contains("N/A") && enchantment.price > 0) { + String price = numberFormat.format(enchantment.price); + enchantment.displayLore.set(index, "\u00a76" + price + ".0 Coins"); + } + index++; + } + enchantment.displayLore.remove(0); + + if (removingEnchantPlayerLevel == -1 && playerEnchantIds.containsKey(enchId)) { + removingEnchantPlayerLevel = playerEnchantIds.get(enchId); + } + + if (removingEnchantPlayerLevel >= 0 && enchantment.level < removingEnchantPlayerLevel) { + continue; + } + + if (enchanterCurrentEnch == null) { + enchanterCurrentEnch = enchantment; + } else if (updateLevel) { + if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level) { + enchanterCurrentEnch = enchantment; + } else if (removingEnchantPlayerLevel >= 0 && enchantment.level < enchanterCurrentEnch.level) { + enchanterCurrentEnch = enchantment; + } + } + + enchanterEnchLevels.put(enchantment.level, enchantment); + } + } + } + } + } + if (enchanterCurrentEnch != null && removingEnchantPlayerLevel >= 0) { + for (String line : enchanterCurrentEnch.displayLore) { + Matcher matcher = XP_COST_PATTERN.matcher(line); + if (matcher.find()) { + enchanterCurrentEnch.xpCost = Integer.parseInt(matcher.group(1)); + } + } + } + } else { + isChangingEnchLevel = false; + enchanterCurrentEnch = null; + + searchRemovedFromRemovable = false; + searchRemovedFromApplicable = false; + applicable.clear(); + removable.clear(); + boolean hasXpBottle = false; + if (currentState == EnchantState.HAS_ITEM) { + for (int i = 0; i < 15; i++) { + int slotIndex = 12 + (i % 5) + (i / 5) * 9; + ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex); + ItemStack xpBottle = cc.getLowerChestInventory().getStackInSlot(50); + if (!hasXpBottle && xpBottle != null && + xpBottle.getItem() == Items.experience_bottle) { //Make show when in dungeon screen + String name = "Buy Xp Bottles"; + String id = "XP_BOTTLE"; + Enchantment xpBottleEnch = new Enchantment(50, name, id, + Utils.getRawTooltip(xpBottle), 1, true, false + ); + applicable.add(xpBottleEnch); + hasXpBottle = true; + } + if (book != null) { + NBTTagCompound tagBook = book.getTagCompound(); + if (tagBook != null) { + NBTTagCompound ea = tagBook.getCompoundTag("ExtraAttributes"); + if (ea != null) { + NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); + if (enchantments != null) { + String enchId = Utils + .cleanColour(book.getDisplayName()) + .toLowerCase() + .replace(" ", "_") + .replace("-", "_"); + if (enchId.equalsIgnoreCase("_")) continue; + if (enchId.equals("prosecute")) { + enchId = "PROSECUTE"; + } + String name = Utils.cleanColour(book.getDisplayName()); + + if (searchField.getText().trim().isEmpty() || + name.toLowerCase().contains(searchField.getText().trim().toLowerCase())) { + if (name.equalsIgnoreCase("Bane of Arthropods")) { + name = "Bane of Arth."; + } else if (name.equalsIgnoreCase("Projectile Protection")) { + name = "Projectile Prot"; + } else if (name.equalsIgnoreCase("Blast Protection")) { + name = "Blast Prot"; + } else if (name.equalsIgnoreCase("Turbo-Mushrooms")) { + name = "Turbo-Mush"; + } + Matcher nameMatcher = ENCHANT_NAME_PATTERN.matcher(name); + if (nameMatcher.matches()) { + name = nameMatcher.group(1); + } + + if (playerEnchantIds.containsKey(enchId)) { + Enchantment enchantment = new Enchantment(slotIndex, name, enchId, + Utils.getRawTooltip(book), playerEnchantIds.get(enchId), false, false + ); + if (!enchantment.overMaxLevel) { + removable.add(enchantment); + } + } else { + Enchantment enchantment = new Enchantment(slotIndex, name, enchId, + Utils.getRawTooltip(book), 1, true, true + ); + applicable.add(enchantment); + } + } else { + if (playerEnchantIds.containsKey(enchId)) { + searchRemovedFromRemovable = true; + } else { + searchRemovedFromApplicable = true; + } + } + + } + } + } + } + } + NEUConfig cfg = NotEnoughUpdates.INSTANCE.config; + int mult = cfg.enchantingSolvers.enchantOrdering == 0 ? 1 : -1; + Comparator comparator = cfg.enchantingSolvers.enchantSorting == 0 ? + Comparator.comparingInt(e -> mult * e.xpCost) : + (c1, c2) -> mult * + c1.enchId.toLowerCase().compareTo(c2.enchId.toLowerCase()); + removable.sort(comparator); + applicable.sort(comparator); + } + } + } + + //Update book model state + if (lastState != currentState) { + do { + this.pageOpenRandom += (float) (this.random.nextInt(4) - this.random.nextInt(4)); + + } while (!(this.pageOpen > this.pageOpenRandom + 1.0F) && !(this.pageOpen < this.pageOpenRandom - 1.0F)); + } + + this.pageOpenLast = this.pageOpen; + this.bookOpenLast = this.bookOpen; + + if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { + this.bookOpen += 0.2F; + } else { + this.bookOpen -= 0.2F; + } + + this.bookOpen = MathHelper.clamp_float(this.bookOpen, 0.0F, 1.0F); + float f1 = (this.pageOpenRandom - this.pageOpen) * 0.4F; + f1 = MathHelper.clamp_float(f1, -0.2F, 0.2F); + this.pageOpenVelocity += (f1 - this.pageOpenVelocity) * 0.9F; + this.pageOpen += this.pageOpenVelocity; + } + + private void tickBooks() { + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + + ItemStack enchantingItemStack = cc.getLowerChestInventory().getStackInSlot(19); + ItemStack anvilStack = cc.getLowerChestInventory().getStackInSlot(28); + + this.lastState = currentState; + + if (anvilStack != null && anvilStack.getItem() == Item.getItemFromBlock(Blocks.anvil) && + currentState != EnchantState.ADDING_BOOK) { + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + enchantingItem = enchantingItemStack; + } else if (currentState == EnchantState.HAS_ITEM_IN_BOOKS && enchantingItem == null && + enchantingItemStack != null) { + enchantingItem = enchantingItemStack; + } else if (anvilStack != null && anvilStack.getItem() == Item.getItemFromBlock(Blocks.enchanting_table) && + currentState != EnchantState.ADDING_BOOK) { + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + enchantingItem = enchantingItemStack; + } + + orbDisplay.physicsTickOrbs(); + + if (++tickCounter >= 20) { + tickCounter = 0; + } + + if (currentState == EnchantState.ADDING_BOOK) { + if (arrowAmount.getTarget() != 1) { + arrowAmount.setTarget(1); + arrowAmount.resetTimer(); + } + } else { + if (arrowAmount.getTarget() != 0) { + arrowAmount.setTarget(0); + arrowAmount.resetTimer(); + } + } + + isChangingEnchLevel = false; + + searchRemovedFromRemovable = false; + searchRemovedFromApplicable = false; + if (applicableItem.size() < 6) leftScroll.setValue(0); + applicableItem.clear(); + removableItem.clear(); + if (currentState == EnchantState.HAS_ITEM_IN_BOOKS || currentState == EnchantState.ADDING_BOOK) { + boolean hasRandomReforge = false; + for (int i = 0; i < 15; i++) { + int slotIndex = 12 + (i % 5) + (i / 5) * 9; + ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex); + ItemStack randomReforge = cc.getLowerChestInventory().getStackInSlot(48); + if (!hasRandomReforge && randomReforge != null && + randomReforge.getItem() == Item.getItemFromBlock(Blocks.anvil)) { //Make show when in dungeon screen + String name = Utils.cleanColour(randomReforge.getDisplayName()); + String id = Utils.cleanColour(randomReforge.getDisplayName()); + if (name.equals("Convert to Dungeon Item")) { + name = "Dungeonize Item"; + id = "CONVERT_TO_DUNGEON"; + } else if (name.equals("Random Basic Reforge")) { + name = "Basic Reforge"; + id = "RANDOM_REFORGE"; + } + HexItem reforgeItem = new HexItem(48, name, id, + Utils.getRawTooltip(randomReforge), true, true + ); + boolean hasAdded = false; + for (String lore : reforgeItem.displayLore) { + if (lore.contains("This item is already a Dungeon")) { + removableItem.add(reforgeItem); + hasAdded = true; + break; + } + } + if (!hasAdded) applicableItem.add(reforgeItem); + hasRandomReforge = true; + } + if (book != null) { + NBTTagCompound tagBook = book.getTagCompound(); + if (tagBook != null) { + NBTTagCompound ea = tagBook.getCompoundTag("ExtraAttributes"); + if (ea != null) { + NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); + if (enchantments != null) { + String itemId = Utils.cleanColour(book.getDisplayName()).toUpperCase().replace(" ", "_").replace( + "-", + "_" + ); + String name = Utils.cleanColour(book.getDisplayName()); + if (itemId.equalsIgnoreCase("_")) continue; + if (itemId.equalsIgnoreCase("Item_Maxed_Out")) continue; + if (searchField.getText().trim().isEmpty() || + name.toLowerCase().contains(searchField.getText().trim().toLowerCase())) { + if (name.equalsIgnoreCase("Hot Potato Book")) { + name = "Hot Potato"; + } else if (name.equalsIgnoreCase("Fuming Potato Book")) { + name = "Fuming Potato"; + } else if (name.equalsIgnoreCase("Recombobulator 3000")) { + name = "Recombobulator"; + } else if (name.contains("Power Scroll")) { + name = name.replace("Power ", ""); + } else if (name.contains("\u272a")) { + name = name.replaceAll("[^✪]*", ""); + } else if (name.equalsIgnoreCase("First Master Star")) { + name = "Master Star \u00a7c➊"; + } else if (name.equalsIgnoreCase("Second Master Star")) { + name = "Master Star \u00a7c➋"; + } else if (name.equalsIgnoreCase("Third Master Star")) { + name = "Master Star \u00a7c➌"; + } else if (name.equalsIgnoreCase("Fourth Master Star")) { + name = "Master Star \u00a7c➍"; + } else if (name.equalsIgnoreCase("Fifth Master Star")) { + name = "Master Star \u00a7c➎"; + } else if (name.equalsIgnoreCase("The Art Of Peace")) { + name = "Art Of Peace"; + } else if (name.equalsIgnoreCase("Mana Disintegrator")) { + name = "M Disintegrator"; + } + /*if (playerEnchantIds.containsKey(itemId)) { + HexItem item = new HexItem(slotIndex, name, itemId, + Utils.getRawTooltip(book), false, false + ); + if (!item.overMaxLevel) { + removableItem.add(item); + } + enchanterItemLevels.put(item.level, item); + } else */ + { + HexItem item = new HexItem(slotIndex, name, itemId, + Utils.getRawTooltip(book), true, true + ); + enchanterItemLevels.put(item.level, item); + if (item.itemType != ItemType.UNKNOWN) { + int potatoCount = 0; + int killCount = 0; + int warCount = 0; + int ffdCount = 0; + int recombCount = 0; + int effLevel = 0; + int starCount = 0; + int singularityCount = 0; + int tunerCount = 0; + int peaceCount = 0; + int manaDisintegratorCount = 0; + boolean shadowWarp = false; + boolean witherShield = false; + boolean implosion = false; + String reforge = ""; + if (enchantingItem != null) { + NBTTagCompound tagItem = enchantingItem.getTagCompound(); + if (tagItem != null) { + NBTTagCompound extra = tagItem.getCompoundTag("ExtraAttributes"); + if (extra != null) { + potatoCount = extra.getInteger("hot_potato_count"); + killCount = extra.getInteger("stats_book"); + warCount = extra.getInteger("art_of_war_count"); + ffdCount = extra.getInteger("farming_for_dummies_count"); + recombCount = extra.getInteger("rarity_upgrades"); + starCount = extra.getInteger("upgrade_level"); + singularityCount = extra.getInteger("wood_singularity_count"); + tunerCount = extra.getInteger("tuned_transmission"); + peaceCount = extra.getInteger("art_of_peace_count"); + manaDisintegratorCount = extra.getInteger("mana_disintegrator_count"); + reforge = extra.getString("modifier"); + NBTTagCompound enchs = extra.getCompoundTag("enchantments"); + NBTTagList scrolls = extra.getTagList("ability_scroll", 8); + if (enchs != null) { + effLevel = enchs.getInteger("efficiency"); + } + if (scrolls != null) { + for (int index = 0; index < scrolls.tagCount(); index++) { + if (scrolls.getStringTagAt(index).equals("IMPLOSION_SCROLL")) { + implosion = true; + } else if (scrolls.getStringTagAt(index).equals("SHADOW_WARP_SCROLL")) { + shadowWarp = true; + } else if (scrolls.getStringTagAt(index).equals("WITHER_SHIELD_SCROLL")) { + witherShield = true; + } + } + } + } + } + } + if (item.itemName.length() > 14) item.itemName = item.itemName.substring(0, 14); + + if (item.itemType == ItemType.HOT_POTATO) { + if (potatoCount < 10) applicableItem.add(item); + else removableItem.add(item); + + } else if (item.itemType == ItemType.FUMING_POTATO) { + if (potatoCount >= 10 && potatoCount < 15) applicableItem.add(item); + else if (potatoCount >= 15) removableItem.add(item); + + } else if (item.itemType == ItemType.BOOK_OF_STATS) { + if (killCount > 0) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.ART