diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 11:53:57 -0500 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 11:53:57 -0500 |
| commit | b09f774d422263ce15b97d6d0804beddf856176d (patch) | |
| tree | e542258481d7496b15679f3c329ef9e087c7d8fc /src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java | |
| parent | 22cb02adbeb24b7ec98f843bcaba99cebe3e4f03 (diff) | |
| download | notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.gz notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.bz2 notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.zip | |
feat: improve formating :)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java | 3426 |
1 files changed, 1839 insertions, 1587 deletions
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 c68f02fc..f5838052 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java @@ -43,566 +43,582 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class GuiCustomEnchant extends Gui { - private static final GuiCustomEnchant INSTANCE = new GuiCustomEnchant(); - 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 enum EnchantState { - NO_ITEM, - ADDING_ENCHANT, - SWITCHING_DONT_UPDATE, - INVALID_ITEM, - HAS_ITEM - } - - private class Enchantment { - public int slotIndex; - public String enchantName; - public String enchId; - public List<String> displayLore; - public int level; - public int xpCost = -1; - public boolean overMaxLevel = false; - public boolean conflicts = false; - - public Enchantment(int slotIndex, String enchantName, String enchId, List<String> displayLore, int level, - boolean useMaxLevelForCost, boolean checkConflicts) { - this.slotIndex = slotIndex; - this.enchantName = enchantName; - this.enchId = enchId; - this.displayLore = displayLore; - this.level = level; - - 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 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<ExperienceOrb> orbs = new ArrayList<>(); - private int orbTargetX = 0; - private int orbTargetY = 0; - - private int guiLeft; - private int guiTop; - private boolean shouldOverrideFast = 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<String, Integer> playerEnchantIds = new HashMap<>(); - - private boolean searchRemovedFromApplicable = false; - private boolean searchRemovedFromRemovable = false; - private final List<Enchantment> applicable = new ArrayList<>(); - private final List<Enchantment> removable = new ArrayList<>(); - - private final HashMap<Integer, Enchantment> enchanterEnchLevels = new HashMap<>(); - private Enchantment enchanterCurrentEnch = 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 GuiCustomEnchant getInstance() { - return INSTANCE; - } - - public boolean shouldOverride(String containerName) { - shouldOverrideFast = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableTableGUI && - Objects.equals("Enchant Item", containerName) && - NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard(); - if (!shouldOverrideFast) { - currentState = EnchantState.NO_ITEM; - applicable.clear(); - removable.clear(); - expectedMaxPage = 1; - } - return shouldOverrideFast; - } - - private int tickCounter = 0; - - public void tick() { - GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); - ContainerChest cc = (ContainerChest) chest.inventorySlots; - - ItemStack stack = cc.getLowerChestInventory().getStackInSlot(23); - ItemStack enchantGuideStack = cc.getLowerChestInventory().getStackInSlot(50); - ItemStack enchantingItemStack = cc.getLowerChestInventory().getStackInSlot(19); - - int lastPage = currentPage; - - this.lastState = currentState; - if (enchantGuideStack != null && enchantGuideStack.getItem() != Items.book && enchantingItem != null) { - currentState = EnchantState.ADDING_ENCHANT; - } else if (stack == null || enchantingItemStack == null) { - if (currentState == EnchantState.SWITCHING_DONT_UPDATE || currentState == EnchantState.NO_ITEM) { - currentState = EnchantState.NO_ITEM; - } else { - currentState = EnchantState.SWITCHING_DONT_UPDATE; - } - } else if (stack.getItem() != Items.dye) { - 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; - } - } else if (stack.getItemDamage() == 1) { - currentState = EnchantState.INVALID_ITEM; - } else { - currentState = EnchantState.NO_ITEM; - } - - 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; - } - } - } - - List<ExperienceOrb> 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); - - 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<EnchantState> 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; - for (int i = 0; i < 27; i++) { - int slotIndex = 9 + i; - ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex); - 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) { - 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); - - 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(); - 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); - 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) { - 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"; - } - - 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); - } - } else { - if (playerEnchantIds.containsKey(enchId)) { - searchRemovedFromRemovable = true; - } else { - searchRemovedFromApplicable = true; - } - } - - } - } - } - } - } - } - NEUConfig cfg = NotEnoughUpdates.INSTANCE.config; - int mult = cfg.enchantingSolvers.enchantOrdering == 0 ? 1 : -1; - Comparator<Enchantment> 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) { - while (true) { - this.pageOpenRandom += (float) (this.random.nextInt(4) - this.random.nextInt(4)); - - if (this.pageOpen > this.pageOpenRandom + 1.0F || this.pageOpen < this.pageOpenRandom - 1.0F) { - break; - } - } - } - - 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 List<String> createTooltip(String title, int selectedOption, String... options) { - String selPrefix = EnumChatFormatting.DARK_AQUA + " \u25b6 "; - String unselPrefix = EnumChatFormatting.GRAY.toString(); - - for (int i = 0; i < options.length; i++) { - if (i == selectedOption) { - options[i] = selPrefix + options[i]; - } else { - options[i] = unselPrefix + options[i]; - } - } - - List<String> list = Lists.newArrayList(options); - list.add(0, ""); - list.add(0, EnumChatFormatting.GREEN + title); - return list; - } - - public void render(float partialTicks) { - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; - - long currentTime = System.currentTimeMillis(); - int playerXpLevel = Minecraft.getMinecraft().thePlayer.experienceLevel; - - GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); - ContainerChest cc = (ContainerChest) chest.inventorySlots; - - leftScroll.tick(); - rightScroll.tick(); - arrowAmount.tick(); - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - - guiLeft = (width - X_SIZE) / 2; - guiTop = (height - Y_SIZE) / 2; - - List<String> tooltipToDisplay = null; - boolean disallowClick = false; - ItemStack stackOnMouse = Minecraft.getMinecraft().thePlayer.inventory.getItemStack(); - int itemHoverX = -1; - int itemHoverY = -1; - boolean hoverLocked = false; - - drawGradientRect(0, 0, width, height, 0xc0101010, 0xd0101010); - - //Base Texture - Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(guiLeft, guiTop, X_SIZE, Y_SIZE, - 0, X_SIZE / 512f, 0, Y_SIZE / 512f, GL11.GL_NEAREST); - - Minecraft.getMinecraft().fontRendererObj.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); - Minecraft.getMinecraft().fontRendererObj.drawString("Removable", guiLeft + 247, guiTop + 7, 0x404040, false); - - //Page Text - if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { - String pageStr = "Page: " + currentPage + "/" + expectedMaxPage; - int pageStrLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(pageStr); - Utils.drawStringCentered(pageStr, Minecraft.getMinecraft().fontRendererObj, - guiLeft + X_SIZE / 2, guiTop + 14, false, 0x404040); - - //Page Arrows - Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - pageStrLen / 2 - 2 - 15, guiTop + 6, 15, 15, - 0, 15 / 512f, 372 / 512f, 387 / 512f, GL11.GL_NEAREST); - Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + pageStrLen / 2 + 2, guiTop + 6, 15, 15, - 15 / 512f, 30 / 512f, 372 / 512f, 387 / 512f, GL11.GL_NEAREST); - } - - //Settings Buttons - Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); - GlStateManager.color(1, 1, 1, 1); - //On Settings Button - Utils.drawTexturedRect(guiLeft + 295, guiTop + 147, 16, 16, - 0, 16 / 512f, 387 / 512f, (387 + 16) / 512f, GL11.GL_NEAREST); - //Incompatible Settings Button + private static final GuiCustomEnchant INSTANCE = new GuiCustomEnchant(); + 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 enum EnchantState { + NO_ITEM, + ADDING_ENCHANT, + SWITCHING_DONT_UPDATE, + INVALID_ITEM, + HAS_ITEM + } + + private class Enchantment { + public int slotIndex; + public String enchantName; + public String enchId; + public List<String> displayLore; + public int level; + public int xpCost = -1; + public boolean overMaxLevel = false; + public boolean conflicts = false; + + public Enchantment( + int slotIndex, String enchantName, String enchId, List<String> displayLore, int level, + boolean useMaxLevelForCost, boolean checkConflicts + ) { + this.slotIndex = slotIndex; + this.enchantName = enchantName; + this.enchId = enchId; + this.displayLore = displayLore; + this.level = level; + + 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 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<ExperienceOrb> orbs = new ArrayList<>(); + private int orbTargetX = 0; + private int orbTargetY = 0; + + private int guiLeft; + private int guiTop; + private boolean shouldOverrideFast = 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<String, Integer> playerEnchantIds = new HashMap<>(); + + private boolean searchRemovedFromApplicable = false; + private boolean searchRemovedFromRemovable = false; + private final List<Enchantment> applicable = new ArrayList<>(); + private final List<Enchantment> removable = new ArrayList<>(); + + private final HashMap<Integer, Enchantment> enchanterEnchLevels = new HashMap<>(); + private Enchantment enchanterCurrentEnch = 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 GuiCustomEnchant getInstance() { + return INSTANCE; + } + + public boolean shouldOverride(String containerName) { + shouldOverrideFast = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableTableGUI && + Objects.equals("Enchant Item", containerName) && + NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard(); + if (!shouldOverrideFast) { + currentState = EnchantState.NO_ITEM; + applicable.clear(); + removable.clear(); + expectedMaxPage = 1; + } + return shouldOverrideFast; + } + + private int tickCounter = 0; + + public void tick() { + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + + ItemStack stack = cc.getLowerChestInventory().getStackInSlot(23); + ItemStack enchantGuideStack = cc.getLowerChestInventory().getStackInSlot(50); + ItemStack enchantingItemStack = cc.getLowerChestInventory().getStackInSlot(19); + + int lastPage = currentPage; + + this.lastState = currentState; + if (enchantGuideStack != null && enchantGuideStack.getItem() != Items.book && enchantingItem != null) { + currentState = EnchantState.ADDING_ENCHANT; + } else if (stack == null || enchantingItemStack == null) { + if (currentState == EnchantState.SWITCHING_DONT_UPDATE || currentState == EnchantState.NO_ITEM) { + currentState = EnchantState.NO_ITEM; + } else { + currentState = EnchantState.SWITCHING_DONT_UPDATE; + } + } else if (stack.getItem() != Items.dye) { + 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; + } + } else if (stack.getItemDamage() == 1) { + currentState = EnchantState.INVALID_ITEM; + } else { + currentState = EnchantState.NO_ITEM; + } + + 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; + } + } + } + + List<ExperienceOrb> 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); + + 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<EnchantState> 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; + for (int i = 0; i < 27; i++) { + int slotIndex = 9 + i; + ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex); + 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) { + for (String enchId |
