diff options
author | nea <romangraef@gmail.com> | 2022-09-28 18:19:11 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-09-28 18:19:11 +0200 |
commit | 52ccb516243af957023d2b5259ffe4d2c51c326c (patch) | |
tree | af93f358dde488de1bd1bc6fda52c2b77225b4bc /src | |
parent | b3e35831f989f996b0f2ea3cd975a8a2ab57a3fd (diff) | |
parent | 29bc3371a62a74d2eab4fe9b6d5c820d52dbbac4 (diff) | |
download | NotEnoughUpdates-52ccb516243af957023d2b5259ffe4d2c51c326c.tar.gz NotEnoughUpdates-52ccb516243af957023d2b5259ffe4d2c51c326c.tar.bz2 NotEnoughUpdates-52ccb516243af957023d2b5259ffe4d2c51c326c.zip |
Merge branch 'master' into feature/glowshrooms
Diffstat (limited to 'src')
62 files changed, 7295 insertions, 1163 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 35385f38..7a2389d4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -29,6 +29,7 @@ import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.miscgui.KatSitterOverlay; +import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; import io.github.moulberry.notenoughupdates.recipes.CraftingOverlay; import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe; import io.github.moulberry.notenoughupdates.recipes.Ingredient; @@ -394,29 +395,94 @@ public class NEUManager { return getUsagesFor(internalname).stream().filter(NeuRecipe::isAvailable).collect(Collectors.toList()); } + private static class DebugMatch { + int index; + String match; + + DebugMatch(int index, String match) { + this.index = index; + this.match = match; + } + } + + + private String searchDebug(String[] searchArray, ArrayList<DebugMatch> debugMatches) { + //splitToSearch, debugMatches and query + final String ANSI_RED = "\u001B[31m"; + final String ANSI_RESET = "\u001B[0m"; + final String ANSI_YELLOW = "\u001B[33m"; + + //create debug message + StringBuilder debugBuilder = new StringBuilder(); + for (int i = 0; i < searchArray.length; i++) { + final int fi = i; + Object[] matches = debugMatches.stream().filter((d) -> d.index == fi).toArray(); + + if (matches.length > 0) { + debugBuilder.append(ANSI_YELLOW + "[").append(((DebugMatch) matches[0]).match).append("]"); + debugBuilder.append(ANSI_RED + "[").append(searchArray[i]).append("]").append(ANSI_RESET).append(" "); + } else { + debugBuilder.append(searchArray[i]).append(" "); + } + } + + //yellow = query match and red = string match + return debugBuilder.toString(); + } + /** * Searches a string for a query. This method is used to mimic the behaviour of the more complex map-based search * function. This method is used for the chest-item-search feature. */ public boolean searchString(String toSearch, String query) { - int lastMatch = -1; + final String ANSI_RESET = "\u001B[0m"; + final String ANSI_YELLOW = "\u001B[33m"; + + int lastStringMatch = -1; + ArrayList<DebugMatch> debugMatches = new ArrayList<>(); toSearch = clean(toSearch).toLowerCase(); query = clean(query).toLowerCase(); - String[] splitToSeach = toSearch.split(" "); - out: - for (String s : query.split(" ")) { - for (int i = 0; i < splitToSeach.length; i++) { - if (!(lastMatch == -1 || lastMatch == i - 1)) continue; - if (splitToSeach[i].startsWith(s)) { - lastMatch = i; - continue out; + String[] splitToSearch = toSearch.split(" "); + String[] queryArray = query.split(" "); + + { + String currentSearch = queryArray[0]; + int queryIndex = 0; + boolean matchedLastQueryItem = false; + + for (int k = 0; k < splitToSearch.length; k++) { + if (queryIndex - 1 != -1 && (queryArray.length - queryIndex) > (splitToSearch.length - k)) continue; + if (splitToSearch[k].startsWith(currentSearch)) { + if (((lastStringMatch != -1 ? lastStringMatch : k-1) == k-1)) { + debugMatches.add(new DebugMatch(k, currentSearch)); + lastStringMatch = k; + if (queryIndex+1 != queryArray.length) { + queryIndex++; + currentSearch = queryArray[queryIndex]; + } else { + matchedLastQueryItem = true; + } + } + } else if (queryIndex != 0) { + queryIndex = 0; + currentSearch = queryArray[queryIndex]; + lastStringMatch = -1; } } - return false; - } - return true; + if (matchedLastQueryItem) { + if (NEUDebugFlag.SEARCH.isSet()) { + NotEnoughUpdates.LOGGER.info("Found match for \"" + ANSI_YELLOW + query + ANSI_RESET + "\":\n\t" + searchDebug(splitToSearch, debugMatches)); + } + } else { + if (NEUDebugFlag.SEARCH.isSet() && lastStringMatch != -1) { + NotEnoughUpdates.LOGGER.info("Found partial match for \"" + ANSI_YELLOW + query + ANSI_RESET + "\":\n\t" + searchDebug(splitToSearch, debugMatches)); + } + } + + return matchedLastQueryItem; + } } /** @@ -1201,7 +1267,7 @@ public class NEUManager { } } - public HashMap<String, String> getLoreReplacements(String petname, String tier, int level) { + public HashMap<String, String> getPetLoreReplacements(String petname, String tier, int level) { JsonObject petnums = null; if (petname != null && tier != null) { petnums = Constants.PETNUMS; @@ -1314,7 +1380,7 @@ public class NEUManager { float statMax = entry.getValue().getAsFloat(); float statMin = min.get("statNums").getAsJsonObject().get(entry.getKey()).getAsFloat(); float val = statMin * minMix + statMax * maxMix; - String statStr = (statMin > 0 ? "+" : "") + (int) Math.floor(val); + String statStr = (statMin > 0 ? "+" : "") + removeUnusedDecimal(Math.floor(val * 10) / 10); replacements.put(entry.getKey(), statStr); } } @@ -1326,7 +1392,7 @@ public class NEUManager { return replacements; } - public HashMap<String, String> getLoreReplacements(NBTTagCompound tag, int level) { + public HashMap<String, String> getPetLoreReplacements(NBTTagCompound tag, int level) { String petname = null; String tier = null; if (tag != null && tag.hasKey("ExtraAttributes")) { @@ -1360,7 +1426,7 @@ public class NEUManager { } } } - return getLoreReplacements(petname, tier, level); + return getPetLoreReplacements(petname, tier, level); } public NBTTagList processLore(JsonArray lore, HashMap<String, String> replacements) { @@ -1391,6 +1457,7 @@ public class NEUManager { } public ItemStack jsonToStack(JsonObject json, boolean useCache, boolean useReplacements, boolean copyStack) { + if (useReplacements) useCache = false; if (json == null) return new ItemStack(Items.painting, 1, 10); String internalname = json.get("internalname").getAsString(); @@ -1430,7 +1497,7 @@ public class NEUManager { HashMap<String, String> replacements = new HashMap<>(); if (useReplacements) { - replacements = getLoreReplacements(stack.getTagCompound(), -1); + replacements = getPetLoreReplacements(stack.getTagCompound(), -1); String displayName = json.get("displayname").getAsString(); for (Map.Entry<String, String> entry : replacements.entrySet()) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 18be69e6..dbff2be2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -23,7 +23,6 @@ import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; @@ -37,7 +36,6 @@ import io.github.moulberry.notenoughupdates.mbgui.MBGuiElement; import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupAligned; import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupFloating; import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; -import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; import io.github.moulberry.notenoughupdates.miscgui.NeuSearchCalculator; @@ -46,17 +44,13 @@ import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.GuiTextures; import io.github.moulberry.notenoughupdates.util.LerpingFloat; import io.github.moulberry.notenoughupdates.util.NotificationHandler; -import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; @@ -72,8 +66,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Items; -import net.minecraft.inventory.ContainerChest; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -101,7 +93,6 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.UUID; @@ -120,48 +111,6 @@ public class NEUOverlay extends Gui { private static final ResourceLocation SEARCH_BAR = new ResourceLocation("notenoughupdates:search_bar.png"); private static final ResourceLocation SEARCH_BAR_GOLD = new ResourceLocation("notenoughupdates:search_bar_gold.png"); - private static final ResourceLocation ARMOR_DISPLAY = new ResourceLocation( - "notenoughupdates:armordisplay/armordisplay.png"); - private static final ResourceLocation ARMOR_DISPLAY_GREY = new ResourceLocation( - "notenoughupdates:armordisplay/armordisplay_grey.png"); - private static final ResourceLocation ARMOR_DISPLAY_DARK = new ResourceLocation( - "notenoughupdates:armordisplay/armordisplay_phq_dark.png"); - private static final ResourceLocation ARMOR_DISPLAY_FSR = new ResourceLocation( - "notenoughupdates:armordisplay/armordisplay_fsr.png"); - private static final ResourceLocation ARMOR_DISPLAY_TRANSPARENT = new ResourceLocation( - "notenoughupdates:armordisplay/armordisplay_transparent.png"); - private static final ResourceLocation ARMOR_DISPLAY_TRANSPARENT_PET = new ResourceLocation( - "notenoughupdates:armordisplay/armordisplay_transparent_pet.png"); - - private static final ResourceLocation QUESTION_MARK = new ResourceLocation("notenoughupdates:pv_unknown.png"); - - private static final ResourceLocation PET_DISPLAY = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplaysolo.png"); - private static final ResourceLocation PET_DISPLAY_GREY = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplaysolo_dark.png"); - private static final ResourceLocation PET_DISPLAY_DARK = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplaysolo_phqdark.png"); - private static final ResourceLocation PET_DISPLAY_FSR = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplaysolo_fsr.png"); - private static final ResourceLocation PET_DISPLAY_TRANSPARENT = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplaysolo_transparent.png"); - - private static final ResourceLocation PET_ARMOR_DISPLAY = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplayarmor.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_GREY = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplayarmor_dark.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_DARK = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplayarmor_phqdark.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_FSR = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplayarmor_fsr.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_TRANSPARENT = new ResourceLocation( - "notenoughupdates:petdisplay/petdisplayarmor_transparent.png"); - - private static boolean renderingArmorHud; - private static boolean renderingPetHud; - public static boolean shouldUseCachedPet; - public static long cachedPetTimer; - private final NEUManager manager; private final String mobRegex = ".*?((_MONSTER)|(_NPC)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$"; @@ -217,6 +166,7 @@ public class NEUOverlay extends Gui { private List<JsonObject> selectedItemGroup = null; private boolean itemPaneOpen = false; + private long itemPaneShouldOpen = -1; private int page = 0; @@ -292,12 +242,14 @@ public class NEUOverlay extends Gui { } if (Mouse.getEventButtonState()) { setSearchBarFocus(true); + if (Mouse.getEventButton() == 1) { //Right mouse button down textField.setText(""); updateSearch(); } else { if (System.currentTimeMillis() - millisLastLeftClick < 300) { searchMode = !searchMode; + itemPaneShouldOpen = -1; lastSearchMode = System.currentTimeMillis(); if (searchMode && NotEnoughUpdates.INSTANCE.config.hidden.firstTimeSearchFocus) { NotificationHandler.displayNotification(Lists.newArrayList( @@ -801,7 +753,9 @@ public class NEUOverlay extends Gui { if (slot != null) { ItemStack hover = slot.getStack(); if (hover != null) { - textField.setText("id:" + manager.getInternalNameForItem(hover)); + if (manager.getInternalNameForItem(hover) != null) { + textField.setText("id:" + manager.getInternalNameForItem(hover)); + } itemPaneOpen = true; updateSearch(); } @@ -1836,85 +1790,6 @@ public class NEUOverlay extends Gui { int guiScaleLast = 0; private boolean showVanillaLast = false; - - private boolean wardrobeOpen = false; - - private boolean isInNamedGui(String guiName) { - GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; - if (guiScreen instanceof GuiChest) { - GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; - ContainerChest container = (ContainerChest) chest.inventorySlots; - IInventory lower = container.getLowerChestInventory(); - String containerName = lower.getDisplayName().getUnformattedText(); - wardrobeOpen = containerName.contains(guiName); - } - if (guiScreen instanceof GuiInventory) { - wardrobeOpen = false; - } - return wardrobeOpen; - } - - private ItemStack getChestSlotsAsItemStack(int slot) { - GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; - if (guiScreen instanceof GuiChest) { - GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; - return chest.inventorySlots.getSlot(slot).getStack(); - } else { - return null; - } - } - - public ItemStack slot1 = null; - public ItemStack slot2 = null; - public ItemStack slot3 = null; - public ItemStack slot4 = null; - public ItemStack petSlot = null; - private String lastProfile; - - private ItemStack getWardrobeSlot(int armourSlot) { - if (SBInfo.getInstance().currentProfile == null) { - return null; - } - - if (!Objects.equals(SBInfo.getInstance().currentProfile, lastProfile)) { - lastProfile = SBInfo.getInstance().currentProfile; - slot1 = null; - slot2 = null; - slot3 = null; - slot4 = null; - petSlot = null; - } - - if (isInNamedGui("Your Equipment")) { - ItemStack itemStack = getChestSlotsAsItemStack(armourSlot); - if (itemStack != null) { - JsonObject itemToSave = NotEnoughUpdates.INSTANCE.manager.getJsonForItem(itemStack); - if (!itemToSave.has("internalname")) { - //would crash without internalName when trying to construct the ItemStack again - itemToSave.add("internalname", new JsonPrimitive("_")); - } - NotEnoughUpdates.INSTANCE.config.getProfileSpecific().savedEquipment.put(armourSlot, itemToSave); - return itemStack; - } - } else { - if (NotEnoughUpdates.INSTANCE.config.getProfileSpecific().savedEquipment.containsKey(armourSlot)) { - //don't use cache since the internalName is identical in most cases - return NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.config.getProfileSpecific().savedEquipment - .get(armourSlot) - .getAsJsonObject(), false); - } - } - return null; - } - - public static boolean isRenderingArmorHud() { - return renderingArmorHud; - } - - public static boolean isRenderingPetHud() { - return renderingPetHud; - } - /** * Renders the search bar, quick commands, item selection (right), item info (left) and armor hud gui elements. */ @@ -1922,8 +1797,6 @@ public class NEUOverlay extends Gui { if (disabled) { return; } - renderingArmorHud = false; - renderingPetHud = false; GlStateManager.enableDepth(); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; @@ -1984,6 +1857,13 @@ public class NEUOverlay extends Gui { (int) (fgFavourite2.getBlue() * 0.8f), fgFavourite2.getAlpha() ); + if (!NotEnoughUpdates.INSTANCE.config.itemlist.openWhenSearching && searchMode) { + itemPaneOpen = false; + } + if (itemPaneShouldOpen != -1 && System.currentTimeMillis() > itemPaneShouldOpen) { + itemPaneOpen = true; + itemPaneShouldOpen = -1; + } if (itemPaneOpen) { if (itemPaneTabOffset.getValue() == 0) { if (itemPaneOffsetFactor.getTarget() != 2 / 3f) { @@ -2321,7 +2201,6 @@ public class NEUOverlay extends Gui { GlStateManager.enableAlpha(); GlStateManager.alphaFunc(516, 0.1F); GlStateManager.disableLighting(); - renderInfoHuds(); Utils.pushGuiScale(-1); if (System.currentTimeMillis() - lastSearchMode > 120000 && @@ -2331,303 +2210,6 @@ public class NEUOverlay extends Gui { } } - void renderInfoHuds() { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - - Utils.resetGuiScale(); - Utils.pushGuiScale(Minecraft.getMinecraft().gameSettings.guiScale); - - int width = Utils.peekGuiScale().getScaledWidth(); - int height = Utils.peekGuiScale().getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; - - if (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud && - NotEnoughUpdates.INSTANCE.config.misc.hidePotionEffect - && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - if (getWardrobeSlot(10) != null) { - slot1 = getWardrobeSlot(10); - slot2 = getWardrobeSlot(19); - slot3 = getWardrobeSlot(28); - slot4 = getWardrobeSlot(37); - } - if (guiScreen instanceof GuiInventory) { - renderingArmorHud = true; - - List<String> tooltipToDisplay = null; - if (NotEnoughUpdates.INSTANCE.config.customArmour.colourStyle == 0) { - Minecraft.getMinecraft().getTextureManager().bindTexture(ARMOR_DISPLAY); - } - if (NotEnoughUpdates.INSTANCE.config.customArmour.colourStyle == 1) { - Minecraft.getMinecraft().getTextureManager().bindTexture(ARMOR_DISPLAY_GREY); - } - if (NotEnoughUpdates.INSTANCE.config.customArmour.colourStyle == 2) { - Minecraft.getMinecraft().getTextureManager().bindTexture(ARMOR_DISPLAY_DARK); - } - if (NotEnoughUpdates.INSTANCE.config.customArmour.colourStyle == 3) { - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 3 && - NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay && petSlot != null) { - Minecraft.getMinecraft().getTextureManager().bindTexture(ARMOR_DISPLAY_TRANSPARENT_PET); - } else { - Minecraft.getMinecraft().getTextureManager().bindTexture(ARMOR_DISPLAY_TRANSPARENT); - } - } - if (NotEnoughUpdates.INSTANCE.config.customArmour.colourStyle == 4) { - Minecraft.getMinecraft().getTextureManager().bindTexture(ARMOR_DISPLAY_FSR); - } - - GlStateManager.color(1, 1, 1, 1); - GL11.glTranslatef(0, 0, 401); - float yNumber = (float) (height - 167) / 2f; - Utils.drawTexturedRect((float) ((width - 224.1) / 2f), yNumber, 31, 86, GL11.GL_NEAREST); - GlStateManager.bindTexture(0); - - Utils.drawItemStack(slot1, (int) ((width - 208) / 2f), (int) ((height + 60) / 2f - 105), true); - Utils.drawItemStack(slot2, (int) ((width - 208) / 2f), (int) ((height + 60) / 2f - 105) + 18, true); - Utils.drawItemStack(slot3, (int) ((width - 208) / 2f), (int) ((height + 60) / 2f - 105) + 36, true); - Utils.drawItemStack(slot4, (int) ((width - 208) / 2f), (int) ((height + 60) / 2f - 105) + 54, true); - if (slot1 == null) { - Minecraft.getMinecraft().getTextureManager().bindTexture(QUESTION_MARK); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(((width - 208) / 2f), ((height + 60) / 2f - 105), 16, 16, GL11.GL_NEAREST); - GlStateManager.bindTexture(0); - - tooltipToDisplay = Lists.newArrayList( - EnumChatFormatting.RED + "Warning", - EnumChatFormatting.GREEN + "You need to open /equipment", - EnumChatFormatting.GREEN + "To cache your armour" - ); - if (mouseX >= ((width - 208) / 2f) && mouseX < ((width - 208) / 2f) + 16) { - if (mouseY >= ((height + 60) / 2f - 105) && mouseY <= ((height + 60) / 2f - 105) + 70 && - NotEnoughUpdates.INSTANCE.config.customArmour.sendWardrobeCommand) { - if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { - if (Mouse.getEventButtonState()) { - if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/equipment") == - 0) { - NotEnoughUpdates.INSTANCE.sendChatMessage("/equipment"); - } - } - } - } - if (mouseY >= ((height + 60) / 2f - 105) && mouseY <= ((height + 60) / 2f - 105) + 16) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); - } - } - GL11.glTranslatef(0, 0, -401); - } - if (slot1 != null && slot2 != null && slot3 != null && slot4 != null) { - if (mouseX >= ((width - 208) / 2f) && mouseX < ((width - 208) / 2f) + 16) { - if (mouseY >= ((height + 60) / 2f - 105) && mouseY <= ((height + 60) / 2f - 105) + 70 && - NotEnoughUpdates.INSTANCE.config.customArmour.sendWardrobeCommand) { - if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { - if (Mouse.getEventButtonState()) { - if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/equipment") == - 0) { - NotEnoughUpdates.INSTANCE.sendChatMessage("/equipment"); - } - } - } - } - - if (mouseY >= ((height + 60) / 2f - 105) && mouseY <= ((height + 60) / 2f - 105) + 16) { - tooltipToDisplay = slot1.getTooltip(Minecraft.getMinecraft().thePlayer, false); - if (shouldShowEquipmentTooltip(tooltipToDisplay)) { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX - calculateTooltipXOffset(tooltipToDisplay, fr), - mouseY, - width, - height, - -1, - fr - ); - } - } - if (mouseY >= ((height + 60) / 2f - 105) + 18 && mouseY <= ((height + 60) / 2f - 105) + 34) { - tooltipToDisplay = slot2.getTooltip(Minecraft.getMinecraft().thePlayer, false); - if (shouldShowEquipmentTooltip(tooltipToDisplay)) { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX - calculateTooltipXOffset(tooltipToDisplay, fr), - mouseY, - width, - height, - -1, - fr - ); - } - } - if (mouseY >= ((height + 60) / 2f - 105) + 36 && mouseY <= ((height + 60) / 2f - 105) + 52) { - tooltipToDisplay = slot3.getTooltip(Minecraft.getMinecraft().thePlayer, false); - if (shouldShowEquipmentTooltip(tooltipToDisplay)) { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX - calculateTooltipXOffset(tooltipToDisplay, fr), - mouseY, - width, - height, - -1, - fr - ); - } - } - if (mouseY >= ((height + 60) / 2f - 105) + 54 && mouseY <= ((height + 60) / 2f - 105) + 70) { - tooltipToDisplay = slot4.getTooltip(Minecraft.getMinecraft().thePlayer, false); - if (shouldShowEquipmentTooltip(tooltipToDisplay)) { - Utils.drawHoveringText( - tooltipToDisplay, - mouseX - calculateTooltipXOffset(tooltipToDisplay, fr), - mouseY, - width, - height, - -1, - fr - ); - } - } - } - GL11.glTranslatef(0, 0, -401); - } - } - } - if (PetInfoOverlay.getCurrentPet() != null) { - if (NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay - && (NotEnoughUpdates.INSTANCE.manager - .jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get(PetInfoOverlay.getCurrentPet().petType + ";" + PetInfoOverlay.getCurrentPet().rarity.petId)) - .hasDisplayName() - || NotEnoughUpdates.INSTANCE.manager - .jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get(PetInfoOverlay.getCurrentPet().petType + ";" + (PetInfoOverlay.getCurrentPet().rarity.petId - 1))) - .hasDisplayName()) - && NotEnoughUpdates.INSTANCE.config.misc.hidePotionEffect && - NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - if (!NotEnoughUpdates.INSTANCE.manager - .jsonToStack( - NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get(PetInfoOverlay.getCurrentPet().petType + ";" + PetInfoOverlay.getCurrentPet().rarity.petId)) - .hasDisplayName()) { - petSlot = NotEnoughUpdates.INSTANCE.manager.jsonToStack( - NotEnoughUpdates.INSTANCE.manager.getItemInformation().get( - PetInfoOverlay.getCurrentPet().petType + ";" + (PetInfoOverlay.getCurrentPet().rarity.petId - 1))); - } else { - petSlot = NotEnoughUpdates.INSTANCE.manager.jsonToStack( - NotEnoughUpdates.INSTANCE.manager.getItemInformation().get( - PetInfoOverlay.getCurrentPet().petType + ";" + PetInfoOverlay.getCurrentPet().rarity.petId)); - } - if (petSlot == null) { - return; - } - petSlot.getTagCompound().setBoolean( - "NEUHIDEPETTOOLTIP", - NotEnoughUpdates.INSTANCE.config.petOverlay.hidePetTooltip - ); - ItemStack petInfo = petSlot; - - if (guiScreen instanceof GuiInventory) { - GL11.glTranslatef(0, 0, 401); - if (!NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud) { - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 0) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_DISPLAY); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 1) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_DISPLAY_GREY); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 2) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_DISPLAY_DARK); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 3) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_DISPLAY_TRANSPARENT); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 4) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_DISPLAY_FSR); - } - } else { - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 0) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_ARMOR_DISPLAY); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 1) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_ARMOR_DISPLAY_GREY); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 2) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_ARMOR_DISPLAY_DARK); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 3) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_ARMOR_DISPLAY_TRANSPARENT); - } - if (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 4) { - Minecraft.getMinecraft().getTextureManager().bindTexture(PET_ARMOR_DISPLAY_FSR); - } - } - - GlStateManager.color(1, 1, 1, 1); - float yNumber = (float) (height - 23) / 2f; - Utils.drawTexturedRect((float) ((width - 224.1) / 2f), yNumber, 31, 32, GL11.GL_NEAREST); - GlStateManager.bindTexture(0); - - Utils.drawItemStack(petInfo, (int) ((width - 208) / 2f), (int) ((height + 60) / 2f - 105) + 72, true); - renderingPetHud = true; - - List<String> tooltipToDisplay = null; - if (petInfo != null) { - if (mouseX >= ((width - 208) / 2f) && mouseX < ((width - 208) / 2f) + 16) { - if (mouseY >= ((height + 60) / 2f - 105) + 72 && mouseY <= ((height + 60) / 2f - 105) + 88 && - NotEnoughUpdates.INSTANCE.config.petOverlay.sendPetsCommand) { - if (Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { - if (Mouse.getEventButtonState()) { - if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/pets") == - 0) { - NotEnoughUpdates.INSTANCE.sendChatMessage("/pets"); - } - } - } - tooltipToDisplay = petInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false); - Utils.drawHoveringText( - tooltipToDisplay, - mouseX - calculateTooltipXOffset(tooltipToDisplay, fr), - mouseY, - width, - height, - -1, - fr - ); - GL11.glTranslatef(0, 0, -80); - } - } - - } - } - } - } - } - - /** - * Calculates the width of the longest String in the tooltip, which can be used to offset the entire tooltip to the left more precisely - * - * @param tooltipToDisplay tooltip - * @param fr FontRenderer object - * @return offset to apply - */ - private int calculateTooltipXOffset(List<String> tooltipToDisplay, FontRenderer fr) { - int offset = 0; - if (tooltipToDisplay != null) { - for (String line : tooltipToDisplay) { - int lineWidth = fr.getStringWidth(line); - if (lineWidth > offset) { - offset = lineWidth; - } - } - } - return offset + 20; - } - - private boolean shouldShowEquipmentTooltip(List<String> toolTip) { - return !toolTip.get(0).equals("§o§7Empty Equipment Slot§r"); - } /** * Used in SettingsInfoPane to redraw the items when a setting changes. diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 6cb26350..9dc00f93 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -67,6 +67,7 @@ import io.github.moulberry.notenoughupdates.miscgui.SignCalculator; import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft; import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.overlays.FuelBar; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; @@ -90,6 +91,7 @@ import net.minecraft.world.biome.BiomeGenHell; import net.minecraft.world.biome.BiomeGenJungle; import net.minecraft.world.biome.BiomeGenMesa; import net.minecraft.world.biome.BiomeGenSnow; +import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -98,6 +100,8 @@ import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.awt.*; import java.io.BufferedReader; @@ -118,6 +122,8 @@ public class NotEnoughUpdates { public static final int VERSION_ID = 20100; public static final int PRE_VERSION_ID = 0; public static final int HOTFIX_VERSION_ID = 0; + + public static final Logger LOGGER = LogManager.getLogger("NotEnoughUpdates"); /** * Registers the biomes for the crystal hollows here so optifine knows they exists */ @@ -244,7 +250,6 @@ public class NotEnoughUpdates { config.apiKey = null; } - //add the trophy fishing tab to the config if (config.profileViewer.pageLayout.size() == 8) { config.profileViewer.pageLayout.add(8); @@ -283,6 +288,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(FishingHelper.getInstance()); MinecraftForge.EVENT_BUS.register(CrystalWishingCompassSolver.getInstance()); MinecraftForge.EVENT_BUS.register(new DwarvenMinesTextures()); + MinecraftForge.EVENT_BUS.register(EquipmentOverlay.INSTANCE); MinecraftForge.EVENT_BUS.register(CustomBiomes.INSTANCE); MinecraftForge.EVENT_BUS.register(new ChatListener(this)); MinecraftForge.EVENT_BUS.register(new ItemTooltipListener(this)); @@ -382,6 +388,12 @@ public class NotEnoughUpdates { } } + public void trySendCommand(String message) { + if (ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, message) == 0) { + sendChatMessage(message); + } + } + public void displayLinks(JsonObject update, int totalWidth) { String discord_link = update.get("discord_link").getAsString(); String youtube_link = update.get("youtube_link").getAsString(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java index fcb2aaf9..62981a30 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.dev.DevTestCommand; import io.github.moulberry.notenoughupdates.commands.dev.DiagCommand; import io.github.moulberry.notenoughupdates.commands.dev.DungeonWinTestCommand; +import io.github.moulberry.notenoughupdates.commands.dev.EnableStorageCommand; import io.github.moulberry.notenoughupdates.commands.dev.NullzeeSphereCommand; import io.github.moulberry.notenoughupdates.commands.dev.PackDevCommand; import io.github.moulberry.notenoughupdates.commands.dev.ReloadRepoCommand; @@ -74,6 +75,7 @@ public class Commands { ClientCommandHandler.instance.registerCommand(new DiagCommand()); ClientCommandHandler.instance.registerCommand(new ReloadRepoCommand()); ClientCommandHandler.instance.registerCommand(new ResetRepoCommand()); + ClientCommandHandler.instance.registerCommand(new EnableStorageCommand()); // Profile Commands ClientCommandHandler.instance.registerCommand(new PeekCommand()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index fdf59bb0..972557c8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -57,7 +57,9 @@ public class DevTestCommand extends ClientCommandBase { "dediamondpro", "lulonaut", "craftyoldminer", - "eisengolem" + "eisengolem", + "whalker", + "ascynx" ); private static final String[] DEV_FAIL_STRINGS = { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java index 326c00b4..fb546efb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java @@ -41,7 +41,8 @@ public class DiagCommand extends ClientCommandBase { " center=<off | on> Disable / enable using center\n" + "/neudiag wishing Wishing Compass Solver diagnostics\n" + "/neudiag debug\n" + - " <no sub-command> Show current flags\n" + + " <no sub-command> Show all enabled flags\n" + + " <list> Show all flags\n"+ " <enable | disable> <flag> Enable/disable flag\n"; private void showUsage(ICommandSender sender) { @@ -86,6 +87,10 @@ public class DiagCommand extends ClientCommandBase { boolean enablingFlag = true; String action = args[1]; switch (action) { + case "list": + sender.addChatMessage(new ChatComponentText( + EnumChatFormatting.YELLOW + "Here are all flags:\n" + NEUDebugFlag.getFlagList())); + return; case "disable": enablingFlag = false; // falls through @@ -93,7 +98,7 @@ public class DiagCommand extends ClientCommandBase { if (args.length != 3) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You must specify a flag:\n" + - NEUDebugFlag.FLAG_LIST)); + NEUDebugFlag.getFlagList())); return; } @@ -108,7 +113,7 @@ public class DiagCommand extends ClientCommandBase { } catch (IllegalArgumentException e) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + flagName + " is invalid. Valid flags are:\n" + - NEUDebugFlag.FLAG_LIST)); + NEUDebugFlag.getFlagList())); return; } break; @@ -118,8 +123,8 @@ public class DiagCommand extends ClientCommandBase { } } - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Effective debug flags: " + - NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.toString())); + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Effective debug flags: \n" + + NEUDebugFlag.getEnabledFlags())); break; default: showUsage(sender); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinSkyclientCosmetics.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/EnableStorageCommand.java index 32c9f418..3415b030 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinSkyclientCosmetics.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/EnableStorageCommand.java @@ -17,23 +17,23 @@ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. */ -package io.github.moulberry.notenoughupdates.mixins; +package io.github.moulberry.notenoughupdates.commands.dev; -import net.minecraftforge.event.world.WorldEvent; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; -@Pseudo -@Mixin(targets = "co.skyclient.scc.SkyclientCosmetics") -public class MixinSkyclientCosmetics { +public class EnableStorageCommand extends ClientCommandBase { - @Dynamic - @Inject(method = "onWorldLoad", at = @At("HEAD"), cancellable = true, remap = false) - public void onWorldLoad(WorldEvent.Load event, CallbackInfo ci) { - ci.cancel(); + public EnableStorageCommand() { + super("neuenablestorage"); } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + NotEnoughUpdates.INSTANCE.config.storageGUI.enableStorageGUI3 = true; + NotEnoughUpdates.INSTANCE.saveConfig(); + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java index 421f7c10..75e779fc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java @@ -122,7 +122,7 @@ public class PeekCommand extends ClientCommandBase { float totalSkillLVL = 0; float totalSkillCount = 0; - List<String> skills = Arrays.asList("taming", "mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy"); + List<String> skills = Arrays.asList("taming", "mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy", "carpentry"); for (String skillName : skills) { totalSkillLVL += skyblockInfo.get(skillName).level; totalSkillCount++; @@ -133,6 +133,7 @@ public class PeekCommand extends ClientCommandBase { float spider = skyblockInfo.get("spider").level; float wolf = skyblockInfo.get("wolf").level; float enderman = skyblockInfo.get("enderman").level; + float blaze = skyblockInfo.get("blaze").level; float avgSkillLVL = totalSkillLVL / totalSkillCount; @@ -143,6 +144,7 @@ public class PeekCommand extends ClientCommandBase { spider = 1; wolf = 2; enderman = 0; + blaze = 0; } EnumChatFormatting combatPrefix = combat > 20 @@ -161,6 +163,11 @@ public class PeekCommand extends ClientCommandBase { ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; + EnumChatFormatting blazePrefix = blaze > 3 + ? (blaze > 6 + ? EnumChatFormatting.GREEN + : EnumChatFormatting.YELLOW) + : EnumChatFormatting.RED; EnumChatFormatting avgPrefix = avgSkillLVL > 20 ? (avgSkillLVL > 35 ? EnumChatFormatting.GREEN @@ -171,6 +178,7 @@ public class PeekCommand extends ClientCommandBase { overallScore += spider * spider / 81f; overallScore += wolf * wolf / 81f; overallScore += enderman * enderman / 81f; + overallScore += blaze * blaze / 81f; overallScore += avgSkillLVL / 20f; int cata = (int) skyblockInfo.get("catacombs").level; @@ -187,8 +195,9 @@ public class PeekCommand extends ClientCommandBase { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( g + "Slayer: " + zombiePrefix + (int) Math.floor(zombie) + g + "-" + spiderPrefix + (int) Math.floor(spider) + g + "-" + - wolfPrefix + (int) Math.floor(wolf) + "-" + - endermanPrefix + (int) Math.floor(enderman))); + wolfPrefix + (int) Math.floor(wolf) + g+ "-" + + endermanPrefix + (int) Math.floor(enderman) + g + "-" + + blazePrefix + (int) Math.floor(blaze))); } if (stats == null) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java index d4a728be..a4c5a60a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java @@ -726,7 +726,7 @@ public class DungeonMap { } GlStateManager.color(1, 1, 1, 1); if ((!NotEnoughUpdates.INSTANCE.config.dungeons.showOwnHeadAsMarker || - playerMarkerMapPositions.size() <= 1 || minU != 1 / 4f) && + playerMarkerMapPositions.size() < 1 || minU != 1 / 4f) && NotEnoughUpdates.INSTANCE.config.dungeonMap.dmPlayerHeads >= 1 && playerSkinMap.containsKey(entry.getKey())) { Minecraft.getMinecraft().getTextureManager().bindTexture(playerSkinMap.get(entry.getKey())); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/GuiInventoryBackgroundDrawnEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/GuiInventoryBackgroundDrawnEvent.java new file mode 100644 index 00000000..0b8bf126 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/GuiInventoryBackgroundDrawnEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.events; + +import net.minecraft.client.gui.inventory.GuiContainer; + +public class GuiInventoryBackgroundDrawnEvent extends NEUEvent { + private final GuiContainer container; + private final float partialTicks; + + public GuiInventoryBackgroundDrawnEvent(GuiContainer container, float partialTicks) { + this.container = container; + this.partialTicks = partialTicks; + } + + public GuiContainer getContainer() { + return container; + } + + public float getPartialTicks() { + return partialTicks; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java index a449919e..0b1963d6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java @@ -81,6 +81,7 @@ public class DevInfoPane extends TextInfoPane { for (String internalname : manager.auctionManager.getItemAuctionInfoKeySet()) { if (internalname.matches("^.*-[0-9]{1,3}$")) continue; if (!manager.getItemInformation().containsKey(internalname)) { + if (internalname.equals("RUNE") || internalname.contains("PARTY_HAT_CRAB")) continue; text += internalname + "\n"; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index b59eaf17..de37b976 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -238,7 +238,7 @@ public class ChatListener { } missingRecipe.set(true); } - if (unformatted.startsWith("Sending to server") && neu.isOnSkyblock() && + if (unformatted.startsWith("Sending to server") && NotEnoughUpdates.INSTANCE.config.misc.streamerMode && e.message instanceof ChatComponentText) { String m = e.message.getFormattedText(); String m2 = StreamerMode.filterChat(e.message.getFormattedText()); 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..d89e886f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipListener.java @@ -55,7 +55,6 @@ import java.awt.datatransfer.StringSelection; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -67,7 +66,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class ItemTooltipListener { - private static final String petToolTipRegex = + public static final String petToolTipRegex = "((Farming)|(Combat)|(Fishing)|(Mining)|(Foraging)|(Enchanting)|(Alchemy)) ((Mount)|(Pet)|(Morph)).*"; private final NotEnoughUpdates neu; private final Pattern xpLevelPattern = Pattern.compile("(.*) (\\xA7e(.*)\\xA76/\\xA7e(.*))"); @@ -382,6 +381,7 @@ public class ItemTooltipListener { } } if (hasEnchantments || hasAttributes) { + ArrayList<String> addedEnchants = new ArrayList<>(); for (String op : NotEnoughUpdates.INSTANCE.config.hidden.enchantColours) { List<String> colourOps = GuiEnchantColour.splitter.splitToList(op); String enchantName = GuiEnchantColour.getColourOpIndex(colourOps, 0); @@ -475,20 +475,22 @@ public class ItemTooltipListener { String extraMods = extraModifiersBuilder.toString(); if (!colourCode.equals("z")) { - line = line.replace("\u00A79" + enchantText, "\u00A7" + colourCode + extraMods + enchantText); - line = line.replace("\u00A7b" + enchantText, "\u00A7" + colourCode + extraMods + enchantText); - line = line.replace( - "\u00A79\u00A7d\u00A7l" + enchantText, - "\u00A7" + colourCode + extraMods + enchantText - ); - line = line.replace( - "\u00A7b\u00A7d\u00A7l" + enchantText, - "\u00A7" + colourCode + extraMods + enchantText - ); - line = line.replace( - "\u00A7l\u00A7d\u00A7l" + enchantText, - "\u00A7" + colourCode + extraMods + enchantText - ); + if (!addedEnchants.contains(enchantText)) { + line = line.replace("\u00A79" + enchantText, "\u00A7" + colourCode + extraMods + enchantText); + line = line.replace("\u00A7b" + enchantText, "\u00A7" + colourCode + extraMods + enchantText); + line = line.replace( + "\u00A79\u00A7d\u00A7l" + enchantText, + "\u00A7" + colourCode + extraMods + enchantText + ); + line = line.replace( + "\u00A7b\u00A7d\u00A7l" + enchantText, + "\u00A7" + colourCode + extraMods + enchantText + ); + line = line.replace( + "\u00A7l\u00A7d\u00A7l" + enchantText, + "\u00A7" + colourCode + extraMods + enchantText + ); + } } else { int offset = Minecraft.getMinecraft().fontRendererObj.getStringWidth(line.replaceAll( "\\u00A79" + enchantText + ".*", @@ -516,6 +518,7 @@ public class ItemTooltipListener { Utils.chromaString(enchantText, offset / 12f + index, true) ); } + addedEnchants.add(enchantText); } } } @@ -689,18 +692,6 @@ public class ItemTooltipListener { index++; } - for (int i = newTooltip.size() - 1; i >= 0; i--) { - String line = Utils.cleanColour(newTooltip.get(i)); - for (int i1 = 0; i1 < Utils.rarityArr.length; i1++) { - if (line.equals(Utils.rarityArr[i1])) { - if (i - 2 < 0) { - break; - } - newTooltip.addAll(i - 1, petToolTipXPExtend(event)); - break; - } - } - } pressedShiftLast = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); pressedArrowLast = Keyboard.isKeyDown(Keyboard.KEY_LEFT) || Keyboard.isKeyDown(Keyboard.KEY_RIGHT); @@ -718,104 +709,45 @@ public class ItemTooltipListener { } } - private List<String> petToolTipXPExtend(ItemTooltipEvent event) { - List<String> tooltipText = new ArrayList<>(); - if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.petExtendExp) { - if (event.itemStack.getTagCompound().hasKey("DisablePetExp")) { - if (event.itemStack.getTagCompound().getBoolean("DisablePetExp")) { - return tooltipText; + private void petToolTipXPExtendPetMenu(ItemTooltipEvent event) { + if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.petExtendExp) return; + //7 is just a random number i chose, prob no pets with less lines than 7 + if (event.toolTip.size() < 7) return; + if (event.itemStack.getTagCompound().hasKey("NEUHIDEPETTOOLTIP")) return; + if (Utils.cleanColour(event.toolTip.get(1)).matches(petToolTipRegex)) { + GuiProfileViewer.PetLevel petLevel; + + int xpLine = -1; + for (int i = event.toolTip.size() - 1; i >= 0; i--) { + Matcher matcher = xpLevelPattern.matcher(event.toolTip.get(i)); + if (matcher.matches()) { + xpLine = i; + event.toolTip.set(xpLine, matcher.group(1)); + break; + } else if (event.toolTip.get(i).matches("MAX LEVEL")) { + return; } } - //7 is just a random number i chose, prob no pets with less lines than 7 - if (event.toolTip.size() > 7) { - if (Utils.cleanColour(event.toolTip.get(1)).matches(petToolTipRegex)) { - - GuiProfileViewer.PetLevel petlevel = null; - - //this is the item itself - NBTTagCompound tag = event.itemStack.getTagCompound(); - if (tag.hasKey("ExtraAttributes")) { - if (tag.getCompoundTag("ExtraAttributes").hasKey("petInfo")) { - JsonObject petInfo = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(tag - .getCompoundTag("ExtraAttributes") - .getString("petInfo"), JsonObject.class); - if (petInfo.has("exp") && petInfo.get("exp").isJsonPrimitive()) { - JsonPrimitive exp = petInfo.getAsJsonPrimitive("exp"); - String petName = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(event.itemStack); - //Utils.getRarityFromInt(Utils.checkItemTypePet(event.toolTip))).getAsInt(); - petlevel = GuiProfileViewer.getPetLevel( - petName, - Utils.getRarityFromInt(Utils.checkItemTypePet(event.toolTip)), - exp.getAsLong() - ); - } - } - } - if (petlevel != null) { - tooltipText.add(""); - if (petlevel.totalXp > petlevel.maxXP) { - tooltipText.add(EnumChatFormatting.AQUA + "" + EnumChatFormatting.BOLD + "MAX LEVEL"); - } else { - tooltipText.add( - EnumChatFormatting.GRAY + "Progress to Level " + (int) Math.floor(petlevel.level + 1) + ": " + - EnumChatFormatting.YELLOW + Utils.round(petlevel.levelPercentage * 100, 1) + "%"); - int levelpercentage = Math.round(petlevel.levelPercentage * 20); - tooltipText.add( - EnumChatFormatting.DARK_GREEN + String.join("", Collections.nCopies(levelpercentage, "-")) + - EnumChatFormatting.WHITE + String.join("", Collections.nCopies(20 - levelpercentage, "-"))); - tooltipText.add( - EnumChatFormatting.GRAY + "EXP: " + EnumChatFormatting.YELLOW + myFormatter.format(petlevel.levelXp) + - EnumChatFormatting.GOLD + "/" + EnumChatFormatting.YELLOW + - myFormatter.format(petlevel.currentLevelRequirement) + " EXP"); - } - } - } + PetInfoOverlay.Pet pet = PetInfoOverlay.getPetFromStack( + event.itemStack.getTagCompound() + ); + if (pet == null) { + return; } - } - return tooltipText; - } + petLevel = pet.petLevel; - private void petToolTipXPExtendPetMenu(ItemTooltipEvent event) { - if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.petExtendExp) { - //7 is just a random number i chose, prob no pets with less lines than 7 - if (event.toolTip.size() > 7) { - if (Utils.cleanColour(event.toolTip.get(1)).matches(petToolTipRegex)) { - GuiProfileViewer.PetLevel petLevel; - - int xpLine = -1; - for (int i = event.toolTip.size() - 1; i >= 0; i--) { - Matcher matcher = xpLevelPattern.matcher(event.toolTip.get(i)); - if (matcher.matches()) { - xpLine = i; - event.toolTip.set(xpLine, matcher.group(1)); - break; - } else if (event.toolTip.get(i).matches("MAX LEVEL")) { - return; - } - } - - PetInfoOverlay.Pet pet = PetInfoOverlay.getPetFromStack( - event.itemStack.getTagCompound() - ); - if (pet == null) { - return; - } - petLevel = pet.petLevel; - - if (petLevel == null || xpLine == -1) { - return; - } + if (petLevel == null || xpLine == -1) { + return; + } - event.toolTip.add( - xpLine + 1, - EnumChatFormatting.GRAY + "EXP: " + EnumChatFormatting.YELLOW + myFormatter.format(petLevel.levelXp) + - EnumChatFormatting.GOLD + "/" + EnumChatFormatting.YELLOW + - myFormatter.format(petLevel.currentLevelRequirement) - ); + event.toolTip.add( + xpLine + 1, + EnumChatFormatting.GRAY + "EXP: " + EnumChatFormatting.YELLOW + myFormatter.format(petLevel.levelXp) + + EnumChatFormatting.GOLD + "/" + EnumChatFormatting.YELLOW + + myFormatter.format(petLevel.currentLevelRequirement) + ); - } - } } } @@ -911,6 +843,7 @@ public class ItemTooltipListener { MiscUtils.copyToClipboard(NotEnoughUpdates.INSTANCE.manager.getSkullValueForItem(event.itemStack)); } + event.toolTip.add( EnumChatFormatting.AQUA + "Internal Name: " + EnumChatFormatting.GRAY + internal + EnumChatFormatting.GOLD + " [K]"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java index bbbb9049..fdae53ea 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java @@ -27,6 +27,8 @@ import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.util.Calculator; import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery; +import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.item.ItemStack; import net.minecraftforge.event.entity.player.ItemTooltipEvent; @@ -135,14 +137,18 @@ public class ItemTooltipRngListener { event.toolTip.addAll(newToolTip); } - private String getFormatCoinsPer(ItemStack stack, int needed, int multiplier, String name) { - String internalName = neu.manager.getInternalNameForItem(stack); - double bin = neu.manager.auctionManager.getBazaarOrBin(internalName); - if (bin <= 0) return null; + private String getFormatCoinsPer(ItemStack stack, int needed, int multiplier, String label) { + String internalName = neu.manager.createItemResolutionQuery().withItemStack(stack).resolveInternalName(); + double profit = neu.manager.auctionManager.getBazaarOrBin(internalName); + if (profit <= 0) return null; - double coinsPer = (bin / needed) * multiplier; + //ask hypixel nicely to release a 'chest price api' with 4 dimensions for us. the 4 dimensions needed are: item name, floor, normal/mm, s/s+ +// double chestPrice = grabChestPrice(stack, internalName); +// profit -= chestPrice; + + double coinsPer = (profit / needed) * multiplier; String format = StringUtils.shortNumberFormat(coinsPer); - return "§7Coins per " + name + ": §6" + format + " coins"; + return "§7Coins per " + label + ": §6" + format + " coins"; } private void fractionDisplay(List<String> newToolTip, String line) { @@ -256,10 +262,12 @@ public class ItemTooltipRngListener { Map<String, Integer> runsData; String labelPlural; String labelSingular; + String repoCategory; if (openChestName.contains("Catacombs")) { runsData = dungeonData; labelPlural = "Runs"; labelSingular = "Run"; + repoCategory = "catacombs"; } else { // Slayer Matcher matcher = SLAYER_INVENTORY_TITLE_PATTERN.matcher(openChestName); if (!matcher.matches()) { @@ -271,6 +279,12 @@ public class ItemTooltipRngListener { runsData = slayerData.get(slayerName); labelPlural = "Bosses"; labelSingular = "Boss"; + repoCategory = "slayer"; + } + + int repoScore = getRepoScore(stack, repoCategory); + if (repoScore != -1) { + needed = repoScore; } handleArrowKeys(runsData); @@ -282,7 +296,7 @@ public class ItemTooltipRngListener { String name = (String) runsData.keySet().toArray()[currentSelected]; int gainPerRun = runsData.get(name); - int runsNeeded = needed / gainPerRun; + int runsNeeded = (int) Math.floor((double) needed / (double) gainPerRun); int runsHaving = having / gainPerRun; String runsNeededFormat = GuiProfileViewer.numberFormat.format(runsNeeded); String runsHavingFormat = GuiProfileViewer.numberFormat.format(runsHaving); @@ -309,6 +323,49 @@ public class ItemTooltipRngListener { } } + private int getRepoScore(ItemStack stack, String repoCategory) { + ItemResolutionQuery query = + NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(stack).withCurrentGuiContext(); + String internalName = query.resolveInternalName(); + + JsonObject jsonObject = Constants.RNGSCORE; + if (jsonObject == null) { + Utils.showOutdatedRepoNotification(); + return -1; + } + + String repoType = grabRepoType(stack); + if (!jsonObject.has(repoCategory)) return -1; + + JsonObject category = jsonObject.get(repoCategory).getAsJsonObject(); + if (!category.has(repoType)) return -1; + + JsonObject typeObject = category.get(repoType).getAsJsonObject(); + if (!typeObject.has(internalName)) return -1; + + return typeObject.get(internalName).getAsInt(); + } + + // Determines the floor or the slayer type from where the item can be obtained. E.g. F7, M3, Revenant Horror or Sven Packmaster + private String grabRepoType(ItemStack stack) { + String openChestName = Utils.getOpenChestName(); + if (openChestName.contains("Catacombs")) { + if (openChestName.equals("Catacombs RNG Meter")) { + List<String> list = ItemUtils.getLore(stack); + String line = list.get(4); + return line.substring(26, 28); + } else { + // supporting more pages (f7/m7) + if (openChestName.contains("(")) { + return openChestName.substring(17, 19); + } + return openChestName.substring(11, 13); + } + } else { + return openChestName.substring(0, openChestName.length() - 9); + } + } + private void handleArrowKeys(Map<String, Integer> runsData) { boolean left = Keyboard.isKeyDown(Keyboard.KEY_LEFT); boolean right = Keyboard.isKeyDown(Keyboard.KEY_RIGHT); 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 166e46d0..6460e1ed 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -50,14 +50,17 @@ import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; import io.github.moulberry.notenoughupdates.miscgui.TradeWindow; import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; +import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay; import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay; +import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.RancherBootOverlay; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; +import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.RequestFocusListener; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -406,7 +409,7 @@ public class RenderListener { GL11.glTranslatef(0, 0, 10); } if (hoverInv) { - renderDungeonChestOverlay(event.gui); + renderDungKuudraChestOverlay(event.gui); if (NotEnoughUpdates.INSTANCE.config.accessoryBag.enableOverlay) { AccessoryBagOverlay.renderOverlay(); } @@ -444,12 +447,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 = @@ -534,12 +544,12 @@ public class RenderListener { x -= 68 - 200; } } - if (NEUOverlay.isRenderingArmorHud()) { + if (EquipmentOverlay.isRenderingArmorHud()) { if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { x -= 25; } } - if (NEUOverlay.isRenderingPetHud()) { + if (EquipmentOverlay.isRenderingPetHud()) { if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { x -= 25; } @@ -594,6 +604,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; } @@ -615,7 +626,7 @@ public class RenderListener { } if (NotificationHandler.shouldRenderOverlay(event.gui) && neu.isOnSkyblock() && !hoverInv) { - renderDungeonChestOverlay(event.gui); + renderDungKuudraChestOverlay(event.gui); if (NotEnoughUpdates.INSTANCE.config.accessoryBag.enableOverlay) { AccessoryBagOverlay.renderOverlay(); } @@ -661,12 +672,12 @@ public class RenderListener { x -= 68 - 200; } } - if (NEUOverlay.isRenderingArmorHud()) { + if (EquipmentOverlay.isRenderingArmorHud()) { if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { x -= 25; } } - if (NEUOverlay.isRenderingPetHud()) { + if (EquipmentOverlay.isRenderingPetHud()) { if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { x -= 25; } @@ -724,7 +735,7 @@ public class RenderListener { } } - private void renderDungeonChestOverlay(GuiScreen gui) { + private void renderDungKuudraChestOverlay(GuiScreen gui) { if (NotEnoughUpdates.INSTANCE.config.dungeons.profitDisplayLoc == 3) return; if (gui instanceof GuiChest && NotEnoughUpdates.INSTANCE.config.dungeons.profitDisplayLoc != 2) { try { @@ -761,7 +772,9 @@ public class RenderListener { HashMap<String, Double> itemValues = new HashMap<>(); for (int i = 0; i < 5; i++) { ItemStack item = lower.getStackInSlot(11 + i); - String internal = neu.manager.getInternalNameForItem(item); + if (ItemUtils.isSoulbound(item)) continue; + + String internal = neu.manager.createItemResolutionQuery().withItemStack(item).resolveInternalName(); String displayName = item.getDisplayName(); Matcher matcher = ESSENCE_PATTERN.matcher(displayName); if (neu.config.dungeons.useEssenceCostFromBazaar && matcher.matches()) { @@ -782,12 +795,16 @@ public class RenderListener { JsonObject bazaarInfo = neu.manager.auctionManager.getBazaarInfo(internal); if (bazaarInfo != null && bazaarInfo.has("curr_sell")) { bazaarPrice = bazaarInfo.get("curr_sell").getAsFloat(); + } else if (bazaarInfo != null) { + bazaarPrice = 0; } if (bazaarPrice < 5000000 && internal.equals("RECOMBOBULATOR_3000")) bazaarPrice = 5000000; double worth = -1; - if (bazaarPrice > 0) { + boolean isOnBz = false; + if (bazaarPrice >= 0) { worth = bazaarPrice; + isOnBz = true; } else { switch (NotEnoughUpdates.INSTANCE.config.dungeons.profitType) { case 1: @@ -825,7 +842,7 @@ public class RenderListener { } } - if (worth > 0 && totalValue >= 0) { + if ((worth >= 0 || isOnBz) && totalValue >= 0) { totalValue += worth; String display = item.getDisplayName(); @@ -1047,12 +1064,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 = @@ -1126,12 +1149,12 @@ public class RenderListener { x -= 68 - 200; } } - if (NEUOverlay.isRenderingArmorHud()) { + if (EquipmentOverlay.isRenderingArmorHud()) { if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { x -= 25; } } - if (NEUOverlay.isRenderingPetHud()) { + if (EquipmentOverlay.isRenderingPetHud()) { if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { x -= 25; } @@ -1516,12 +1539,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/miscfeatures/AntiCoopAdd.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java new file mode 100644 index 00000000..25aaaa0a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.event.ClickEvent; +import net.minecraft.event.HoverEvent; +import net.minecraft.init.Items; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class AntiCoopAdd { + + public static boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { + if (!NotEnoughUpdates.INSTANCE.config.misc.coopWarning) return false; + if (slotId == -999) return false; + if (!Utils.getOpenChestName().contains("Profile")) return false; + + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + + ItemStack stack = chest.inventorySlots.getSlot(slotId).getStack(); + if (stack == null) return false; + if (stack.getItem() == Items.diamond && stack.getDisplayName() != null && stack.getDisplayName().contains("Co-op Request")) { + String ign = Utils.getOpenChestName().split("'s Profile")[0]; + ChatComponentText storageMessage = new ChatComponentText( + EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.YELLOW + + "You just clicked on the Co-op add button. If you want to coop add this person, click this chat message"); + storageMessage.setChatStyle(Utils.createClickStyle(ClickEvent.Action.RUN_COMMAND, "/coopadd " + ign)); + storageMessage.setChatStyle(storageMessage.getChatStyle().setChatHoverEvent( + new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ChatComponentText(EnumChatFormatting.YELLOW + "Click to add " + ign + " to your coop")))); + ChatComponentText storageChatMessage = new ChatComponentText(""); + storageChatMessage.appendSibling(storageMessage); + Minecraft.getMinecraft().thePlayer.addChatMessage(storageChatMessage); + return true; + } + + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java index 7007f39b..9ab85390 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BazaarSacksProfit.java @@ -103,6 +103,10 @@ public class BazaarSacksProfit { .getItemInformation() .entrySet()) { String internalName = entry.getKey(); + + // Ignoring builder melon, builder clay and builder cactus + if (NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName) == null) continue; + JsonObject object = entry.getValue(); if (object.has("displayname")) { String name = object.get("displayname").getAsString(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java index 167b6a2f..ab9345cb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java @@ -170,7 +170,7 @@ public class CrystalMetalDetectorSolver { // falls through case FOUND: mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution.")); - if (NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.contains(NEUDebugFlag.METAL) && + if (NEUDebugFlag.METAL.isSet() && (previousState == SolutionState.INVALID || previousState == SolutionState.FAILED)) { NEUDebugLogger.log( NEUDebugFlag.METAL, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java index 36b58424..d5a8a53f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java @@ -924,7 +924,7 @@ public class CrystalWishingCompassSolver { return; } - boolean wishingDebugFlagSet = NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.contains(NEUDebugFlag.WISHING); + boolean wishingDebugFlagSet = NEUDebugFlag.WISHING.isSet(); if (outputAlways || wishingDebugFlagSet) { NEUDebugLogger.logAlways(getDiagnosticMessage()); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java index 558917fe..a1580d8e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java @@ -342,8 +342,9 @@ public class EnchantingSolvers { if (chronomatronReplayIndex < chronomatronOrder.size()) { String chronomatronCurrent = chronomatronOrder.get(chronomatronReplayIndex); - if (!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks1 || - chronomatronCurrent.equals(displayName) || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT) { + if ((!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks1 || + chronomatronCurrent.equals(displayName) || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT) && + stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane) && slotId != 4 && slotId != 49) { chronomatronReplayIndex++; Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, 2, mode, Minecraft.getMinecraft().thePlayer @@ -374,7 +375,7 @@ public class EnchantingSolvers { long currentTime = System.currentTimeMillis(); if (currentTime - millisLastClick > 150 && (!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks1 || - current.containerIndex == slotId || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT)) { + current.containerIndex == slotId || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT) && (slotId < 45 && slotId > 8)) { ultrasequencerReplayIndex++; Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, 2, mode, Minecraft.getMinecraft().thePlayer diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 90300bbc..499448fa 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -26,7 +26,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.util.StringUtils; @@ -134,6 +133,13 @@ public class PetInfoOverlay extends TextOverlay { public String petXpType; public String petItem; public String skin; + public int candyUsed; + + public String getPetId(boolean withoutBoost) { + boolean shouldDecreaseRarity = withoutBoost && "PET_ITEM_TIER_BOOST".equals(petItem); + return petType + ";" + (shouldDecreaseRarity ? rarity.petId - 1 : rarity.petId); + } + } public static class PetConfig { @@ -243,7 +249,8 @@ public class PetInfoOverlay extends TextOverlay { } private static Pet getClosestPet(String petType, int petId, String petItem, float petLevel) { - Set<Pet> pets = config.petMap.values().stream().filter(pet -> pet.petType.equals(petType) && pet.rarity.petId == petId).collect( + Set<Pet> pets = config.petMap.values().stream().filter(pet -> pet.petType.equals(petType) && + pet.rarity.petId == petId).collect( Collectors.toSet()); if (pets.isEmpty()) { @@ -254,7 +261,10 @@ public class PetInfoOverlay extends TextOverlay { return pets.iterator().next(); } - Set<Pet> itemMatches = pets.stream().filter(pet -> Objects.equals(petItem, pet.petItem)).collect(Collectors.toSet()); + Set<Pet> itemMatches = pets + .stream() + .filter(pet -> Objects.equals(petItem, pet.petItem)) + .collect(Collectors.toSet()); if (itemMatches.size() == 1) { return itemMatches.iterator().next(); @@ -452,14 +462,15 @@ public class PetInfoOverlay extends TextOverlay { } } - if (currentPet.petLevel.level < (currentPet.petLevel.maxLevel - 1) || !NotEnoughUpdates.INSTANCE.config.petOverlay.petOverlayText.contains(6)) { + if (currentPet.petLevel.level < (currentPet.petLevel.maxLevel - 1) || + !NotEnoughUpdates.INSTANCE.config.petOverlay.petOverlayText.contains(6)) { float remainingMax = currentPet.petLevel.maxXP - currentPet.petLevel.totalXp; if (remaining > 0) { if (xpGain < 1000) { - etaMaxStr = EnumChatFormatting.AQUA + "Until L" + currentPet.petLevel.maxLevel + ": " + + etaMaxStr = EnumChatFormatting.AQUA + "Until L" + (int) currentPet.petLevel.maxLevel + ": " + EnumChatFormatting.YELLOW + "N/A"; } else { - etaMaxStr = EnumChatFormatting.AQUA + "Until L" + currentPet.petLevel.maxLevel + ": " + + etaMaxStr = EnumChatFormatting.AQUA + "Until L" + (int) currentPet.petLevel.maxLevel + ": " + EnumChatFormatting.YELLOW + Utils.prettyTime((long) (remainingMax) * 1000 * 60 * 60 / (long) xpGain); } } @@ -563,7 +574,7 @@ public class PetInfoOverlay extends TextOverlay { JsonObject petInfo = new JsonParser().parse(ea.getString("petInfo")).getAsJsonObject(); petType = petInfo.get("type").getAsString(); rarity = Rarity.valueOf(petInfo.get("tier").getAsString()); - level = GuiProfileViewer. getPetLevel( + level = GuiProfileViewer.getPetLevel( petType, rarity.name(), Utils.getElementAsFloat(petInfo.get("exp"), 0) // Should only default if from item list and repo missing exp:0 @@ -782,7 +793,8 @@ public class PetInfoOverlay extends TextOverlay { if (currentPet.rarity.petId == 5) { mythicRarity = 4; } - JsonObject petItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(currentPet.skin != null ? currentPet.skin : (currentPet.petType + ";" + mythicRarity)); + JsonObject petItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get( + currentPet.skin != null ? currentPet.skin : (currentPet.petType + ";" + mythicRarity)); if (petItem != null) { Vector2f position = getPosition(overlayWidth, overlayHeight); int x = (int) position.x; @@ -799,7 +811,8 @@ public class PetInfoOverlay extends TextOverlay { Pet currentPet2 = getCurrentPet2(); if (currentPet2 != null) { - JsonObject petItem2 = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(currentPet2.skin != null ? currentPet2.skin : (currentPet2.petType + ";" + currentPet2.rarity.petId)); + JsonObject petItem2 = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get( + currentPet2.skin != null ? currentPet2.skin : (currentPet2.petType + ";" + currentPet2.rarity.petId)); if (petItem2 != null) { Vector2f position = getPosition(overlayWidth, overlayHeight); int x = (int) position.x; @@ -847,8 +860,7 @@ public class PetInfoOverlay extends TextOverlay { ); public static void onStackClick(ItemStack stack, int windowId, int slotId, int mouseButtonClicked, int mode) { - if (mode != 0) return; - if (mouseButtonClicked != 0 && mouseButtonClicked != 1) return; + if (mouseButtonClicked != 0 && mouseButtonClicked != 1 && mouseButtonClicked != 2) return; int slotIdMod = (slotId - 10) % 9; if (slotId >= 10 && slotId <= 43 && slotIdMod >= 0 && slotIdMod <= 6 && @@ -1031,18 +1043,12 @@ public class PetInfoOverlay extends TextOverlay { @SubscribeEvent(priority = EventPriority.HIGHEST) public void onChatReceived(ClientChatReceivedEvent event) { NEUConfig config = NotEnoughUpdates.INSTANCE.config; - if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && - (config.petOverlay.enablePetInfo || config.itemOverlays.enableMonkeyCheck || config.petOverlay.petInvDisplay)) { + if (config.petOverlay.enablePetInfo || config.itemOverlays.enableMonkeyCheck || config.petOverlay.petInvDisplay) { if (event.type == 0) { String chatMessage = Utils.cleanColour(event.message.getUnformattedText()); Matcher autopetMatcher = AUTOPET_EQUIP.matcher(event.message.getFormattedText()); - if (event.message.getUnformattedText().startsWith("You summoned your") || - System.currentTimeMillis() - NEUOverlay.cachedPetTimer < 500) { - NEUOverlay.cachedPetTimer = System.currentTimeMillis(); - NEUOverlay.shouldUseCachedPet = false; - } else if (autopetMatcher.matches()) { - NEUOverlay.shouldUseCachedPet = false; + if (autopetMatcher.matches()) { try { lastLevelHovered = Integer.parseInt(autopetMatcher.group(1)); } catch (NumberFormatException ignored) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java index 680637f2..93e9f516 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java @@ -38,12 +38,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTException; import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagByteArray; import net.minecraft.nbt.NBTTagCompound; @@ -82,11 +84,12 @@ public class StorageManager { private static final StorageManager INSTANCE = new StorageManager(); private static final Gson GSON = new GsonBuilder() .registerTypeAdapter(ItemStack.class, new ItemStackSerializer()) - .registerTypeAdapter(ItemStack.class, new ItemStackDeserilizer()).create(); + .registerTypeAdapter(ItemStack.class, new ItemStackDeserializer()).create(); public static class ItemStackSerializer implements JsonSerializer<ItemStack> { @Override public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) { + fixPetInfo(src); NBTTagCompound tag = src.serializeNBT(); return nbtToJson(tag); } @@ -94,7 +97,7 @@ public class StorageManager { private static final Pattern JSON_FIX_REGEX = Pattern.compile("\"([^,:]+)\":"); - public static class ItemStackDeserilizer implements JsonDeserializer<ItemStack> { + public static class ItemStackDeserializer implements JsonDeserializer<ItemStack> { @Override public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { @@ -134,6 +137,63 @@ public class StorageManager { return (JsonObject) loadJson(NBTTagCompound); } + private static class PetInfo { + String type; + Boolean active; + Double exp; + String tier; + Boolean hideInfo; + Integer candyUsed; + String uuid; + Boolean hideRightClick; + String heldItem; + String skin; + + private <T> void appendIfNotNull(StringBuilder builder, String key, T value) { + if (value != null) { + if (builder.indexOf("{") != builder.length()-1) { + builder.append(","); + } + builder.append(key).append(":"); + if (value instanceof String) { + builder.append("\"").append(value).append("\""); + } else { + builder.append(value); + } + } + } + + @Override + public String toString() { + StringBuilder object = new StringBuilder(); + object.append("{"); + appendIfNotNull(object, "type", type); + appendIfNotNull(object, "active", active); + appendIfNotNull(object, "exp", exp); + appendIfNotNull(object, "tier", tier); + appendIfNotNull(object, "hideInfo", hideInfo); + appendIfNotNull(object, "candyUsed", candyUsed); + appendIfNotNull(object, "uuid", uuid); + appendIfNotNull(object, "hideRightClick", hideRightClick); + appendIfNotNull(object, "heldItem", heldItem); + appendIfNotNull(object, "skin", skin); + object.append("}"); + return object.toString(); + } + } + + private static void fixPetInfo(ItemStack src) { + if (src.getTagCompound() == null || !src.getTagCompound().hasKey("ExtraAttributes") || !src.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("petInfo")) return; + PetInfo oldPetInfo = GSON.fromJson(src.getTagCompound().getCompoundTag("ExtraAttributes").getString("petInfo"), PetInfo.class); + src.getTagCompound().getCompoundTag("ExtraAttributes").removeTag("petInfo"); + try { + src.getTagCompound().getCompoundTag("ExtraAttributes").setTag( + "petInfo", + JsonToNBT.getTagFromJson(oldPetInfo.toString()) + ); + } catch (NBTException | NullPointerException ignored) {} + } + private static JsonElement loadJson(NBTBase tag) { if (tag instanceof NBTTagCompound) { NBTTagCompound compoundTag = (NBTTagCompound) tag; @@ -555,8 +615,8 @@ public class StorageManager { int index = slot - 9; boolean changed = false; - if (stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) && - stack.getMetadata() == 14) { + if ((stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) && + stack.getMetadata() == 14) || (stack.getItem() == Items.dye && stack.getMetadata() == 8)) { if (storagePresent[index]) changed = true; storagePresent[index] = false; removePage(index); @@ -596,7 +656,8 @@ public class StorageManager { boolean changed = false; - if (stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane)) { + if (stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) + || (stack.getItem() == Items.dye && stack.getMetadata() == 8)) { if (storagePresent[index]) changed = true; storagePresent[index] = false; removePage(index); 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..6f190ada 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiCustomEnchant.java @@ -28,9 +28,11 @@ 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; +import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; @@ -74,9 +76,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 +107,7 @@ public class GuiCustomEnchant extends Gui { this.enchId = enchId; this.displayLore = displayLore; this.level = level; + this.enchId = ItemUtils.fixEnchantId(enchId, true); if (Constants.ENCHANTS != null) { if (checkConflicts && Constants.ENCHANTS.has("enchant_pools")) { @@ -133,12 +136,18 @@ public class GuiCustomEnchant extends Gui { 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); + JsonObject maxLevel = null; + if (Constants.ENCHANTS.has("max_xp_table_levels")) { + maxLevel = Constants.ENCHANTS.getAsJsonObject("max_xp_table_levels"); + } + + if (allCosts.has(this.enchId)) { + JsonArray costs = allCosts.getAsJsonArray(this.enchId); if (costs.size() >= 1) { if (useMaxLevelForCost) { - this.xpCost = costs.get(costs.size() - 1).getAsInt(); + int cost = (maxLevel != null && maxLevel.has(this.enchId) ? maxLevel.get(this.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 +161,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<ExperienceOrb> orbs = new ArrayList<>(); - private int orbTargetX = 0; - private int orbTargetY = 0; + public OrbDisplay orbDisplay = new OrbDisplay(); private int guiLeft; private int guiTop; @@ -226,8 +221,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 +237,13 @@ 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) { + shouldOverrideFast = false; + return false; + } return shouldOverrideFast; } @@ -245,13 +254,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 +316,7 @@ public class GuiCustomEnchant extends Gui { } } - 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); + orbDisplay.physicsTickOrbs(); if (++tickCounter >= 20) { tickCounter = 0; @@ -389,40 +377,50 @@ 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("-", "_") + .replaceAll("[^a-z_]", ""); + 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 +453,53 @@ 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("-", "_") + .replaceAll("[^a-z_]", ""); + if (enchId.equalsIgnoreCase("_")) continue; + enchId = ItemUtils.fixEnchantId(enchId, true); + 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; } - } + } } } @@ -1065,7 +1073,9 @@ public class GuiCustomEnchant extends Gui { Minecraft.getMinecraft().fontRendererObj.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); //Enchant name - String name = WordUtils.capitalizeFully(enchanterCurrentEnch.enchId.replace("_", " ")); + String name = WordUtils.capitalizeFully(ItemUtils + .fixEnchantId(enchanterCurrentEnch.enchId, false) + .replace("_", " ")); if (name.equalsIgnoreCase("Bane of Arthropods")) { name = "Bane of Arth."; } else if (name.equalsIgnoreCase("Projectile Protection")) { @@ -1356,37 +1366,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 +1387,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 +1493,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 +1545,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 +1570,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 +1743,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 +1783,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 +1830,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 +1851,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/GuiEnchantColour.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java index 31713189..b90b1356 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java @@ -271,17 +271,21 @@ public class GuiEnchantColour extends GuiScreen { } if (mouseX >= guiLeft + xSize + 3 && mouseX < guiLeft + xSize + 39) { + boolean renderingTooltip = false; + if (mouseY >= guiTopSidebar - 34 && mouseY <= guiTopSidebar - 18 && maxedBookFound == 1) { tooltipToDisplay = maxedBook.getTooltip(Minecraft.getMinecraft().thePlayer, false); Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); tooltipToDisplay = null; + renderingTooltip = true; } - if (mouseY >= guiTopSidebar - 52 && mouseY <= guiTopSidebar - 34 && maxedAttBookFound == 1) { + if (mouseY >= guiTopSidebar - 52 && mouseY <= guiTopSidebar - 34 && maxedAttBookFound == 1 && !renderingTooltip) { tooltipToDisplay = maxedAttBook.getTooltip(Minecraft.getMinecraft().thePlayer, false); Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); tooltipToDisplay = null; + renderingTooltip = true; } - if (mouseY >= guiTopSidebar - 18 && mouseY <= guiTopSidebar - 2) { + if (mouseY >= guiTopSidebar - 18 && mouseY <= guiTopSidebar - 2 && !renderingTooltip) { tooltipToDisplay = Lists.newArrayList( EnumChatFormatting.AQUA + "NEUEC Colouring Guide", EnumChatFormatting.GREEN + "", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java index 40e12e35..7aa0d2ec 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java @@ -25,11 +25,13 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; 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.core.GlScissorStack; import io.github.moulberry.notenoughupdates.core.GuiElementTextField; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -83,6 +85,15 @@ public class GuiInvButtonEditor extends GuiScreen { private int guiLeft; private int guiTop; + //region getGuiCoordinates + public int getGuiLeft() { + return this.guiLeft; + } + public int getGuiTop() { + return this.guiTop; + } + //endregion + private static final int BACKGROUND_TYPES = 5; private static final int ICON_TYPES = 3; private int iconTypeIndex = 0; @@ -316,6 +327,13 @@ public class GuiInvButtonEditor extends GuiScreen { GlStateManager.color(1, 1, 1, 1); Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, xSize / 256f, 0, ySize / 256f, GL11.GL_NEAREST); + if (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud) { + EquipmentOverlay.INSTANCE.renderPreviewArmorHud(); + } + if (NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay) { + EquipmentOverlay.INSTANCE.renderPreviewPetInvHud(); + } + for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { int x = guiLeft + button.x; int y = guiTop + button.y; @@ -326,6 +344,17 @@ public class GuiInvButtonEditor extends GuiScreen { y += ySize; } + if (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud) { + if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { + x -= 25; + } + } + if (NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay) { + if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { + x -= 25; + } + } + if (button.isActive()) { GlStateManager.color(1, 1, 1, 1f); } else { @@ -358,7 +387,7 @@ public class GuiInvButtonEditor extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(custom_ench_colour); GlStateManager.color(1, 1, 1, 1); Utils.drawTexturedRect( - guiLeft - 88 - 2 - 22, + guiLeft - 88 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 2, 88, 20, @@ -369,7 +398,7 @@ public class GuiInvButtonEditor extends GuiScreen { GL11.GL_NEAREST ); Utils.drawTexturedRect( - guiLeft - 88 - 2 - 22, + guiLeft - 88 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 2 + 24, 88, 20, @@ -382,7 +411,7 @@ public class GuiInvButtonEditor extends GuiScreen { Utils.drawStringCenteredScaledMaxWidth( "Load preset", fontRendererObj, - guiLeft - 44 - 2 - 22, + guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 8, false, 86, @@ -391,7 +420,7 @@ public class GuiInvButtonEditor extends GuiScreen { Utils.drawStringCenteredScaledMaxWidth( "from Clipboard", fontRendererObj, - guiLeft - 44 - 2 - 22, + guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 16, false, 86, @@ -400,7 +429,7 @@ public class GuiInvButtonEditor extends GuiScreen { Utils.drawStringCenteredScaledMaxWidth( "Save preset", fontRendererObj, - guiLeft - 44 - 2 - 22, + guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 8 + 24, false, 86, @@ -409,7 +438,7 @@ public class GuiInvButtonEditor extends GuiScreen { Utils.drawStringCenteredScaledMaxWidth( "to Clipboard", fontRendererObj, - guiLeft - 44 - 2 - 22, + guiLeft - 44 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 16 + 24, false, 86, @@ -417,7 +446,7 @@ public class GuiInvButtonEditor extends GuiScreen { ); if (!validShareContents()) { - Gui.drawRect(guiLeft - 88 - 2 - 22, guiTop + 2, guiLeft - 2 - 22, guiTop + 2 + 20, 0x80000000); + Gui.drawRect(guiLeft - 88 - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 2, guiLeft - 2 - 22 - (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud ? 25 : 0), guiTop + 2 + 20, 0x80000000); } GlStateManager.color(1, 1, 1, 1); @@ -461,6 +490,17 @@ public class GuiInvButtonEditor extends GuiScreen { y += ySize; } + if (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud) { + if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { + x -= 25; + } + } + if (NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay) { + if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { + x -= 25; + } + } + GlStateManager.translate(0, 0, 300); editorLeft = x + 8 - editorXSize / 2; editorTop = y + 18 + 2; @@ -741,6 +781,17 @@ public class GuiInvButtonEditor extends GuiScreen { y += ySize; } + if (NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud) { + if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop && y < guiTop + 84) { + x -= 25; + } + } + if (NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay) { + if (x < guiLeft + xSize - 150 && x > guiLeft + xSize - 200 && y > guiTop + 60 && y < guiTop + 120) { + x -= 25; + } + } + if (mouseX >= x && mouseY >= y && mouseX <= x + 18 && mouseY <= y + 18) { if (editingButton == button) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java index 7e6b991c..8878c284 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java @@ -45,13 +45,17 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.shader.Framebuffer; +import net.minecraft.event.ClickEvent; +import net.minecraft.event.HoverEvent; 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.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.ClientCommandHandler; import org.lwjgl.input.Keyboard; @@ -414,7 +418,7 @@ public class StorageOverlay extends GuiElement { if (stackOnMouse != null) { String stackDisplay = Utils.cleanColour(stackOnMouse.getDisplayName()); if (stackDisplay.startsWith("Backpack Slot ") || stackDisplay.startsWith("Empty Backpack Slot ") || - stackDisplay.startsWith("Ender Chest Page ")) { + stackDisplay.startsWith("Ender Chest Page ") || stackDisplay.startsWith("Locked Backpack Slot ")) { stackOnMouse = null; } } @@ -1966,6 +1970,16 @@ public class StorageOverlay extends GuiElement { switch (buttonIndex) { case 0: NotEnoughUpdates.INSTANCE.config.storageGUI.enableStorageGUI3 = false; + ChatComponentText storageMessage = new ChatComponentText( + EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.YELLOW + + "You just disabled the custom storage gui, did you mean to do that? If not click this message to turn it back on."); + storageMessage.setChatStyle(Utils.createClickStyle(ClickEvent.Action.RUN_COMMAND, "/neuenablestorage")); + storageMessage.setChatStyle(storageMessage.getChatStyle().setChatHoverEvent( + new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ChatComponentText(EnumChatFormatting.YELLOW + "Click to enable the custom storage gui.")))); + ChatComponentText storageChatMessage = new ChatComponentText(""); + storageChatMessage.appendSibling(storageMessage); + Minecraft.getMinecraft().thePlayer.addChatMessage(storageChatMessage); break; case 1: int size = 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 <https://www.gnu.org/licenses/>. + */ + +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..5361ae89 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/GuiCustomHex.java @@ -0,0 +1,4885 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.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.ItemUtils; +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<String> 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<String> 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(); + } + this.enchId = ItemUtils.fixEnchantId(this.enchId, true); + + 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 (this.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"); + JsonObject maxLevel = null; + if (NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel && Constants.ENCHANTS.has( + "max_xp_table_levels")) { + maxLevel = Constants.ENCHANTS.getAsJsonObject("max_xp_table_levels"); + } + + if (allCosts.has(this.enchId)) { + JsonArray costs = allCosts.getAsJsonArray(this.enchId); + + if (costs.size() >= 1) { + if (useMaxLevelForCost) { + int cost = + (maxLevel != null && maxLevel.has(this.enchId) ? maxLevel.get(this.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 { + 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<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 List<HexItem> applicableItem = new ArrayList<>(); + private final List<HexItem> removableItem = new ArrayList<>(); + private final HashMap<Integer, Enchantment> enchanterEnchLevels = new HashMap<>(); + private final HashMap<Integer, HexItem> 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.enableHexGUI; + final List<String> 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<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; + 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) { + 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("-", "_") + .replaceAll("[^a-z_]", ""); + 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"); + } + if (lore.contains("Loading...")) { + if (enchantment.price > 0) { + enchantment.displayLore.set(index, "\u00a7eClick to buy on the Bazaar!"); + } else { + enchantment.displayLore.set(index, "\u00a7cNot enough supply on the Bazaar!"); + } + } + index++; + } + enchantment.displayLore.remove(0); + + if (removingEnchantPlayerLevel == -1 && playerEnchantIds.containsKey(enchId)) { + removingEnchantPlayerLevel = playerEnchantIds.get(enchId); + } + + if (removingEnchantPlayerLevel >= 0 && enchantment.level < removingEnchantPlayerLevel) { + continue; + } + + boolean aboveMaxLevelFromEt = false; + if (NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel && Constants.ENCHANTS != null) { + JsonObject maxLevel = null; + if (Constants.ENCHANTS.has("max_xp_table_levels")) { + maxLevel = Constants.ENCHANTS.getAsJsonObject("max_xp_table_levels"); + } + if (maxLevel != null && maxLevel.has(enchId)) { + if (enchantment.level > maxLevel.get(enchId).getAsInt()) { + aboveMaxLevelFromEt = true; + } + } + } + + if (enchanterCurrentEnch == null) { + enchanterCurrentEnch = enchantment; + } else if (updateLevel) { + if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level && !aboveMaxLevelFromEt) { + 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) { + 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("-", "_") + .replaceAll("[^a-z_]", ""); + if (enchId.equalsIgnoreCase("_")) continue; + enchId = ItemUtils.fixEnchantId(enchId, true); + 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<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) { + 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)) { + 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_OF_WAR) { + if (warCount > 0) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.FARMING_DUMMY) { + if (ffdCount < 5) applicableItem.add(item); + else removableItem.add(item); + + } else if (item.itemType == ItemType.RECOMB) { + if (recombCount > 0) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.SILEX) { + if (effLevel >= 5 && effLevel < 10) applicableItem.add(item); + else if (effLevel == 10) removableItem.add(item); + + } else if (item.isPowerScroll()) { + applicableItem.add(item); + + } else if (item.isMasterStar()) { + applicableItem.add(item); + + } else if (item.isDungeonStar()) { + if (starCount >= item.itemType.getStarLevel()) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.WOOD_SINGULARITY) { + if (singularityCount > 0) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.isHypeScroll()) { + if (shadowWarp) removableItem.add(item); + else if (implosion) removableItem.add(item); + else if (witherShield) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.TUNER) { + if (tunerCount >= 4) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.REFORGE) { + if (item.getReforge().equalsIgnoreCase(reforge) && !reforge.equals("")) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.ART_OF_PEACE) { + if (peaceCount > 0) removableItem.add(item); + else applicableItem.add(item); + + } else if (item.itemType == ItemType.MANA_DISINTEGRATOR) { + if (manaDisintegratorCount >= 10) removableItem.add(item); + else applicableItem.add(item); + + } else { + applicableItem.add(item); + } + } else { + applicableItem.add(item); + } + } + } else { + if (playerEnchantIds.containsKey(itemId)) { + searchRemovedFromRemovable = true; + } else { + searchRemovedFromApplicable = true; + } + } + } + } + } + } + } + NEUConfig cfg = NotEnoughUpdates.INSTANCE.config; + int mult = cfg.enchantingSolvers.enchantOrdering == 0 ? 1 : -1; + Comparator<HexItem> comparator = cfg.enchantingSolvers.enchantSorting == 0 ? + Comparator.comparingInt(e -> (int) (mult * e.price)) : + (c1, c2) -> mult * + c1.itemId.toLowerCase().compareTo(c2.itemId.toLowerCase()); + removableItem.sort(comparator); + applicableItem.sort(comparator); + } + } + + private void tickHex() { + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + + ItemStack enchantingItemStack = cc.getLowerChestInventory().getStackInSlot(22); + ItemStack glassStack = cc.getLowerChestInventory().getStackInSlot(12); + //ItemStack anvilStack = cc.getLowerChestInventory().getStackInSlot(28); + + this.lastState = currentState; + + if (enchantingItemStack != null) { + if (glassStack.getItem() != null && glassStack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane)) { + if (glassStack.getItemDamage() == 14) { + currentState = EnchantState.INVALID_ITEM_HEX; + } else if (glassStack.getItemDamage() == 10) { + currentState = EnchantState.HAS_ITEM_IN_HEX; + } else { + currentState = EnchantState.NO_ITEM_IN_HEX; + } + enchantingItem = enchantingItemStack; + } + } else { + currentState = EnchantState.NO_ITEM_IN_HEX; + } + + 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; + applicableItem.clear(); + removableItem.clear(); + boolean hasHexItem = false; + if (currentState == EnchantState.HAS_ITEM_IN_HEX) { + for (int i = 0; i < 9; i++) { + int slotIndex = 15 + (i % 3) + (i / 3) * 9; + ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex); + if (!hasHexItem && glassStack != null) { + HexItem item = new HexItem(slotIndex, "Total Upgrades", "TOTAL_UPGRADES", + Utils.getRawTooltip(glassStack), true, true + ); + removableItem.add(item); + hasHexItem = 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("Ultimate Enchantments")) { + name = "Ult Enchants"; + } + /*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, "HEX_ITEM" + i, + Utils.getRawTooltip(book), true, true + ); + enchanterItemLevels.put(item.level, item); + applicableItem.add(item); + } + } else { + if (playerEnchantIds.containsKey(itemId)) { + searchRemovedFromRemovable = true; + } else { + searchRemovedFromApplicable = true; + } + } + } + } + } + } + } + NEUConfig cfg = NotEnoughUpdates.INSTANCE.config; + int mult = cfg.enchantingSolvers.enchantOrdering == 0 ? 1 : -1; + Comparator<HexItem> comparator = cfg.enchantingSolvers.enchantSorting == 0 ? + Comparator.comparingInt(e -> (int) (mult * e.price)) : + (c1, c2) -> mult * + c1.itemId.toLowerCase().compareTo(c2.itemId.toLowerCase()); + removableItem.sort(comparator); + applicableItem.sort(comparator); + } + } + + private void tickGemstones() { + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + + ItemStack enchantingItemStack = cc.getLowerChestInventory().getStackInSlot(19); + ItemStack portalStack = cc.getLowerChestInventory().getStackInSlot(28); + + int lastPage = currentPage; + this.lastState = currentState; + if (portalStack != null && portalStack.getItem() == Item.getItemFromBlock(Blocks.end_portal_frame) && + currentState != EnchantState.ADDING_GEMSTONE && !shouldOverrideGemstones && + currentState != EnchantState.APPLYING_GEMSTONE) { + currentState = EnchantState.HAS_ITEM_IN_GEMSTONE; + enchantingItem = enchantingItemStack; + } else if (portalStack != null && portalStack.getItem() == Item.getItemFromBlock(Blocks.end_portal_frame) && + shouldOverrideGemstones && currentState != EnchantState.APPLYING_GEMSTONE) { + currentState = EnchantState.ADDING_GEMSTONE; + } else if (currentState == EnchantState.HAS_ITEM_IN_GEMSTONE && enchantingItem == null && + enchantingItemStack != null) { + enchantingItem = enchantingItemStack; + } else if (currentState != EnchantState.APPLYING_GEMSTONE) { + currentState = EnchantState.HAS_ITEM_IN_GEMSTONE; + } + + if (currentState == EnchantState.APPLYING_GEMSTONE || currentState == EnchantState.ADDING_GEMSTONE) { + 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; + } + + if (lastState != currentState || lastPage != currentPage) { + leftScroll.setValue(0); + rightScroll.setValue(0); + } + + if (currentState == EnchantState.APPLYING_GEMSTONE) { + 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; + applicableItem.clear(); + removableItem.clear(); + if (isInGemstones()) { + 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) { + 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 (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.isGemstone()) { + if (book.getItem() == Items.dye) { + item.conflicts = true; + } + boolean removed = false; + for (String lore : item.displayLore) { + if (lore.contains("Click to remove!")) { + removableItem.add(item); + removed = true; + break; + } + } + if (!removed) { + applicableItem.add(item); + } + if (item.itemName.length() > 14) item.itemName = item.itemName.substring(0, 14); + } else { + applicableItem.add(item); + } + } + } else { + if (playerEnchantIds.containsKey(itemId)) { + searchRemovedFromRemovable = true; + } else { + searchRemovedFromApplicable = true; + } + } + } + } + } + } + } + NEUConfig cfg = NotEnoughUpdates.INSTANCE.config; + int mult = cfg.enchantingSolvers.enchantOrdering == 0 ? 1 : -1; + Comparator<HexItem> comparator = cfg.enchantingSolvers.enchantSorting == 0 ? + Comparator.comparingInt(e -> (int) (mult * e.price)) : + (c1, c2) -> mult * + c1.itemId.toLowerCase().compareTo(c2.itemId.toLowerCase()); + removableItem.sort(comparator); + applicableItem.sort(comparator); + } + this.pageOpenLast = this.pageOpen; + } + + 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, String containerName) { + if (containerName == null) return; + if (containerName.equals("The Hex")) { + renderHex(partialTicks); + } else if (containerName.contains("Enchant Item")) { + renderEnchantment(partialTicks); + } else if (containerName.contains("Books") || containerName.contains("Modifiers") || containerName.contains( + "Bottles of Enchanting")) { + renderBooks(partialTicks); + } else if (containerName.contains("Gemstones")) { + renderGemstones(partialTicks); + } else { + renderBooks(partialTicks); + } + } + + private void renderEnchantment(float partialTicks) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; + + 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); + + renderBaseTexture(); + + 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 + ); + } + + tooltipToDisplay = renderSettings(mouseX, mouseY, tooltipToDisplay); + + renderScrollBars(applicable, removable, mouseY); + + //Enchant book model + renderEnchantBook(scaledResolution, partialTicks); + + //Can't be enchanted text + if (currentState == EnchantState.INVALID_ITEM) { + GlStateManager.disableDepth(); + Utils.drawStringCentered("This item can't", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555 + ); + Utils.drawStringCentered("be enchanted", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555 + ); + GlStateManager.enableDepth(); + } + + renderArrow(); + + //Text if no enchants appear + if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT) { + if (applicable.isEmpty() && removable.isEmpty() && searchRemovedFromApplicable) { + Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 + ); + Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 58, true, 0xffff5555 + ); + } else if (applicable.isEmpty() && !searchRemovedFromApplicable) { + Utils.drawStringCentered("No applicable", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 + ); + } + if (applicable.isEmpty() && removable.isEmpty() && searchRemovedFromRemovable) { + Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 + ); + Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 58, true, 0xffff5555 + ); + } else if (removable.isEmpty() && !searchRemovedFromRemovable) { + Utils.drawStringCentered("No removable", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 + ); + } + } + //Available enchants (left) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + + if (applicable.size() <= index) break; + Enchantment ench = applicable.get(index); + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentEnch != null && enchanterCurrentEnch.enchId.equals(ench.enchId) ? 16 : 0; + int uOffset = ench.conflicts ? 112 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 8, top, 96, 16, + uOffset / 512f, (96 + uOffset) / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (ench.displayLore != null) { + tooltipToDisplay = ench.displayLore; + } + } + + String levelStr = "" + ench.xpCost; + int colour = 0xc8ff8f; + if (ench.xpCost > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString( + ench.enchantName, + guiLeft + 8 + 16 + 2 + textOffset, + top + 4 + textOffset, + 0xffffffdd, + true + ); + } + GlScissorStack.pop(scaledResolution); + + //Removable enchants (right) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + rightScroll.getValue() / 16; + + if (removable.size() <= index) break; + Enchantment ench = removable.get(index); + + int top = guiTop - (rightScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentEnch != null && enchanterCurrentEnch.enchId.equals(ench.enchId) ? 16 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 248, top, 96, 16, + 0, 96 / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 248 && mouseX <= guiLeft + 248 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (ench.displayLore != null) { + tooltipToDisplay = ench.displayLore; + } + } + + String levelStr = "" + ench.xpCost; + if (ench.xpCost < 0) levelStr = "?"; + int colour = 0xc8ff8f; + if (ench.xpCost > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString(ench.enchantName, + guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true + ); + } + GlScissorStack.pop(scaledResolution); + + //Player Inventory Items + Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory + .getDisplayName() + .getUnformattedText(), + guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 + ); + int inventoryStartIndex = cc.getLowerChestInventory().getSizeInventory(); + GlStateManager.enableDepth(); + for (int i = 0; i < 36; i++) { + int itemX = guiLeft + 102 + 18 * (i % 9); + int itemY = guiTop + 133 + 18 * (i / 9); + + if (i >= 27) { + itemY += 4; + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(guiLeft + 102 - 8, guiTop + 191 - (inventoryStartIndex / 9 * 18 + 89), 0); + Slot slot = cc.getSlot(inventoryStartIndex + i); + ((AccessorGuiContainer) chest).doDrawSlot(slot); + GlStateManager.popMatrix(); + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + hoverLocked = SlotLocking.getInstance().isSlotLocked(slot); + + if (slot.getHasStack()) { + tooltipToDisplay = slot.getStack().getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + //Search bar + if (currentState == EnchantState.HAS_ITEM) { + if (searchField.getText().isEmpty() && !searchField.getFocus()) { + searchField.setSize(90, 14); + searchField.setPrependText("\u00a77Search..."); + } else { + if (searchField.getFocus()) { + int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(searchField.getTextDisplay()) + 10; + searchField.setSize(Math.max(90, len), 14); + } else { + searchField.setSize(90, 14); + } + searchField.setPrependText(""); + } + searchField.render(guiLeft + X_SIZE / 2 - searchField.getWidth() / 2, guiTop + 83); + } else if (currentState == EnchantState.ADDING_ENCHANT && + enchanterCurrentEnch != null && !enchanterEnchLevels.isEmpty()) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + int uOffset = enchanterCurrentEnch.conflicts ? 112 : 0; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(left, top, 112, 16, + uOffset / 512f, (112 + uOffset) / 512f, 249 / 512f, (249 + 16) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (enchanterCurrentEnch.displayLore != null) { + tooltipToDisplay = enchanterCurrentEnch.displayLore; + } + } + + //Enchant cost + String levelStr = "" + enchanterCurrentEnch.xpCost; + if (enchanterCurrentEnch.xpCost < 0) levelStr = "?"; + + int colour = 0xc8ff8f; + if (enchanterCurrentEnch.xpCost > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); + + String priceStr = "" + numberFormat.format(enchanterCurrentEnch.price) + " Coins"; + if (enchanterCurrentEnch.price < 0) priceStr = ""; + int priceWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(priceStr); + int priceTop = guiTop + 16; + int x = 180; + int color = 0x2d2102; + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2 - 1, + priceTop + 4, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2 + 1, + priceTop + 4, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2, + priceTop + 4 - 1, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2, + priceTop + 4 + 1, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2, + priceTop + 4, + 0xfcba03, + false + ); + + //Enchant name + String name = WordUtils.capitalizeFully(ItemUtils + .fixEnchantId(enchanterCurrentEnch.enchId, false) + .replace("_", " ")); + 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"; + } else if (name.equalsIgnoreCase("Turbo Mushrooms")) { + name = "Turbo-Mush"; + } + Utils.drawStringCentered( + name, + Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, + top + 8, + true, + 0xffffffdd + ); + + if (isChangingEnchLevel) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(left + 96, top, 16, 16, + 96 / 512f, 112 / 512f, 265 / 512f, (265 + 16) / 512f, GL11.GL_NEAREST + ); + } + + //Enchant level + levelStr = "" + enchanterCurrentEnch.level; + if (enchanterCurrentEnch.xpCost < 0) levelStr = "?"; + levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 4, + 0xea82ff, + false + ); + + //Confirm button + + String confirmText = "Apply"; + if (removingEnchantPlayerLevel >= 0) { + if (removingEnchantPlayerLevel == enchanterCurrentEnch.level) { + confirmText = "Remove"; + } else if (enchanterCurrentEnch.level > removingEnchantPlayerLevel) { + confirmText = "Upgrade"; + } else { + confirmText = "Bad Level"; + } + } + if (System.currentTimeMillis() - confirmButtonAnimTime < 500 && !(playerXpLevel < enchanterCurrentEnch.xpCost)) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040 + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040 + ); + + if (playerXpLevel < enchanterCurrentEnch.xpCost) { + Gui.drawRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, guiLeft + X_SIZE / 2 - 1, top + 18 + 14, 0x80000000); + } + } + + //Cancel button + if (System.currentTimeMillis() - cancelButtonAnimTime < 500) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 + ); + } + + if (mouseY > top + 18 && mouseY <= top + 18 + 16) { + if (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1) { + disallowClick = true; + if (enchanterCurrentEnch.displayLore != null) { + tooltipToDisplay = enchanterCurrentEnch.displayLore; + } + } else if (mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48) { + disallowClick = true; + tooltipToDisplay = Lists.newArrayList("\u00a7cCancel"); + } + } + + //Enchant level switcher + if (isChangingEnchLevel) { + tooltipToDisplay = null; + + List<Enchantment> before = new ArrayList<>(); + List<Enchantment> after = new ArrayList<>(); + + for (Enchantment ench : enchanterEnchLevels.values()) { + if (ench.level < enchanterCurrentEnch.level) { + before.add(ench); + } else if (ench.level > enchanterCurrentEnch.level) { + after.add(ench); + } + } + + before.sort(Comparator.comparingInt(o -> -o.level)); + after.sort(Comparator.comparingInt(o -> o.level)); + + int bSize = before.size(); + int aSize = after.size(); + GlStateManager.disableDepth(); + for (int i = 0; i < bSize + aSize; i++) { + Enchantment ench; + int yIndex; + if (i < bSize) { + ench = before.get(i); + yIndex = -i - 1; + } else { + ench = after.get(i - bSize); + yIndex = i - bSize + 1; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + + int type = 0; + if (i == bSize) { + type = 2; + } else if (i == 0) { + type = 1; + } + + if (mouseX > left + 96 && mouseX <= left + 96 + 16 && + mouseY > top + 16 * yIndex && mouseY <= top + 16 * yIndex + 16) { + tooltipToDisplay = new ArrayList<>(ench.displayLore); + if (tooltipToDisplay.size() > 2) { + tooltipToDisplay.remove(tooltipToDisplay.size() - 1); + tooltipToDisplay.remove(tooltipToDisplay.size() - 1); + } + itemHoverX = -1; + itemHoverY = -1; + } + + Utils.drawTexturedRect(left + 96, top + 16 * yIndex, 16, 16, + 16 * type / 512f, (16 + 16 * type) / 512f, 356 / 512f, (356 + 16) / 512f, GL11.GL_NEAREST + ); + + levelStr = "" + ench.level; + levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2 - 1, + top + 16 * yIndex + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2 + 1, + top + 16 * yIndex + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 16 * yIndex + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 16 * yIndex + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 16 * yIndex + 4, + 0xea82ff, + false + ); + } + GlStateManager.enableDepth(); + } + + if (mouseX > left + 96 && mouseX <= left + 96 + 16 && + mouseY > top && mouseY <= top + 16) { + if (isChangingEnchLevel) { + tooltipToDisplay = Lists.newArrayList("\u00a7cCancel level change"); + } else { + tooltipToDisplay = Lists.newArrayList("\u00a7aChange enchant level"); + } + } + } + + if (currentState == EnchantState.HAS_ITEM) { + renderCancel(); + } + + //Item enchant input + ItemStack itemEnchantInput; + if (currentState == EnchantState.HAS_ITEM_IN_HEX) { + itemEnchantInput = cc.getSlot(22).getStack(); + } else { + itemEnchantInput = cc.getSlot(19).getStack(); + } + if (itemEnchantInput != null && itemEnchantInput.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane)) { + itemEnchantInput = enchantingItem; + } + { + int itemX = guiLeft + 174; + int itemY = guiTop + 58; + + if (itemEnchantInput == null) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(itemX, itemY, 16, 16, + 0, 16 / 512f, 281 / 512f, (281 + 16) / 512f, GL11.GL_NEAREST + ); + } else { + Utils.drawItemStack(itemEnchantInput, itemX, itemY); + } + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + + if (itemEnchantInput != null) { + tooltipToDisplay = itemEnchantInput.getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + if (!isChangingEnchLevel && itemHoverX >= 0 && itemHoverY >= 0) { + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + Gui.drawRect(itemHoverX, itemHoverY, itemHoverX + 16, itemHoverY + 16, + hoverLocked ? 0x80ff8080 : 0x80ffffff + ); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableDepth(); + } + + GlStateManager.translate(0, 0, 300); + + renderOrbAnim(partialTicks); + + renderMouseStack(stackOnMouse, disallowClick, mouseX, mouseY, + width, height, tooltipToDisplay + ); + GlStateManager.translate(0, 0, -300); + } + + private void renderBooks(float partialTicks) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; + + 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); + + renderBaseTexture(); + + Minecraft.getMinecraft().fontRendererObj.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); + Minecraft.getMinecraft().fontRendererObj.drawString("Applied", 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 + ); + }*/ + + tooltipToDisplay = renderSettings(mouseX, mouseY, tooltipToDisplay); + + renderScrollBars(applicableItem, applicableItem, mouseY); + + //Enchant book model + renderEnchantBook(scaledResolution, partialTicks); + + //Can't be enchanted text + /*if (currentState == EnchantState.INVALID_ITEM) { + GlStateManager.disableDepth(); + Utils.drawStringCentered("This item can't", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555 + ); + Utils.drawStringCentered("be enchanted", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555 + ); + GlStateManager.enableDepth(); + }*/ + + renderArrow(); + + //Text if no enchants appear + if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT || + currentState == EnchantState.HAS_ITEM_IN_BOOKS || currentState == EnchantState.ADDING_BOOK) { + if (applicableItem.isEmpty() && removableItem.isEmpty() && searchRemovedFromApplicable) { + Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 + ); + Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 58, true, 0xffff5555 + ); + } else if (applicableItem.isEmpty() && !searchRemovedFromApplicable) { + Utils.drawStringCentered("No applicable", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 8 + 48, guiTop + 48, true, 0xffff5555 + ); + } + if (applicableItem.isEmpty() && removableItem.isEmpty() && searchRemovedFromRemovable) { + Utils.drawStringCentered("Can't find that", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchant, perhaps", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("it is on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 + ); + Utils.drawStringCentered("another page?", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 58, true, 0xffff5555 + ); + } else if (removableItem.isEmpty() && !searchRemovedFromRemovable) { + Utils.drawStringCentered("No removable", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 28, true, 0xffff5555 + ); + Utils.drawStringCentered("enchants on", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 38, true, 0xffff5555 + ); + Utils.drawStringCentered("this page...", Minecraft.getMinecraft().fontRendererObj, + guiLeft + 248 + 48, guiTop + 48, true, 0xffff5555 + ); + } + } + //Available enchants (left) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + + if (applicableItem.size() <= index) break; + HexItem item = applicableItem.get(index); + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentItem != null && enchanterCurrentItem.itemId.equals(item.itemId) ? 16 : 0; + int uOffset = item.conflicts ? 112 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 8, top, 96, 16, + uOffset / 512f, (96 + uOffset) / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (item.displayLore != null) { + tooltipToDisplay = item.displayLore; + } + } + + String levelStr = getIconStr(item); + int colour = 0xc8ff8f; + if (item.price > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString( + item.itemName, + guiLeft + 8 + 16 + 2 + textOffset, + top + 4 + textOffset, + 0xffffffdd, + true + ); + } + GlScissorStack.pop(scaledResolution); + + //Removable enchants (right) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + rightScroll.getValue() / 16; + + if (removableItem.size() <= index) break; + HexItem item = removableItem.get(index); + + int top = guiTop - (rightScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentItem != null && enchanterCurrentItem.itemId.equals(item.itemId) ? 16 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 248, top, 96, 16, + 0, 96 / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 248 && mouseX <= guiLeft + 248 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (item.displayLore != null) { + tooltipToDisplay = item.displayLore; + } + } + + String levelStr = getIconStr(item); + int colour = 0xc8ff8f; + /*if (item.price > playerXpLevel) { + colour = 0xff5555; + }*/ + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString(item.itemName, + guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true + ); + } + GlScissorStack.pop(scaledResolution); + + //Player Inventory Items + Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory + .getDisplayName() + .getUnformattedText(), + guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 + ); + int inventoryStartIndex = cc.getLowerChestInventory().getSizeInventory(); + GlStateManager.enableDepth(); + for (int i = 0; i < 36; i++) { + int itemX = guiLeft + 102 + 18 * (i % 9); + int itemY = guiTop + 133 + 18 * (i / 9); + + if (i >= 27) { + itemY += 4; + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(guiLeft + 102 - 8, guiTop + 191 - (inventoryStartIndex / 9 * 18 + 89), 0); + Slot slot = cc.getSlot(inventoryStartIndex + i); + ((AccessorGuiContainer) chest).doDrawSlot(slot); + GlStateManager.popMatrix(); + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + hoverLocked = SlotLocking.getInstance().isSlotLocked(slot); + + if (slot.getHasStack()) { + tooltipToDisplay = slot.getStack().getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + //Search bar + if (currentState == EnchantState.HAS_ITEM) { + if (searchField.getText().isEmpty() && !searchField.getFocus()) { + searchField.setSize(90, 14); + searchField.setPrependText("\u00a77Search..."); + } else { + if (searchField.getFocus()) { + int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(searchField.getTextDisplay()) + 10; + searchField.setSize(Math.max(90, len), 14); + } else { + searchField.setSize(90, 14); + } + searchField.setPrependText(""); + } + searchField.render(guiLeft + X_SIZE / 2 - searchField.getWidth() / 2, guiTop + 83); + } else if (currentState == EnchantState.ADDING_BOOK && + enchanterCurrentItem != null /*&& !enchanterItemLevels.isEmpty()*/) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + int uOffset = enchanterCurrentItem.conflicts ? 112 : 0; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(left, top, 112, 16, + uOffset / 512f, (112 + uOffset) / 512f, 249 / 512f, (249 + 16) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (enchanterCurrentItem.displayLore != null) { + tooltipToDisplay = enchanterCurrentItem.displayLore; + } + } + + String priceStr = "" + numberFormat.format(enchanterCurrentItem.getPrice()) + " Coins"; + if (enchanterCurrentItem.price < 0) priceStr = ""; + int priceWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(priceStr); + int priceTop = guiTop + 10; + int x = 180; + int color = 0x2d2102; + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2 - 1, + priceTop + 4, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2 + 1, + priceTop + 4, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2, + priceTop + 4 - 1, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2, + priceTop + 4 + 1, + color, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + priceStr, + guiLeft + x - priceWidth / 2, + priceTop + 4, + 0xfcba03, + false + ); + + //Enchant name + String name = WordUtils.capitalizeFully(enchanterCurrentItem.itemId.replace("_", " ")); + 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"; + } + Utils.drawStringCentered( + name, + Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, + top + 8, + true, + 0xffffffdd + ); + + //Confirm button + String confirmText = "Apply"; + if (removingEnchantPlayerLevel >= 0) { + if (removingEnchantPlayerLevel == enchanterCurrentItem.level) { + confirmText = "Remove"; + } else if (enchanterCurrentItem.level > removingEnchantPlayerLevel) { + confirmText = "Upgrade"; + } else { + confirmText = "Bad Level"; + } + } + if (System.currentTimeMillis() - confirmButtonAnimTime < 500 && !(playerXpLevel < enchanterCurrentItem.price)) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040 + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040 + ); + + /*if (playerXpLevel < enchanterCurrentItem.price) { + Gui.drawRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, guiLeft + X_SIZE / 2 - 1, top + 18 + 14, 0x80000000); + }*/ + } + + //Cancel button + if (System.currentTimeMillis() - cancelButtonAnimTime < 500) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 + ); + } + + if (mouseY > top + 18 && mouseY <= top + 18 + 16) { + if (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1) { + disallowClick = true; + if (enchanterCurrentItem.displayLore != null) { + tooltipToDisplay = enchanterCurrentItem.displayLore; + } + } else if (mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48) { + disallowClick = true; + tooltipToDisplay = Lists.newArrayList("\u00a7cCancel"); + } + } + } + + if (currentState == EnchantState.HAS_ITEM_IN_BOOKS || currentState == EnchantState.ADDING_BOOK) { + renderCancel(); + } + + //Item enchant input + ItemStack itemEnchantInput; + if (currentState == EnchantState.HAS_ITEM_IN_HEX) { + itemEnchantInput = cc.getSlot(22).getStack(); + } else { + itemEnchantInput = cc.getSlot(19).getStack(); + } + if (itemEnchantInput != null && itemEnchantInput.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane)) { + itemEnchantInput = enchantingItem; + } + { + int itemX = guiLeft + 174; + int itemY = guiTop + 58; + + if (itemEnchantInput == null) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(itemX, itemY, 16, 16, + 0, 16 / 512f, 281 / 512f, (281 + 16) / 512f, GL11.GL_NEAREST + ); + } else { + Utils.drawItemStack(itemEnchantInput, itemX, itemY); + } + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + + if (itemEnchantInput != null) { + tooltipToDisplay = itemEnchantInput.getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + if (!isChangingEnchLevel && itemHoverX >= 0 && itemHoverY >= 0) { + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + Gui.drawRect(itemHoverX, itemHoverY, itemHoverX + 16, itemHoverY + 16, + hoverLocked ? 0x80ff8080 : 0x80ffffff + ); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableDepth(); + } + + GlStateManager.translate(0, 0, 300); + + renderOrbAnim(partialTicks); + + renderMouseStack(stackOnMouse, disallowClick, mouseX, mouseY, + width, height, tooltipToDisplay + ); + GlStateManager.translate(0, 0, -300); + } + + private void renderHex(float partialTicks) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; + + 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); + + renderBaseTexture(); + + Minecraft.getMinecraft().fontRendererObj.drawString("The Hex", guiLeft + 7, guiTop + 7, 0x404040, false); + //Minecraft.getMinecraft().fontRendererObj.drawString("Applied", guiLeft + 247, guiTop + 7, 0x404040, false); + + tooltipToDisplay = renderSettings(mouseX, mouseY, tooltipToDisplay); + + renderScrollBars(applicableItem, applicableItem, mouseY); + + //Enchant book model + renderEnchantBook(scaledResolution, partialTicks); + + //Can't be enchanted text + if (currentState == EnchantState.INVALID_ITEM_HEX) { + GlStateManager.disableDepth(); + Utils.drawStringCentered("This item can't", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, guiTop + 88, true, 0xffff5555 + ); + Utils.drawStringCentered("be enchanted", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, guiTop + 98, true, 0xffff5555 + ); + GlStateManager.enableDepth(); + } + + renderArrow(); + + //Available enchants (left) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + + if (applicableItem.size() <= index) break; + HexItem item = applicableItem.get(index); + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentItem != null && enchanterCurrentItem.itemId.equals(item.itemId) ? 16 : 0; + int uOffset = item.conflicts ? 112 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 8, top, 96, 16, + uOffset / 512f, (96 + uOffset) / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (item.displayLore != null) { + tooltipToDisplay = item.displayLore; + } + } + + String levelStr = getIconStr(item); + int colour = 0xc8ff8f; + if (item.price > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString( + item.itemName, + guiLeft + 8 + 16 + 2 + textOffset, + top + 4 + textOffset, + 0xffffffdd, + true + ); + } + GlScissorStack.pop(scaledResolution); + + //Removable enchants (right) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + rightScroll.getValue() / 16; + + if (removableItem.size() <= index) break; + HexItem item = removableItem.get(index); + + int top = guiTop - (rightScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentItem != null && enchanterCurrentItem.itemId.equals(item.itemId) ? 16 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 248, top, 96, 16, + 0, 96 / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 248 && mouseX <= guiLeft + 248 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (item.displayLore != null) { + tooltipToDisplay = item.displayLore; + } + } + + String levelStr = getIconStr(item); + int colour = 0xc8ff8f; + if (item.price > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString(item.itemName, + guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true + ); + } + GlScissorStack.pop(scaledResolution); + + //Player Inventory Items + Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory + .getDisplayName() + .getUnformattedText(), + guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 + ); + int inventoryStartIndex = cc.getLowerChestInventory().getSizeInventory(); + GlStateManager.enableDepth(); + for (int i = 0; i < 36; i++) { + int itemX = guiLeft + 102 + 18 * (i % 9); + int itemY = guiTop + 133 + 18 * (i / 9); + + if (i >= 27) { + itemY += 4; + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(guiLeft + 102 - 8, guiTop + 191 - (inventoryStartIndex / 9 * 18 + 89), 0); + Slot slot = cc.getSlot(inventoryStartIndex + i); + ((AccessorGuiContainer) chest).doDrawSlot(slot); + GlStateManager.popMatrix(); + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + hoverLocked = SlotLocking.getInstance().isSlotLocked(slot); + + if (slot.getHasStack()) { + tooltipToDisplay = slot.getStack().getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + if (currentState == EnchantState.ADDING_BOOK && + enchanterCurrentItem != null /*&& !enchanterItemLevels.isEmpty()*/) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + int uOffset = enchanterCurrentItem.conflicts ? 112 : 0; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(left, top, 112, 16, + uOffset / 512f, (112 + uOffset) / 512f, 249 / 512f, (249 + 16) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (enchanterCurrentItem.displayLore != null) { + tooltipToDisplay = enchanterCurrentItem.displayLore; + } + } + + if (mouseY > top + 18 && mouseY <= top + 18 + 16) { + if (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1) { + disallowClick = true; + if (enchanterCurrentItem.displayLore != null) { + tooltipToDisplay = enchanterCurrentItem.displayLore; + } + } else if (mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48) { + disallowClick = true; + tooltipToDisplay = Lists.newArrayList("\u00a7cCancel"); + } + } + } + + if (currentState == EnchantState.HAS_ITEM_IN_BOOKS || currentState == EnchantState.ADDING_BOOK) { + renderCancel(); + } + + //Item enchant input + ItemStack itemEnchantInput; + if (isInHex()) { + itemEnchantInput = cc.getSlot(22).getStack(); + } else { + itemEnchantInput = cc.getSlot(19).getStack(); + } + if (itemEnchantInput != null && itemEnchantInput.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane)) { + itemEnchantInput = enchantingItem; + } + { + int itemX = guiLeft + 174; + int itemY = guiTop + 58; + + if (itemEnchantInput == null) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(itemX, itemY, 16, 16, + 0, 16 / 512f, 281 / 512f, (281 + 16) / 512f, GL11.GL_NEAREST + ); + } else { + Utils.drawItemStack(itemEnchantInput, itemX, itemY); + } + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + + if (itemEnchantInput != null) { + tooltipToDisplay = itemEnchantInput.getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + if (!isChangingEnchLevel && itemHoverX >= 0 && itemHoverY >= 0) { + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + Gui.drawRect(itemHoverX, itemHoverY, itemHoverX + 16, itemHoverY + 16, + hoverLocked ? 0x80ff8080 : 0x80ffffff + ); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableDepth(); + } + + GlStateManager.translate(0, 0, 300); + + renderOrbAnim(partialTicks); + + renderMouseStack(stackOnMouse, disallowClick, mouseX, mouseY, + width, height, tooltipToDisplay + ); + GlStateManager.translate(0, 0, -300); + } + + private void renderGemstones(float partialTicks) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; + + 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); + + renderBaseTexture(); + + Minecraft.getMinecraft().fontRendererObj.drawString("Applicable", guiLeft + 7, guiTop + 7, 0x404040, false); + Minecraft.getMinecraft().fontRendererObj.drawString("Applied", guiLeft + 247, guiTop + 7, 0x404040, false); + + //Page Text + if (currentState == EnchantState.ADDING_GEMSTONE || currentState == EnchantState.APPLYING_GEMSTONE) { + 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 + ); + } + + //Confirm button + { + int top = guiTop + 83; + if (currentState == EnchantState.APPLYING_GEMSTONE) { + String confirmText = "Apply"; + if (removingEnchantPlayerLevel >= 0) { + if (removingEnchantPlayerLevel == enchanterCurrentItem.level) { + confirmText = "Remove"; + } else if (enchanterCurrentItem.level > removingEnchantPlayerLevel) { + confirmText = "Upgrade"; + } else { + confirmText = "Bad Level"; + } + } + if (System.currentTimeMillis() - confirmButtonAnimTime < 500) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 - 1 - 23, top + 18 + 9, false, 0x408040 + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered(confirmText, Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 - 1 - 24, top + 18 + 8, false, 0x408040 + ); + } + } + + //Cancel button + + if (System.currentTimeMillis() - cancelButtonAnimTime < 500) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 + ); + } + } + + tooltipToDisplay = renderSettings(mouseX, mouseY, tooltipToDisplay); + + renderScrollBars(applicableItem, applicableItem, mouseY); + + //Enchant book model + renderEnchantBook(scaledResolution, partialTicks); + + renderArrow(); + + //Available enchants (left) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + + if (applicableItem.size() <= index) break; + HexItem item = applicableItem.get(index); + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentItem != null && enchanterCurrentItem.itemId.equals(item.itemId) ? 16 : 0; + int uOffset = item.conflicts ? 112 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 8, top, 96, 16, + uOffset / 512f, (96 + uOffset) / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (item.displayLore != null) { + tooltipToDisplay = item.displayLore; + } + } + + String levelStr = getIconStr(item); + int colour = 0xc8ff8f; + if (item.price > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 16 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString( + item.itemName, + guiLeft + 8 + 16 + 2 + textOffset, + top + 4 + textOffset, + 0xffffffdd, + true + ); + } + GlScissorStack.pop(scaledResolution); + + //Removable enchants (right) + GlScissorStack.push(0, guiTop + 18, width, guiTop + 18 + 96, scaledResolution); + for (int i = 0; i < 7; i++) { + int index = i + rightScroll.getValue() / 16; + + if (removableItem.size() <= index) break; + HexItem item = removableItem.get(index); + + int top = guiTop - (rightScroll.getValue() % 16) + 18 + 16 * i; + int vOffset = enchanterCurrentItem != null && enchanterCurrentItem.itemId.equals(item.itemId) ? 16 : 0; + int textOffset = vOffset / 16; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 248, top, 96, 16, + 0, 96 / 512f, (249 + vOffset) / 512f, (249 + 16 + vOffset) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > guiLeft + 248 && mouseX <= guiLeft + 248 + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (item.displayLore != null) { + tooltipToDisplay = item.displayLore; + } + } + + String levelStr = getIconStr(item); + int colour = 0xc8ff8f; + if (item.price > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + guiLeft + 256 - levelWidth / 2, + top + 4, + colour, + false + ); + + Minecraft.getMinecraft().fontRendererObj.drawString(item.itemName, + guiLeft + 248 + 16 + 2 + textOffset, top + 4 + textOffset, 0xffffffdd, true + ); + } + GlScissorStack.pop(scaledResolution); + + //Player Inventory Items + Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.inventory + .getDisplayName() + .getUnformattedText(), + guiLeft + 102, guiTop + Y_SIZE - 96 + 2, 0x404040 + ); + int inventoryStartIndex = cc.getLowerChestInventory().getSizeInventory(); + GlStateManager.enableDepth(); + for (int i = 0; i < 36; i++) { + int itemX = guiLeft + 102 + 18 * (i % 9); + int itemY = guiTop + 133 + 18 * (i / 9); + + if (i >= 27) { + itemY += 4; + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(guiLeft + 102 - 8, guiTop + 191 - (inventoryStartIndex / 9 * 18 + 89), 0); + Slot slot = cc.getSlot(inventoryStartIndex + i); + ((AccessorGuiContainer) chest).doDrawSlot(slot); + GlStateManager.popMatrix(); + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + hoverLocked = SlotLocking.getInstance().isSlotLocked(slot); + + if (slot.getHasStack()) { + tooltipToDisplay = slot.getStack().getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + if (currentState == EnchantState.APPLYING_GEMSTONE && + enchanterCurrentItem != null /*&& !enchanterItemLevels.isEmpty()*/) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + int uOffset = enchanterCurrentItem.conflicts ? 112 : 0; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(left, top, 112, 16, + uOffset / 512f, (112 + uOffset) / 512f, 249 / 512f, (249 + 16) / 512f, GL11.GL_NEAREST + ); + + if (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) { + disallowClick = true; + if (enchanterCurrentItem.displayLore != null) { + tooltipToDisplay = enchanterCurrentItem.displayLore; + } + } + + if (mouseY > top + 18 && mouseY <= top + 18 + 16) { + if (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1) { + disallowClick = true; + if (enchanterCurrentItem.displayLore != null) { + tooltipToDisplay = enchanterCurrentItem.displayLore; + } + } else if (mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48) { + disallowClick = true; + tooltipToDisplay = Lists.newArrayList("\u00a7cCancel"); + } + } + } + + if (currentState == EnchantState.HAS_ITEM_IN_BOOKS || currentState == EnchantState.ADDING_BOOK) { + renderCancel(); + } + + //Item enchant input + ItemStack itemEnchantInput; + if (isInHex()) { + itemEnchantInput = cc.getSlot(22).getStack(); + } else { + itemEnchantInput = cc.getSlot(19).getStack(); + } + if (itemEnchantInput != null && itemEnchantInput.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane)) { + itemEnchantInput = enchantingItem; + } + { + int itemX = guiLeft + 174; + int itemY = guiTop + 58; + + if (itemEnchantInput == null) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(itemX, itemY, 16, 16, + 0, 16 / 512f, 281 / 512f, (281 + 16) / 512f, GL11.GL_NEAREST + ); + } else { + Utils.drawItemStack(itemEnchantInput, itemX, itemY); + } + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + itemHoverX = itemX; + itemHoverY = itemY; + + if (itemEnchantInput != null) { + tooltipToDisplay = itemEnchantInput.getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); + } + } + } + + if (currentState == EnchantState.APPLYING_GEMSTONE) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + //Enchant cost + String levelStr = getIconStr(enchanterCurrentItem); + + int colour = 0xc8ff8f; + if (enchanterCurrentItem.price > playerXpLevel) { + colour = 0xff5555; + } + + int levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 8 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false); + + //Enchant name + String name = WordUtils.capitalizeFully(enchanterCurrentItem.itemName); + 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"; + } else if (name.equalsIgnoreCase("Turbo Mushrooms")) { + name = "Turbo-Mush"; + } + Utils.drawStringCentered( + name, + Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2, + top + 8, + true, + 0xffffffdd + ); + + if (isChangingEnchLevel) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(left + 96, top, 16, 16, + 96 / 512f, 112 / 512f, 265 / 512f, (265 + 16) / 512f, GL11.GL_NEAREST + ); + } + + //Enchant level + levelStr = ""; + levelWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(levelStr); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2 - 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2 + 1, + top + 4, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 4 - 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 4 + 1, + 0x2d2102, + false + ); + Minecraft.getMinecraft().fontRendererObj.drawString( + levelStr, + left + 96 + 8 - levelWidth / 2, + top + 4, + 0xea82ff, + false + ); + } + + if (!isChangingEnchLevel && itemHoverX >= 0 && itemHoverY >= 0) { + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + Gui.drawRect(itemHoverX, itemHoverY, itemHoverX + 16, itemHoverY + 16, + hoverLocked ? 0x80ff8080 : 0x80ffffff + ); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableDepth(); + } + + GlStateManager.translate(0, 0, 300); + + renderOrbAnim(partialTicks); + + renderMouseStack(stackOnMouse, disallowClick, mouseX, mouseY, + width, height, tooltipToDisplay + ); + GlStateManager.translate(0, 0, -300); + } + + private String getIconStr(HexItem item) { + String levelStr = ""; + 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 manaDisintegratorCount = 0; + int peaceCount = 0; + int dungeonItem = 0; + boolean shadowWarp = false; + boolean witherShield = false; + boolean implosion = false; + String reforge = ""; + if (enchantingItem != null) { + NBTTagCompound tagItem = enchantingItem.getTagCompound(); + if (tagItem != null) { + NBTTagCompound ea = tagItem.getCompoundTag("ExtraAttributes"); + if (ea != null) { + potatoCount = ea.getInteger("hot_potato_count"); + killCount = ea.getInteger("stats_book"); + warCount = ea.getInteger("art_of_war_count"); + ffdCount = ea.getInteger("farming_for_dummies_count"); + recombCount = ea.getInteger("rarity_upgrades"); + starCount = ea.getInteger("upgrade_level"); + singularityCount = ea.getInteger("wood_singularity_count"); + tunerCount = ea.getInteger("tuned_transmission"); + peaceCount = ea.getInteger("art_of_peace_count"); + manaDisintegratorCount = ea.getInteger("mana_disintegrator_count"); + dungeonItem = ea.getInteger("dungeon_item"); + reforge = ea.getString("modifier"); + NBTTagCompound enchs = ea.getCompoundTag("enchantments"); + NBTTagList scrolls = ea.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.itemType == ItemType.HOT_POTATO) { + if (potatoCount < 10) levelStr = "" + potatoCount; + else levelStr = "✔"; + + } else if (item.itemType == ItemType.FUMING_POTATO) { + if (potatoCount <= 10) levelStr = "" + 0; + else if (potatoCount < 15) levelStr = "" + (potatoCount - 10); + else levelStr = "✔"; + + } else if (item.itemType == ItemType.BOOK_OF_STATS) { + if (killCount > 0) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.ART_OF_WAR) { + if (warCount > 0) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.FARMING_DUMMY) { + if (ffdCount < 5) levelStr = "" + ffdCount; + else levelStr = "✔"; + + } else if (item.itemType == ItemType.RECOMB) { + if (recombCount > 0) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.SILEX) { + if (effLevel < 10) levelStr = "✖"; + else levelStr = "✔"; + + } else if (item.isPowerScroll()) { + levelStr = "✖"; + + } else if (item.isMasterStar()) { + levelStr = "✖"; + + } else if (item.isDungeonStar()) { + if (starCount >= item.itemType.getStarLevel()) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.WOOD_SINGULARITY) { + if (singularityCount > 0) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.isHypeScroll()) { + if (shadowWarp) levelStr = "✔"; + else if (implosion) levelStr = "✔"; + else if (witherShield) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.TUNER) { + if (tunerCount >= 4) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.REFORGE) { + if (item.getReforge().equalsIgnoreCase(reforge)) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.RANDOM_REFORGE) { + levelStr = "?"; + + } else if (item.itemType == ItemType.ART_OF_PEACE) { + if (peaceCount > 0) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.MANA_DISINTEGRATOR) { + if (manaDisintegratorCount >= 10) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.CONVERT_TO_DUNGEON) { + if (dungeonItem > 0) levelStr = "✔"; + else levelStr = "✖"; + + } else if (item.itemType == ItemType.RUBY_GEMSTONE) { + levelStr = "❤"; + + } else if (item.itemType == ItemType.AMETHYST_GEMSTONE) { + levelStr = "❈"; + + } else if (item.itemType == ItemType.SAPPHIRE_GEMSTONE) { + levelStr = "✎"; + + } else if (item.itemType == ItemType.JADE_GEMSTONE) { + levelStr = "☘"; + + } else if (item.itemType == ItemType.AMBER_GEMSTONE) { + levelStr = "⸕"; + + } else if (item.itemType == ItemType.TOPAZ_GEMSTONE) { + levelStr = "✧"; + + } else if (item.itemType == ItemType.JASPER_GEMSTONE) { + levelStr = "❁"; + + } else if (item.itemType == ItemType.OPAL_GEMSTONE) { + levelStr = "❂"; + } + } else { + levelStr = "?"; + } + return levelStr; + } + + private void renderBaseTexture() { + //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 + ); + } + + private List<String> renderSettings(int mouseX, int mouseY, List<String> tooltipToDisplay) { + //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 + ); + //Sorting Settings Button + float sortingMinU = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantSorting * 16 / 512f; + Utils.drawTexturedRect(guiLeft + 295, guiTop + 147 + 18, 16, 16, + sortingMinU, sortingMinU + 16 / 512f, 419 / 512f, (419 + 16) / 512f, GL11.GL_NEAREST + ); + //Ordering Settings Button + float orderingMinU = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantOrdering * 16 / 512f; + Utils.drawTexturedRect(guiLeft + 295 + 18, guiTop + 147 + 18, 16, 16, + orderingMinU, orderingMinU + 16 / 512f, 435 / 512f, (435 + 16) / 512f, GL11.GL_NEAREST + ); + + if (mouseX >= guiLeft + 294 && mouseX < guiLeft + 294 + 36 && + mouseY >= guiTop + 146 && mouseY < guiTop + 146 + 36) { + int index = (mouseX - (guiLeft + 295)) / 18 + (mouseY - (guiTop + 147)) / 18 * 2; + switch (index) { + case 0: + Gui.drawRect(guiLeft + 295, guiTop + 147, guiLeft + 295 + 16, guiTop + 147 + 16, 0x80ffffff); + tooltipToDisplay = createTooltip("Enable GUI", 0, "On", "Off"); + break; + case 1: + Gui.drawRect(guiLeft + 295 + 18, guiTop + 147, guiLeft + 295 + 16 + 18, guiTop + 147 + 16, 0x80ffffff); + tooltipToDisplay = createTooltip("Max Level", + (NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel ? 0 : 1), + "Enabled", "Disabled"); + tooltipToDisplay.add(1, EnumChatFormatting.GRAY + "Show max level of enchant"); + tooltipToDisplay.add(2, EnumChatFormatting.GRAY + "from either hex or enchantment table"); + tooltipToDisplay.add(3, EnumChatFormatting.GRAY + "max level"); + break; + case 2: + Gui.drawRect(guiLeft + 295, guiTop + 147 + 18, guiLeft + 295 + 16, guiTop + 147 + 16 + 18, 0x80ffffff); + tooltipToDisplay = createTooltip("Sort enchants...", + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantSorting, + "By Cost", "Alphabetically" + ); + break; + case 3: + Gui.drawRect( + guiLeft + 295 + 18, + guiTop + 147 + 18, + guiLeft + 295 + 16 + 18, + guiTop + 147 + 16 + 18, + 0x80ffffff + ); + tooltipToDisplay = createTooltip("Order enchants...", + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantOrdering, + "Ascending", "Descending" + ); + break; + } + } + return tooltipToDisplay; + } + + private void renderScrollBars(List applicable, List removable, int mouseY) { + //Left scroll bar + { + int offset; + if (applicable.size() <= 6) { + offset = 0; + } else if (isScrollingLeft && clickedScrollOffset >= 0) { + offset = mouseY - clickedScrollOffset; + if (offset < 0) offset = 0; + if (offset > 96 - 15) offset = 96 - 15; + } else { + offset = Math.round((96 - 15) * (leftScroll.getValue() / (float) ((applicable.size() - 6) * 16))); + } + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 104, guiTop + 18 + offset, 12, 15, + 0, 12 / 512f, 313 / 512f, (313 + 15) / 512f, GL11.GL_NEAREST + ); + } + //Right scroll bar + { + int offset; + if (removable.size() <= 6) { + offset = 0; + } else if (!isScrollingLeft && clickedScrollOffset >= 0) { + offset = mouseY - clickedScrollOffset; + if (offset < 0) offset = 0; + if (offset > 96 - 15) offset = 96 - 15; + } else { + offset = Math.round((96 - 15) * (rightScroll.getValue() / (float) ((removable.size() - 6) * 16))); + } + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + 344, guiTop + 18 + offset, 12, 15, + 0, 12 / 512f, 313 / 512f, (313 + 15) / 512f, GL11.GL_NEAREST + ); + } + } + + private void renderArrow() { + //Enchant arrow + if (arrowAmount.getValue() > 0) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + float w = 22 * arrowAmount.getValue(); + if (removingEnchantPlayerLevel < 0) { + Utils.drawTexturedRect(guiLeft + 134, guiTop + 58, w, 16, + 0, w / 512f, 297 / 512f, (297 + 16) / 512f, GL11.GL_NEAREST + ); + } else { + Utils.drawTexturedRect(guiLeft + 230 - w, guiTop + 58, w, 16, + (44 - w) / 512f, 44 / 512f, 297 / 512f, (297 + 16) / 512f, GL11.GL_NEAREST + ); + } + } + } + + private void renderCancel() { + int top = guiTop + 83; + //Cancel button + if (System.currentTimeMillis() - cancelButtonAnimTime < 500) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 342 / 512f, (342 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 25, top + 18 + 9, false, 0xa04040 + ); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawStringCentered("Cancel", Minecraft.getMinecraft().fontRendererObj, + guiLeft + X_SIZE / 2 + 1 + 24, top + 18 + 8, false, 0xa04040 + ); + } + } + + private void renderOrbAnim(float partialTicks) { + //Orb animation + GlStateManager.pushMatrix(); + GlStateManager.translate(guiLeft, guiTop, 0); + orbDisplay.renderOrbs(partialTicks); + GlStateManager.popMatrix(); + } + + private void renderMouseStack( + ItemStack stackOnMouse, boolean disallowClick, + int mouseX, int mouseY, int width, int height, + List<String> tooltipToDisplay + ) { + if (stackOnMouse != null) { + if (disallowClick) { + Utils.drawItemStack(new ItemStack(Item.getItemFromBlock(Blocks.barrier)), mouseX - 8, mouseY - 8); + } else { + Utils.drawItemStack(stackOnMouse, mouseX - 8, mouseY - 8); + } + } else if (tooltipToDisplay != null) { + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, + Minecraft.getMinecraft().fontRendererObj + ); + } + } + + private void renderEnchantBook(ScaledResolution scaledresolution, float partialTicks) { + GlStateManager.enableDepth(); + + GlStateManager.pushMatrix(); + GlStateManager.matrixMode(5889); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); + GlStateManager.viewport((scaledresolution.getScaledWidth() - 320) / 2 * scaledresolution.getScaleFactor(), + (scaledresolution.getScaledHeight() - 240) / 2 * scaledresolution.getScaleFactor(), + 320 * scaledresolution.getScaleFactor(), 240 * scaledresolution.getScaleFactor() + ); + GlStateManager.translate(0.0F, 0.33F, 0.0F); + Project.gluPerspective(90.0F, 1.3333334F, 9.0F, 80.0F); + GlStateManager.matrixMode(5888); + GlStateManager.loadIdentity(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.translate(0.0F, 3.3F, -16.0F); + GlStateManager.scale(5, 5, 5); + GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(ENCHANTMENT_TABLE_BOOK_TEXTURE); + GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F); + float bookOpenAngle = this.bookOpenLast + (this.bookOpen - this.bookOpenLast) * partialTicks; + GlStateManager.translate( + (1.0F - bookOpenAngle) * 0.2F, + (1.0F - bookOpenAngle) * 0.1F, + (1.0F - bookOpenAngle) * 0.25F + ); + GlStateManager.rotate(-(1.0F - bookOpenAngle) * 90.0F - 90.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F); + float pageAngle1 = this.pageOpenLast + (this.pageOpen - this.pageOpenLast) * partialTicks + 0.25F; + float pageAngle2 = this.pageOpenLast + (this.pageOpen - this.pageOpenLast) * partialTicks + 0.75F; + pageAngle1 = (pageAngle1 - (float) MathHelper.truncateDoubleToInt(pageAngle1)) * 1.6F - 0.3F; + pageAngle2 = (pageAngle2 - (float) MathHelper.truncateDoubleToInt(pageAngle2)) * 1.6F - 0.3F; + + if (pageAngle1 < 0.0F) pageAngle1 = 0.0F; + if (pageAngle1 > 1.0F) pageAngle1 = 1.0F; + if (pageAngle2 < 0.0F) pageAngle2 = 0.0F; + if (pageAngle2 > 1.0F) pageAngle2 = 1.0F; + + GlStateManager.enableRescaleNormal(); + MODEL_BOOK.render(null, 0.0F, pageAngle1, pageAngle2, bookOpenAngle, 0.0F, 0.0625F); + GlStateManager.disableRescaleNormal(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.matrixMode(5889); + GlStateManager.viewport(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); + GlStateManager.popMatrix(); + GlStateManager.matrixMode(5888); + GlStateManager.popMatrix(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + + GlStateManager.enableDepth(); + } + + private boolean isInEnchanting() { + return currentState == EnchantState.ADDING_ENCHANT || currentState == EnchantState.HAS_ITEM || + currentState == EnchantState.SWITCHING_DONT_UPDATE; + } + + private boolean isInHex() { + return currentState == EnchantState.HAS_ITEM_IN_HEX || currentState == EnchantState.INVALID_ITEM_HEX || + currentState == EnchantState.NO_ITEM_IN_HEX; + } + + private boolean isInGemstones() { + return currentState == EnchantState.HAS_ITEM_IN_GEMSTONE || currentState == EnchantState.ADDING_GEMSTONE || + currentState == EnchantState.APPLYING_GEMSTONE; + } + + public void overrideIsMouseOverSlot(Slot slot, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> cir) { + if ((shouldOverrideFast || shouldOverrideGemstones || shouldOverrideXp) && + currentState != EnchantState.ADDING_ENCHANT) { + boolean playerInv = slot.inventory == Minecraft.getMinecraft().thePlayer.inventory; + int slotId = slot.getSlotIndex(); + if (playerInv && slotId < 36) { + slotId -= 9; + if (slotId < 0) slotId += 36; + + int itemX = guiLeft + 102 + 18 * (slotId % 9); + int itemY = guiTop + 133 + 18 * (slotId / 9); + + if (slotId >= 27) { + itemY += 4; + } + + if (mouseX >= itemX && mouseX < itemX + 18 && + mouseY >= itemY && mouseY < itemY + 18) { + cir.setReturnValue(true); + } else { + cir.setReturnValue(false); + } + } else if ((slotId == 19 && !isInHex()) || (slotId == 22 && isInHex())) { + cir.setReturnValue(mouseX >= guiLeft + 173 && mouseX < guiLeft + 173 + 18 && + mouseY >= guiTop + 57 && mouseY < guiTop + 57 + 18); + } + } + } + + public boolean mouseInput(int mouseX, int mouseY) { + if (Mouse.getEventButtonState() && + (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.ADDING_ENCHANT || + currentState == EnchantState.HAS_ITEM_IN_HEX || currentState == EnchantState.ADDING_BOOK || + currentState == EnchantState.ADDING_GEMSTONE || currentState == EnchantState.APPLYING_GEMSTONE)) { + if (mouseY > guiTop + 6 && mouseY < guiTop + 6 + 15) { + String pageStr = "Page: " + currentPage + "/" + expectedMaxPage; + int pageStrLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(pageStr); + + int click = -1; + if (mouseX > guiLeft + X_SIZE / 2 - pageStrLen / 2 - 2 - 15 && + mouseX <= guiLeft + X_SIZE / 2 - pageStrLen / 2 - 2) { + click = 17; + } else if (mouseX > guiLeft + X_SIZE / 2 + pageStrLen / 2 + 2 && + mouseX <= guiLeft + X_SIZE / 2 + pageStrLen / 2 + 2 + 15) { + click = 35; + } + + if (click >= 0) { + if (currentState == EnchantState.ADDING_ENCHANT || currentState == EnchantState.ADDING_BOOK) { + if (Mouse.getEventButtonState()) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + } + } else { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(click); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, click, 0, 0, stack, transactionID)); + } + return true; + } + } + } + + // Cancel button + if (currentState == EnchantState.HAS_ITEM || + currentState == EnchantState.HAS_ITEM_IN_BOOKS || currentState == EnchantState.HAS_ITEM_IN_GEMSTONE) { + if (Mouse.getEventButtonState()) { + int top = guiTop + 83; + + if (!isChangingEnchLevel && mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48 && + mouseY > top + 18 && mouseY <= top + 18 + 14) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + leftScroll.setValue(0); + rightScroll.setValue(0); + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState != EnchantState.ADDING_BOOK) { + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + if (isInGemstones()) { + currentState = EnchantState.HAS_ITEM_IN_GEMSTONE; + } + } else { + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + } + searchField.setText(""); + cancelButtonAnimTime = System.currentTimeMillis(); + enchanterCurrentItem = null; + } + + if (mouseX > guiLeft + X_SIZE / 2 - searchField.getWidth() / 2 && + mouseX < guiLeft + X_SIZE / 2 + searchField.getWidth() / 2 && + mouseY > guiTop + 80 && mouseY < guiTop + 96) { + searchField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + } else { + searchField.setFocus(false); + } + } else if (Mouse.getEventButton() < 0 && searchField.getFocus() && Mouse.isButtonDown(0)) { + searchField.mouseClickMove(mouseX, mouseY, 0, 0); + } + } else if (currentState == EnchantState.ADDING_ENCHANT && !enchanterEnchLevels.isEmpty()) { + if (Mouse.getEventButtonState()) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + + if (!isChangingEnchLevel && mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48 && + mouseY > top + 18 && mouseY <= top + 18 + 14) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + } else if (!isChangingEnchLevel && enchanterCurrentEnch != null && + (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) || + (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1 && + mouseY > top + 18 && mouseY <= top + 18 + 14)) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot( + enchanterCurrentEnch.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + enchanterCurrentEnch.slotIndex, 0, 0, stack, transactionID + )); + + int playerXpLevel = Minecraft.getMinecraft().thePlayer.experienceLevel; + if (playerXpLevel >= enchanterCurrentEnch.xpCost) { + if (removingEnchantPlayerLevel >= 0 && enchanterCurrentEnch.level == removingEnchantPlayerLevel) { + orbDisplay.spawnExperienceOrbs(X_SIZE / 2, 66, X_SIZE / 2, 36, 3); + } else { + orbDisplay.spawnExperienceOrbs(mouseX - guiLeft, mouseY - guiTop, X_SIZE / 2, 66, 0); + } + } + + confirmButtonAnimTime = System.currentTimeMillis(); + } else if (mouseX > left + 96 && mouseX <= left + 96 + 16) { + if (!isChangingEnchLevel) { + if (mouseY > top && mouseY < top + 16) { + isChangingEnchLevel = true; + return true; + } + } else { + List<Enchantment> before = new ArrayList<>(); + List<Enchantment> after = new ArrayList<>(); + + for (Enchantment ench : enchanterEnchLevels.values()) { + if (ench.level < enchanterCurrentEnch.level) { + before.add(ench); + } else if (ench.level > enchanterCurrentEnch.level) { + after.add(ench); + } + } + + before.sort(Comparator.comparingInt(o -> -o.level)); + after.sort(Comparator.comparingInt(o -> o.level)); + + int bSize = before.size(); + int aSize = after.size(); + for (int i = 0; i < bSize + aSize; i++) { + Enchantment ench; + int yIndex; + if (i < bSize) { + yIndex = -i - 1; + ench = before.get(i); + } else { + yIndex = i - bSize + 1; + ench = after.get(i - bSize); + } + + if (mouseY > top + 16 * yIndex && mouseY <= top + 16 * yIndex + 16) { + enchanterCurrentEnch = ench; + isChangingEnchLevel = false; + return true; + } + } + } + } + + if (isChangingEnchLevel) { + isChangingEnchLevel = false; + return true; + } + } + } else if (currentState == EnchantState.ADDING_BOOK) { + if (Mouse.getEventButtonState()) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + + if (!isChangingEnchLevel && mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48 && + mouseY > top + 18 && mouseY <= top + 18 + 14) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + /*GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID));*/ + + cancelButtonAnimTime = System.currentTimeMillis(); + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + enchanterCurrentItem = null; + } else if (!isChangingEnchLevel && enchanterCurrentItem != null && + (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) || + (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1 && + mouseY > top + 18 && mouseY <= top + 18 + 14)) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot( + enchanterCurrentItem.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + enchanterCurrentItem.slotIndex, 0, 0, stack, transactionID + )); + + if (removingEnchantPlayerLevel >= 0 && enchanterCurrentItem.level == removingEnchantPlayerLevel) { + orbDisplay.spawnExperienceOrbs(X_SIZE / 2, 66, X_SIZE / 2, 36, 3); + } else { + orbDisplay.spawnExperienceOrbs(mouseX - guiLeft, mouseY - guiTop, X_SIZE / 2, 66, 0); + } + + confirmButtonAnimTime = System.currentTimeMillis(); + enchanterCurrentItem = null; + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + } else if (mouseX > left + 96 && mouseX <= left + 96 + 16) { + if (!isChangingEnchLevel) { + if (mouseY > top && mouseY < top + 16) { + isChangingEnchLevel = true; + return true; + } + } else { + List<HexItem> before = new ArrayList<>(); + List<HexItem> after = new ArrayList<>(); + + for (HexItem item : enchanterItemLevels.values()) { + if (item.level < enchanterCurrentItem.level) { + before.add(item); + } else if (item.level > enchanterCurrentItem.level) { + after.add(item); + } + } + + before.sort(Comparator.comparingInt(o -> -o.level)); + after.sort(Comparator.comparingInt(o -> o.level)); + + int bSize = before.size(); + int aSize = after.size(); + for (int i = 0; i < bSize + aSize; i++) { + HexItem item; + int yIndex; + if (i < bSize) { + yIndex = -i - 1; + item = before.get(i); + } else { + yIndex = i - bSize + 1; + item = after.get(i - bSize); + } + + if (mouseY > top + 16 * yIndex && mouseY <= top + 16 * yIndex + 16) { + enchanterCurrentItem = item; + isChangingEnchLevel = false; + return true; + } + } + } + } + + if (isChangingEnchLevel) { + isChangingEnchLevel = false; + return true; + } + } + } else if (currentState == EnchantState.HAS_ITEM_IN_HEX) { + if (Mouse.getEventButtonState()) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + + if (!isChangingEnchLevel && mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48 && + mouseY > top + 18 && mouseY <= top + 18 + 14) { + /*if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + enchanterCurrentItem = null;*/ + } else if (!isChangingEnchLevel && enchanterCurrentItem != null && + (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) || + (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1 && + mouseY > top + 18 && mouseY <= top + 18 + 14)) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot( + enchanterCurrentItem.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + enchanterCurrentItem.slotIndex, 0, 0, stack, transactionID + )); + enchantingItem = null; + if (removingEnchantPlayerLevel >= 0 && enchanterCurrentItem.level == removingEnchantPlayerLevel) { + orbDisplay.spawnExperienceOrbs(X_SIZE / 2, 66, X_SIZE / 2, 36, 3); + } else { + orbDisplay.spawnExperienceOrbs(mouseX - guiLeft, mouseY - guiTop, X_SIZE / 2, 66, 0); + } + + confirmButtonAnimTime = System.currentTimeMillis(); + //enchanterCurrentItem = null; + //currentState = EnchantState.HAS_ITEM_IN_BOOKS; + } else if (mouseX > left + 96 && mouseX <= left + 96 + 16) { + if (!isChangingEnchLevel) { + if (mouseY > top && mouseY < top + 16) { + isChangingEnchLevel = true; + return true; + } + } else { + List<HexItem> before = new ArrayList<>(); + List<HexItem> after = new ArrayList<>(); + + for (HexItem item : enchanterItemLevels.values()) { + if (item.level < enchanterCurrentItem.level) { + before.add(item); + } else if (item.level > enchanterCurrentItem.level) { + after.add(item); + } + } + + before.sort(Comparator.comparingInt(o -> -o.level)); + after.sort(Comparator.comparingInt(o -> o.level)); + + int bSize = before.size(); + int aSize = after.size(); + for (int i = 0; i < bSize + aSize; i++) { + HexItem item; + int yIndex; + if (i < bSize) { + yIndex = -i - 1; + item = before.get(i); + } else { + yIndex = i - bSize + 1; + item = after.get(i - bSize); + } + + if (mouseY > top + 16 * yIndex && mouseY <= top + 16 * yIndex + 16) { + enchanterCurrentItem = item; + isChangingEnchLevel = false; + return true; + } + } + } + } + + if (isChangingEnchLevel) { + isChangingEnchLevel = false; + return true; + } + } + } else if (currentState == EnchantState.ADDING_GEMSTONE || currentState == EnchantState.APPLYING_GEMSTONE) { + if (Mouse.getEventButtonState()) { + int left = guiLeft + X_SIZE / 2 - 56; + int top = guiTop + 83; + + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 - 1 - 48, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + Utils.drawTexturedRect(guiLeft + X_SIZE / 2 + 1, top + 18, 48, 14, + 0, 48 / 512f, 328 / 512f, (328 + 14) / 512f, GL11.GL_NEAREST + ); + + if (!isChangingEnchLevel && mouseX > guiLeft + X_SIZE / 2 + 1 && mouseX <= guiLeft + X_SIZE / 2 + 1 + 48 && + mouseY > top + 18 && mouseY <= top + 18 + 14) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState != EnchantState.APPLYING_GEMSTONE) { + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + currentState = EnchantState.HAS_ITEM_IN_GEMSTONE; + enchanterCurrentItem = null; + } else { + currentState = EnchantState.ADDING_ENCHANT; + enchanterCurrentItem = null; + } + } else if (!isChangingEnchLevel && enchanterCurrentItem != null && + (mouseX > left + 16 && mouseX <= left + 96 && + mouseY > top && mouseY <= top + 16) || + (mouseX > guiLeft + X_SIZE / 2 - 1 - 48 && mouseX <= guiLeft + X_SIZE / 2 - 1 && + mouseY > top + 18 && mouseY <= top + 18 + 14) && currentState == EnchantState.APPLYING_GEMSTONE) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot( + enchanterCurrentItem.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + enchanterCurrentItem.slotIndex, 0, 0, stack, transactionID + )); + enchantingItem = null; + if (removingEnchantPlayerLevel >= 0 && enchanterCurrentItem.level == removingEnchantPlayerLevel) { + orbDisplay.spawnExperienceOrbs(X_SIZE / 2, 66, X_SIZE / 2, 36, 3); + } else { + orbDisplay.spawnExperienceOrbs(mouseX - guiLeft, mouseY - guiTop, X_SIZE / 2, 66, 0); + } + + confirmButtonAnimTime = System.currentTimeMillis(); + enchanterCurrentItem = null; + currentState = EnchantState.ADDING_GEMSTONE; + } else if (mouseX > left + 96 && mouseX <= left + 96 + 16) { + if (!isChangingEnchLevel) { + if (mouseY > top && mouseY < top + 16) { + isChangingEnchLevel = true; + return true; + } + } else { + List<HexItem> before = new ArrayList<>(); + List<HexItem> after = new ArrayList<>(); + + for (HexItem item : enchanterItemLevels.values()) { + if (item.level < enchanterCurrentItem.level) { + before.add(item); + } else if (item.level > enchanterCurrentItem.level) { + after.add(item); + } + } + + before.sort(Comparator.comparingInt(o -> -o.level)); + after.sort(Comparator.comparingInt(o -> o.level)); + + int bSize = before.size(); + int aSize = after.size(); + for (int i = 0; i < bSize + aSize; i++) { + HexItem item; + int yIndex; + if (i < bSize) { + yIndex = -i - 1; + item = before.get(i); + } else { + yIndex = i - bSize + 1; + item = after.get(i - bSize); + } + + if (mouseY > top + 16 * yIndex && mouseY <= top + 16 * yIndex + 16) { + enchanterCurrentItem = item; + isChangingEnchLevel = false; + return true; + } + } + } + } + + if (isChangingEnchLevel) { + isChangingEnchLevel = false; + return true; + } + } + } + + if (!Mouse.getEventButtonState() && Mouse.getEventButton() < 0 && clickedScrollOffset != -1) { + if (isInEnchanting()) { + LerpingInteger lerpingInteger = isClickedScrollLeft ? leftScroll : rightScroll; + List<Enchantment> enchantsList = isClickedScrollLeft ? applicable : removable; + + if (enchantsList.size() > 6) { + int newOffset = mouseY - clickedScrollOffset; + + int newScroll = Math.round(newOffset * (float) ((enchantsList.size() - 6) * 16) / (96 - 15)); + int max = (enchantsList.size() - 6) * 16; + + if (newScroll > max) newScroll = max; + if (newScroll < 0) newScroll = 0; + + lerpingInteger.setValue(newScroll); + } + } else { + LerpingInteger lerpingInteger = isClickedScrollLeft ? leftScroll : rightScroll; + List<HexItem> itemsList = isClickedScrollLeft ? applicableItem : removableItem; + + if (itemsList.size() > 6) { + int newOffset = mouseY - clickedScrollOffset; + + int newScroll = Math.round(newOffset * (float) ((itemsList.size() - 6) * 16) / (96 - 15)); + int max = (itemsList.size() - 6) * 16; + + if (newScroll > max) newScroll = max; + if (newScroll < 0) newScroll = 0; + + lerpingInteger.setValue(newScroll); + } + } + } + + //Config options + if (Mouse.getEventButtonState()) { + if (mouseX >= guiLeft + 294 && mouseX < guiLeft + 294 + 36 && + mouseY >= guiTop + 146 && mouseY < guiTop + 146 + 36) { + int index = (mouseX - (guiLeft + 295)) / 18 + (mouseY - (guiTop + 147)) / 18 * 2; + + int direction = Mouse.getEventButton() == 0 ? 1 : -1; + + switch (index) { + case 0: { + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableHexGUI = false; + break; + } + case 1: { + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel = !NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel; + break; + } + case 2: { + int val = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantSorting; + val += direction; + if (val < 0) val = 1; + if (val > 1) val = 0; + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantSorting = val; + break; + } + case 3: { + int val = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantOrdering; + val += direction; + if (val < 0) val = 1; + if (val > 1) val = 0; + NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantOrdering = val; + break; + } + } + } + } + + if (Mouse.getEventButton() == 0) { + if (Mouse.getEventButtonState()) { + if (isInEnchanting()) { + if (mouseX > guiLeft + 104 && mouseX < guiLeft + 104 + 12) { + int offset; + if (applicable.size() <= 6) { + offset = 0; + } else { + offset = Math.round((96 - 15) * (leftScroll.getValue() / (float) ((applicable.size() - 6) * 16))); + } + if (mouseY >= guiTop + 18 + offset && mouseY < guiTop + 18 + offset + 15) { + isClickedScrollLeft = true; + clickedScrollOffset = mouseY - offset; + } + } else if (mouseX > guiLeft + 344 && mouseX < guiLeft + 344 + 12) { + int offset; + if (removable.size() <= 6) { + offset = 0; + } else { + offset = Math.round((96 - 15) * (rightScroll.getValue() / (float) ((removable.size() - 6) * 16))); + } + if (mouseY >= guiTop + 18 + offset && mouseY < guiTop + 18 + offset + 15) { + isClickedScrollLeft = false; + clickedScrollOffset = mouseY - offset; + } + } + } else { + if (mouseX > guiLeft + 104 && mouseX < guiLeft + 104 + 12) { + int offset; + if (applicableItem.size() <= 6) { + offset = 0; + } else { + offset = Math.round((96 - 15) * (leftScroll.getValue() / (float) ((applicableItem.size() - 6) * 16))); + } + if (mouseY >= guiTop + 18 + offset && mouseY < guiTop + 18 + offset + 15) { + isClickedScrollLeft = true; + clickedScrollOffset = mouseY - offset; + } + } else if (mouseX > guiLeft + 344 && mouseX < guiLeft + 344 + 12) { + int offset; + if (removableItem.size() <= 6) { + offset = 0; + } else { + offset = Math.round((96 - 15) * (rightScroll.getValue() / (float) ((removableItem.size() - 6) * 16))); + } + if (mouseY >= guiTop + 18 + offset && mouseY < guiTop + 18 + offset + 15) { + isClickedScrollLeft = false; + clickedScrollOffset = mouseY - offset; + } + } + } + } else { + clickedScrollOffset = -1; + } + } + + if (mouseY > guiTop + 18 && mouseY < guiTop + 18 + 96) { + if (mouseX > guiLeft + 8 && mouseX < guiLeft + 8 + 96) { + if (Mouse.getEventButton() == 0 && Mouse.getEventButtonState() && + Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { + if (isInEnchanting()) { + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + if (applicable.size() <= index) break; + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + Enchantment ench = applicable.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState == EnchantState.HAS_ITEM) { + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(ench.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + ench.slotIndex, 0, 0, stack, transactionID + )); + } 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(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + } + + return true; + } + } + } else if (!isInHex() && !isInGemstones()) { + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + if (applicableItem.size() <= index) break; + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + HexItem item = applicableItem.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState == EnchantState.HAS_ITEM_IN_BOOKS) { + currentState = EnchantState.ADDING_BOOK; + enchanterCurrentItem = item; + } else if (currentState == EnchantState.ADDING_BOOK && enchanterCurrentItem == item) { + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(item.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + item.slotIndex, 0, 0, stack, transactionID + )); + + cancelButtonAnimTime = System.currentTimeMillis(); + } else { + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + enchanterCurrentItem = null; + } + + return true; + } + } + } else if (isInHex() && !isInGemstones()) { + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + if (applicableItem.size() <= index) break; + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + HexItem item = applicableItem.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(item.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + item.slotIndex, 0, 0, stack, transactionID + )); + + //cancelButtonAnimTime = System.currentTimeMillis(); + + return true; + } + } + } else if (currentState == EnchantState.ADDING_GEMSTONE || currentState == EnchantState.APPLYING_GEMSTONE) { + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + if (applicableItem.size() <= index) break; + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + HexItem item = applicableItem.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState == EnchantState.ADDING_GEMSTONE) { + currentState = EnchantState.APPLYING_GEMSTONE; + enchanterCurrentItem = item; + } else if (currentState == EnchantState.APPLYING_GEMSTONE && enchanterCurrentItem == item) { + currentState = EnchantState.ADDING_GEMSTONE; + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(item.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + item.slotIndex, 0, 0, stack, transactionID + )); + + cancelButtonAnimTime = System.currentTimeMillis(); + } else { + currentState = EnchantState.ADDING_GEMSTONE; + enchanterCurrentItem = null; + } + + //cancelButtonAnimTime = System.currentTimeMillis(); + + return true; + } + } + } else if (currentState == EnchantState.HAS_ITEM_IN_GEMSTONE) { + for (int i = 0; i < 7; i++) { + int index = i + leftScroll.getValue() / 16; + if (applicableItem.size() <= index) break; + + int top = guiTop - (leftScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 8 && mouseX <= guiLeft + 8 + 96 && + mouseY > top && mouseY <= top + 16) { + HexItem item = applicableItem.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(item.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + item.slotIndex, 0, 0, stack, transactionID + )); + + cancelButtonAnimTime = System.currentTimeMillis(); + + //cancelButtonAnimTime = System.currentTimeMillis(); + + return true; + } + } + } + } + + isScrollingLeft = true; + } else if (mouseX > guiLeft + 248 && mouseX < guiLeft + 248 + 96) { + if (Mouse.getEventButton() == 0 && Mouse.getEventButtonState() && + Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { + if (isInEnchanting()) { + for (int i = 0; i < 7; i++) { + int index = i + rightScroll.getValue() / 16; + if (removable.size() <= index) break; + + int top = guiTop - (rightScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 248 && mouseX <= guiLeft + 248 + 96 && + mouseY > top && mouseY <= top + 16) { + Enchantment ench = removable.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState == EnchantState.HAS_ITEM || currentState == EnchantState.HAS_ITEM_IN_HEX) { + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(ench.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + ench.slotIndex, 0, 0, stack, transactionID + )); + } 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(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + } + + return true; + } + } + } else if (currentState == EnchantState.ADDING_GEMSTONE) { + for (int i = 0; i < 7; i++) { + int index = i + rightScroll.getValue() / 16; + if (removableItem.size() <= index) break; + + int top = guiTop - (rightScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 248 && mouseX <= guiLeft + 248 + 96 && + mouseY > top && mouseY <= top + 16) { + HexItem item = removableItem.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState == EnchantState.ADDING_GEMSTONE) { + currentState = EnchantState.APPLYING_GEMSTONE; + enchanterCurrentItem = item; + } else if (currentState == EnchantState.APPLYING_GEMSTONE && enchanterCurrentItem == item) { + currentState = EnchantState.ADDING_GEMSTONE; + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(item.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + item.slotIndex, 0, 0, stack, transactionID + )); + + cancelButtonAnimTime = System.currentTimeMillis(); + } else { + currentState = EnchantState.ADDING_GEMSTONE; + enchanterCurrentItem = null; + } + + return true; + } + } + + } else { + for (int i = 0; i < 7; i++) { + int index = i + rightScroll.getValue() / 16; + if (removableItem.size() <= index) break; + + int top = guiTop - (rightScroll.getValue() % 16) + 18 + 16 * i; + if (mouseX > guiLeft + 248 && mouseX <= guiLeft + 248 + 96 && + mouseY > top && mouseY <= top + 16) { + HexItem item = removableItem.get(index); + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + if (currentState == EnchantState.HAS_ITEM_IN_BOOKS) { + currentState = EnchantState.ADDING_BOOK; + enchanterCurrentItem = item; + } else if (currentState == EnchantState.ADDING_BOOK && enchanterCurrentItem == item) { + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = + ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(item.slotIndex); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, + item.slotIndex, 0, 0, stack, transactionID + )); + + cancelButtonAnimTime = System.currentTimeMillis(); + } else { + currentState = EnchantState.HAS_ITEM_IN_BOOKS; + enchanterCurrentItem = null; + } + + return true; + } + } + } + } + isScrollingLeft = false; + } + } + if (Mouse.getEventDWheel() != 0) { + int scroll = Mouse.getEventDWheel(); + if (scroll > 0) { + scroll = -16; + } else { + scroll = 16; + } + + LerpingInteger lerpingInteger = isScrollingLeft ? leftScroll : rightScroll; + int elementsCount; + if (isInEnchanting()) { + elementsCount = isScrollingLeft ? applicable.size() : removable.size(); + } else { + elementsCount = isScrollingLeft ? applicableItem.size() : removableItem.size(); + } + int max = (elementsCount - 6) * 16; + + int newTarget = lerpingInteger.getTarget() + scroll; + if (newTarget > max) newTarget = max; + if (newTarget < 0) newTarget = 0; + + if (newTarget != lerpingInteger.getTarget()) { + lerpingInteger.resetTimer(); + lerpingInteger.setTarget(newTarget); + } + } + + if (mouseX > guiLeft + 102 && mouseX < guiLeft + 102 + 160) { + if ((mouseY > guiTop + 133 && mouseY < guiTop + 133 + 54) || + (mouseY > guiTop + 133 + 54 + 4 && mouseY < guiTop + 133 + 54 + 4 + 18)) { + if (currentState == EnchantState.ADDING_ENCHANT) { + if (Mouse.getEventButtonState()) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + } + return true; + } else { + return false; + } + } + } + if (mouseX >= guiLeft + 173 && mouseX < guiLeft + 173 + 18 && + mouseY >= guiTop + 57 && mouseY < guiTop + 57 + 18) { + if (currentState == EnchantState.ADDING_ENCHANT) { + if (Mouse.getEventButtonState()) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true; + GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); + + EntityPlayerSP playerIn = Minecraft.getMinecraft().thePlayer; + short transactionID = playerIn.openContainer.getNextTransactionID(playerIn.inventory); + ItemStack stack = ((ContainerChest) chest.inventorySlots).getLowerChestInventory().getStackInSlot(45); + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0EPacketClickWindow( + chest.inventorySlots.windowId, 45, 0, 0, stack, transactionID)); + + cancelButtonAnimTime = System.currentTimeMillis(); + } + return true; + } else { + return false; + } + } + return true; + } + + public boolean keyboardInput() { + if (currentState == EnchantState.HAS_ITEM && searchField.getFocus()) { + if (Keyboard.getEventKeyState()) { + searchField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + } + return true; + } + if (Keyboard.getEventKey() == Minecraft.getMinecraft().gameSettings.keyBindScreenshot.getKeyCode()) { + return false; + } + + return Keyboard.getEventKey() != Keyboard.KEY_ESCAPE && + Keyboard.getEventKey() != Minecraft.getMinecraft().gameSettings.keyBindInventory.getKeyCode() && + (!NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotLocking || + Keyboard.getEventKey() != NotEnoughUpdates.INSTANCE.config.slotLocking.slotLockKey); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/HexItem.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/HexItem.java new file mode 100644 index 00000000..5b3b30ea --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/HexItem.java @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscgui.hex; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.util.StringUtils; + +import java.util.List; + +public class HexItem { + public int slotIndex; + public String itemName; + public String itemId; + public List<String> displayLore; + public int level; + public int price = -1; + public boolean overMaxLevel = false; + public boolean conflicts = false; + public ItemType itemType; + public int gemstoneLevel = -1; + + public HexItem( + int slotIndex, String itemName, String itemId, List<String> displayLore, + boolean useMaxLevelForCost, boolean checkConflicts + ) { + this.slotIndex = slotIndex; + this.itemName = itemName; + this.itemId = itemId.replace("'S", ""); + this.displayLore = displayLore; + switch (itemId) { + default: + this.itemType = ItemType.UNKNOWN; + break; + case "HOT_POTATO_BOOK": + this.itemType = ItemType.HOT_POTATO; + break; + case "FUMING_POTATO_BOOK": + this.itemType = ItemType.FUMING_POTATO; + break; + case "BOOK_OF_STATS": + this.itemType = ItemType.BOOK_OF_STATS; + break; + case "THE_ART_OF_WAR": + this.itemType = ItemType.ART_OF_WAR; + break; + case "FARMING_FOR_DUMMIES": + this.itemType = ItemType.FARMING_DUMMY; + break; + case "THE_ART_OF_PEACE": + this.itemType = ItemType.ART_OF_PEACE; + break; + case "RECOMBOBULATOR_3000": + this.itemType = ItemType.RECOMB; + break; + case "SILEX": + this.itemId = "SIL_EX"; + this.itemType = ItemType.SILEX; + break; + case "RUBY_POWER_SCROLL": + this.itemType = ItemType.RUBY_SCROLL; + break; + case "SAPPHIRE_POWER_SCROLL": + this.itemType = ItemType.SAPPHIRE_SCROLL; + break; + case "JASPER_POWER_SCROLL": + this.itemType = ItemType.JASPER_SCROLL; + break; + case "AMETHYST_POWER_SCROLL": + this.itemType = ItemType.AMETHYST_SCROLL; + break; + case "AMBER_POWER_SCROLL": + this.itemType = ItemType.AMBER_SCROLL; + break; + case "OPAL_POWER_SCROLL": + this.itemType = ItemType.OPAL_SCROLL; + break; + case "FIRST_MASTER_STAR": + this.itemType = ItemType.FIRST_MASTER_STAR; + break; + case "SECOND_MASTER_STAR": + this.itemType = ItemType.SECOND_MASTER_STAR; + break; + case "THIRD_MASTER_STAR": + this.itemType = ItemType.THIRD_MASTER_STAR; + break; + case "FOURTH_MASTER_STAR": + this.itemType = ItemType.FOURTH_MASTER_STAR; + break; + case "FIFTH_MASTER_STAR": + this.itemType = ItemType.FIFTH_MASTER_STAR; + break; + case "WOOD_SINGULARITY": + this.itemType = ItemType.WOOD_SINGULARITY; + break; + case "IMPLOSION": + this.itemType = ItemType.IMPLOSION_SCROLL; + break; + case "WITHER_SHIELD": + this.itemType = ItemType.WITHER_SHIELD_SCROLL; + break; + case "SHADOW_WARP": + this.itemType = ItemType.SHADOW_WARP_SCROLL; + break; + case "TRANSMISSION_TUNER": + this.itemType = ItemType.TUNER; + break; + case "RANDOM_REFORGE": + this.itemType = ItemType.RANDOM_REFORGE; + break; + case "MANA_DISINTEGRATOR": + this.itemType = ItemType.MANA_DISINTEGRATOR; + break; + case "TOTAL_UPGRADES": + this.itemType = ItemType.TOTAL_UPGRADES; + break; + case "CONVERT_TO_DUNGEON": + this.itemType = ItemType.CONVERT_TO_DUNGEON; + break; + case "EXPERIENCE_BOTTLE": + this.itemType = ItemType.EXPERIENCE_BOTTLE; + break; + case "GRAND_EXPERIENCE_BOTTLE": + this.itemType = ItemType.GRAND_EXPERIENCE_BOTTLE; + break; + case "TITANIC_EXPERIENCE_BOTTLE": + this.itemType = ItemType.TITANIC_EXPERIENCE_BOTTLE; + break; + case "COLOSSAL_EXPERIENCE_BOTTLE": + this.itemType = ItemType.COLOSSAL_EXPERIENCE_BOTTLE; + break; + } + if (this.itemType == ItemType.UNKNOWN) { + for (String string : displayLore) { + if ((string.contains("Applies the") && string.contains("reforge")) || + string.contains("reforge when combined")) { + this.itemType = ItemType.REFORGE; + break; + } + } + } + if (!this.isMasterStar() && itemId.contains("✪")) { + if (itemId.contains("✪✪✪✪✪")) this.itemType = ItemType.FIFTH_STAR; + else if (itemId.contains("✪✪✪✪")) this.itemType = ItemType.FOURTH_STAR; + else if (itemId.contains("✪✪✪")) this.itemType = ItemType.THIRD_STAR; + else if (itemId.contains("✪✪")) this.itemType = ItemType.SECOND_STAR; + else if (itemId.contains("✪")) this.itemType = ItemType.FIRST_STAR; + } + if (this.itemId.contains("EXPERIENCE_BOTTLE")) { + this.itemId = this.itemId.replace("EXPERIENCE_BOTTLE", "EXP_BOTTLE"); + } + if (this.itemId.contains("END_STONE_GEODE")) { + this.itemId = this.itemId.replace("END_STONE_GEODE", "ENDSTONE_GEODE"); + } + if (itemId.contains("HEX_ITEM")) this.itemType = ItemType.HEX_ITEM; + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(this.itemId); + if (bazaarInfo != null && bazaarInfo.get("curr_buy") != null) { + this.price = bazaarInfo.get("curr_buy").getAsInt(); + } + if ("SIL_EX".equals(this.itemId)) this.itemId = "SILEX"; + if (itemName.contains("Amethyst Gemstone")) this.itemType = ItemType.AMETHYST_GEMSTONE; + if (itemName.contains("Ruby Gemstone")) this.itemType = ItemType.RUBY_GEMSTONE; + if (itemName.contains("Sapphire Gemstone")) this.itemType = ItemType.SAPPHIRE_GEMSTONE; + if (itemName.contains("Jasper Gemstone")) this.itemType = ItemType.JASPER_GEMSTONE; + if (itemName.contains("Jade Gemstone")) this.itemType = ItemType.JADE_GEMSTONE; + if (itemName.contains("Amber Gemstone")) this.itemType = ItemType.AMBER_GEMSTONE; + if (itemName.contains("Opal Gemstone")) this.itemType = ItemType.OPAL_GEMSTONE; + if (itemName.contains("Topaz Gemstone")) this.itemType = ItemType.TOPAZ_GEMSTONE; + if (itemName.contains("Gemstone Slot")) this.itemType = ItemType.GEMSTONE_SLOT; + if (this.itemName.contains(" Gemstone")) { + this.itemName = this.itemName.replace(" Gemstone", "").substring(2); + } else if (this.itemName.contains(" Experience Bottle")) { + this.itemName = this.itemName.replace("Experience Bottle", ""); + } else if (this.itemName.equals("Experience Bottle")) { + this.itemName = "Exp Bottle"; + } + if (isGemstone()) { + if (this.itemName.contains("Rough")) this.gemstoneLevel = 0; + if (this.itemName.contains("Flawed")) this.gemstoneLevel = 1; + if (this.itemName.contains("Fine")) this.gemstoneLevel = 2; + if (this.itemName.contains("Flawless")) this.gemstoneLevel = 3; + if (this.itemName.contains("Perfect")) this.gemstoneLevel = 4; + } + } + + public boolean isPowerScroll() { + return itemType == ItemType.RUBY_SCROLL || itemType == ItemType.SAPPHIRE_SCROLL || + itemType == ItemType.JASPER_SCROLL || itemType == ItemType.AMETHYST_SCROLL || + itemType == ItemType.AMBER_SCROLL || itemType == ItemType.OPAL_SCROLL; + } + + public boolean isDungeonStar() { + return itemType == ItemType.FIRST_STAR || itemType == ItemType.SECOND_STAR || + itemType == ItemType.THIRD_STAR || itemType == ItemType.FOURTH_STAR || + itemType == ItemType.FIFTH_STAR; + } + + public boolean isMasterStar() { + return itemType == ItemType.FIRST_MASTER_STAR || itemType == ItemType.SECOND_MASTER_STAR || + itemType == ItemType.THIRD_MASTER_STAR || itemType == ItemType.FOURTH_MASTER_STAR || + itemType == ItemType.FIFTH_MASTER_STAR; + } + + public String getReforge() { + JsonObject reforgeStones = Constants.REFORGESTONES; + if (reforgeStones != null && reforgeStones.has(this.itemId.toUpperCase())) { + JsonObject reforgeInfo = reforgeStones.get(this.itemId.toUpperCase()).getAsJsonObject(); + if (reforgeInfo != null) { + return Utils.getElementAsString(reforgeInfo.get("reforgeName"), ""); + } + + } + return ""; + } + + public int getPrice() { + if (this.itemType == ItemType.RANDOM_REFORGE) { + for (String string : displayLore) { + if (string.contains("Coins")) { + try { + price = Integer.parseInt(StringUtils + .stripControlCodes(string) + .replace(" Coins", "") + .replace(",", "") + .trim()); + } catch (NumberFormatException ignored) { + } + } + } + } + return price; + } + + public boolean isHypeScroll() { + return itemType == ItemType.IMPLOSION_SCROLL || itemType == ItemType.WITHER_SHIELD_SCROLL || + itemType == ItemType.SHADOW_WARP_SCROLL; + } + + public boolean isGemstone() { + return itemType == ItemType.RUBY_GEMSTONE || itemType == ItemType.AMETHYST_GEMSTONE || + itemType == ItemType.SAPPHIRE_GEMSTONE || itemType == ItemType.JASPER_GEMSTONE || + itemType == ItemType.JADE_GEMSTONE || itemType == ItemType.AMBER_GEMSTONE || + itemType == ItemType.OPAL_GEMSTONE || itemType == ItemType.TOPAZ_GEMSTONE; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/ItemType.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/ItemType.java new file mode 100644 index 00000000..3b47a86d --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/hex/ItemType.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscgui.hex; + +enum ItemType { + HOT_POTATO, + FUMING_POTATO, + BOOK_OF_STATS, + ART_OF_WAR, + ART_OF_PEACE, + FARMING_DUMMY, + RECOMB, + SILEX, + RUBY_SCROLL, + SAPPHIRE_SCROLL, + JASPER_SCROLL, + AMETHYST_SCROLL, + AMBER_SCROLL, + OPAL_SCROLL, + FIRST_STAR(1), + SECOND_STAR(2), + THIRD_STAR(3), + FOURTH_STAR(4), + FIFTH_STAR(5), + FIRST_MASTER_STAR(6), + SECOND_MASTER_STAR(7), + THIRD_MASTER_STAR(8), + FOURTH_MASTER_STAR(9), + FIFTH_MASTER_STAR(10), + WOOD_SINGULARITY, + IMPLOSION_SCROLL, + SHADOW_WARP_SCROLL, + WITHER_SHIELD_SCROLL, + TUNER, + REFORGE, + RANDOM_REFORGE, + MANA_DISINTEGRATOR, + HEX_ITEM, + TOTAL_UPGRADES, + RUBY_GEMSTONE, + AMETHYST_GEMSTONE, + SAPPHIRE_GEMSTONE, + JASPER_GEMSTONE, + JADE_GEMSTONE, + AMBER_GEMSTONE, + OPAL_GEMSTONE, + TOPAZ_GEMSTONE, + CONVERT_TO_DUNGEON, + GEMSTONE_SLOT, + EXPERIENCE_BOTTLE, + GRAND_EXPERIENCE_BOTTLE, + TITANIC_EXPERIENCE_BOTTLE, + COLOSSAL_EXPERIENCE_BOTTLE, + UNKNOWN; + + private int starLevel = -1; + + ItemType() {} + + ItemType(int starLevel) { + this.starLevel = starLevel; + } + + public int getStarLevel() { + return starLevel; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/ExperienceOrb.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/ExperienceOrb.java new file mode 100644 index 00000000..9da4f553 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/ExperienceOrb.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscgui.util; + +import org.lwjgl.util.vector.Vector2f; + +public class ExperienceOrb { + public Vector2f position; + public Vector2f positionLast; + public Vector2f velocity; + public Vector2f target; + + public int type; + public int rotationDeg; +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/OrbDisplay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/OrbDisplay.java new file mode 100644 index 00000000..42e935f5 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/util/OrbDisplay.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscgui.util; + +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.vector.Vector2f; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.Random; + +public class OrbDisplay { + private static final ResourceLocation TEXTURE = new ResourceLocation("notenoughupdates:custom_enchant_gui.png"); + private static final int DEFAULT_COUNT = 30; + + private final List<ExperienceOrb> experienceOrbList = new ArrayList<>(); + + public ExperienceOrb spawnExperienceOrb(Random random, Vector2f start, Vector2f target, int baseType) { + ExperienceOrb orb = new ExperienceOrb(); + orb.position = new Vector2f(start); + orb.positionLast = new Vector2f(orb.position); + orb.velocity = new Vector2f( + random.nextFloat() * 20 - 10, + random.nextFloat() * 20 - 10 + ); + orb.target = new Vector2f(target); + orb.type = baseType; + orb.rotationDeg = random.nextInt(4) * 90; + + float v = random.nextFloat(); + if (v > 0.6) { + orb.type += 1; + } + if (v > 0.9) { + orb.type += 1; + } + + experienceOrbList.add(orb); + + return orb; + } + + public void spawnExperienceOrbs(int startX, int startY, int targetX, int targetY, int baseType) { + spawnExperienceOrbs(new Random(),new Vector2f(startX, startY), new Vector2f(targetX, targetY), baseType, DEFAULT_COUNT); + } + + public void spawnExperienceOrbs(Random random, Vector2f start, Vector2f target, int baseType, int count) { + for (int i = 0; i < count; i++) { + spawnExperienceOrb(random, start, target, baseType); + } + } + + public void physicsTickOrbs() { + for (ListIterator<ExperienceOrb> it = experienceOrbList.listIterator(); it.hasNext(); ) { + ExperienceOrb orb = it.next(); + + Vector2f delta = Vector2f.sub(orb.target, orb.position, null); + float length = delta.length(); + + // Remove close Orbs + if (length < 8 && orb.velocity.lengthSquared() < 20) { + it.remove(); + continue; + } + + // Update velocity + Vector2f.add(orb.velocity, (Vector2f) delta.scale(2 / length), orb.velocity); + orb.velocity.scale(0.9F); + + // Update position + orb.positionLast.set(orb.position); + Vector2f.add(orb.position, orb.velocity, orb.position); + } + } + + public void renderOrbs(float partialTicks) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE); + GlStateManager.disableDepth(); + + for (ExperienceOrb orb : experienceOrbList) { + int orbX = Math.round(LerpUtils.lerp(orb.position.x, orb.positionLast.x, partialTicks)); + int orbY = Math.round(LerpUtils.lerp(orb.position.y, orb.positionLast.y, partialTicks)); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(orbX, orbY, 0); + GlStateManager.rotate(orb.rotationDeg, 0, 0, 1); + + Vector2f delta = Vector2f.sub(orb.position, orb.target, null); + + float length = delta.length(); + float velocitySquared = orb.velocity.lengthSquared(); + float opacity = (float) Math.sqrt( + Math.min( + 1, + Math.min(2, Math.max(0.5F, length / 16)) + * Math.min(2, Math.max(0.5F, velocitySquared / 40)) + )); + GlStateManager.color(1, 1, 1, opacity); + + int orbU = (orb.type % 3) * 16; + int orbV = (orb.type / 3) * 16 + 217; + + Utils.drawTexturedRect( + -8, -8, 16, 16, + orbU / 512f, + (orbU + 16) / 512f, + orbV / 512f, + (orbV + 16) / 512f, + GL11.GL_NEAREST + ); + + GlStateManager.popMatrix(); + } + + GlStateManager.enableDepth(); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index 7c3414fa..f708fb5f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; +import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionSortModeWarning; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; @@ -31,6 +32,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; +import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -96,7 +98,7 @@ public abstract class MixinGuiContainer extends GuiScreen { if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) { String tagName = tag.getCompoundTag("SkullOwner").getString("Name"); String displayName = Utils.cleanColour(cc.inventorySlots.get(22).getStack().getDisplayName()); - if (tagName.equals(displayName.substring(displayName.length() - tagName.length()))) { + if (displayName.length() - tagName.length() >= 0 && tagName.equals(displayName.substring(displayName.length() - tagName.length()))) { ci.cancel(); this.zLevel = 100.0F; @@ -189,6 +191,7 @@ public abstract class MixinGuiContainer extends GuiScreen { public void isMouseOverSlot(Slot slotIn, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> cir) { StorageOverlay.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); GuiCustomEnchant.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); + GuiCustomHex.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); AuctionBINWarning.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); AbiphoneWarning.getInstance().overrideIsMouseOverSlot(slotIn, mouseX, mouseY, cir); } @@ -312,6 +315,11 @@ public abstract class MixinGuiContainer extends GuiScreen { return; } + if (AntiCoopAdd.onMouseClick(slotIn, slotId, clickedButton, clickType)) { + ci.cancel(); + return; + } + AtomicBoolean ret = new AtomicBoolean(false); SlotLocking.getInstance().onWindowClick(slotIn, slotId, clickedButton, clickType, (tuple) -> { ci.cancel(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java index 3856e2d5..381f5934 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java @@ -43,7 +43,7 @@ public class MixinGuiIngame { @Redirect(method = "renderScoreboard", at = @At(value = "INVOKE", target = TARGET)) public String renderScoreboard_formatPlayerName(Team team, String name) { - if (NotEnoughUpdates.INSTANCE.isOnSkyblock() && NotEnoughUpdates.INSTANCE.config.misc.streamerMode) { + if (NotEnoughUpdates.INSTANCE.config.misc.streamerMode) { return StreamerMode.filterScoreboard(ScorePlayerTeam.formatPlayerName(team, name)); } return ScorePlayerTeam.formatPlayerName(team, name); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiInventory.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiInventory.java index bd712ec7..86ed9b8f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiInventory.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiInventory.java @@ -20,7 +20,9 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.GuiInventoryBackgroundDrawnEvent; import io.github.moulberry.notenoughupdates.listener.RenderListener; +import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiInventory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -36,4 +38,9 @@ public class MixinGuiInventory { ci.cancel(); } } + + @Inject(method = "drawGuiContainerBackgroundLayer", at = @At("TAIL")) + public void onDrawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY, CallbackInfo ci) { + new GuiInventoryBackgroundDrawnEvent((GuiContainer) (Object) this, partialTicks).post(); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java index dc59c0bb..7c2cfcbf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java @@ -25,6 +25,7 @@ import io.github.moulberry.notenoughupdates.core.ChromaColour; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCooldowns; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; +import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -195,7 +196,7 @@ public abstract class MixinRenderItem { @Inject(method = "renderItemIntoGUI", at = @At("HEAD")) public void renderItemHead(ItemStack stack, int x, int y, CallbackInfo ci) { - if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { + if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock() && !(Minecraft.getMinecraft().currentScreen instanceof GuiProfileViewer)) { boolean matches = false; GuiTextField textField = NotEnoughUpdates.INSTANCE.overlay.getTextField(); @@ -221,7 +222,7 @@ public abstract class MixinRenderItem { @Inject(method = "renderItemIntoGUI", at = @At("RETURN")) public void renderItemReturn(ItemStack stack, int x, int y, CallbackInfo ci) { if (stack != null && stack.stackSize != 1) return; - if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { + if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock() && !(Minecraft.getMinecraft().currentScreen instanceof GuiProfileViewer)) { boolean matches = false; GuiTextField textField = NotEnoughUpdates.INSTANCE.overlay.getTextField(); @@ -252,7 +253,7 @@ public abstract class MixinRenderItem { CallbackInfo ci ) { if (stack != null && stack.stackSize != 1) { - if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { + if (NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock() && !(Minecraft.getMinecraft().currentScreen instanceof GuiProfileViewer)) { boolean matches = false; GuiTextField textField = NotEnoughUpdates.INSTANCE.overlay.getTextField(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java index 8e0e4c11..50f459c0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java @@ -19,13 +19,55 @@ package io.github.moulberry.notenoughupdates.options.customtypes; +import io.github.moulberry.notenoughupdates.util.NEUDebugLogger; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + public enum NEUDebugFlag { // NOTE: Removing enum values causes gson to remove all debugFlags on load if any removed value is present - METAL, - WISHING, + METAL("Metal Detector Solver"), + WISHING("Wishing Compass Solver"), + MAP("Dungeon Map Player Information"), + SEARCH("SearchString Matches"), ; - public static final String FLAG_LIST = - "METAL - Metal Detector Solver\n" + - "WISHING - Wishing Compass Solver"; + private final String description; + + NEUDebugFlag(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public boolean isSet() { + return NEUDebugLogger.isFlagEnabled(this); + } + + public static String getFlagList() { + return renderFlagInformation(Arrays.asList(values())); + } + + public static String getEnabledFlags() { + return renderFlagInformation(Arrays.stream(values()) + .filter(NEUDebugFlag::isSet) + .collect(Collectors.toList())); + } + + public static String renderFlagInformation(List<NEUDebugFlag> flags) { + int maxNameLength = flags.stream() + .mapToInt(it -> it.name().length()) + .max() + .orElse(0); + return flags.stream() + .map(it -> (CharSequence) String.format( + "%-" + maxNameLength + "s" + " - %s", + it.name(), + it.getDescription() + )) + .collect(Collectors.joining("\n")); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/CustomArmour.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/CustomArmour.java index 6c47b7a6..d7f82a66 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/CustomArmour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/CustomArmour.java @@ -29,7 +29,8 @@ public class CustomArmour { @Expose @ConfigOption( name = "Enable Equipment Hud", - desc = "Shows an overlay in your inventory showing your 4 extra armour slots" + desc = "Shows an overlay in your inventory showing your 4 extra armour slots" + + "\u00A7cRequires Hide Potion Effects to be enabled" ) @ConfigEditorBoolean public boolean enableArmourHud = true; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/DungeonMapConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/DungeonMapConfig.java index 4397c02e..8e211bd6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/DungeonMapConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/DungeonMapConfig.java @@ -73,7 +73,7 @@ public class DungeonMapConfig { name = "Show Dungeon Map", desc = "Show/hide the NEU dungeon map" ) - public boolean dmEnable = false; + public boolean dmEnable = true; @Expose @ConfigOption( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Enchanting.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Enchanting.java index 2f3ffa36..b596d180 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Enchanting.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Enchanting.java @@ -28,7 +28,7 @@ import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption public class Enchanting { @ConfigOption( - name = "Enchant Table GUI", + name = "Enchant Table / Hex GUI", desc = "" ) @ConfigEditorAccordion(id = 1) @@ -43,6 +43,15 @@ public class Enchanting { @ConfigAccordionId(id = 1) public boolean enableTableGUI = true; + @Expose + @ConfigOption( + name = "Enable Hex GUI", + desc = "Show a custom GUI when using the Hex" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean enableHexGUI = true; + /*@Expose @ConfigOption( name = "Incompatible Enchants", @@ -76,6 +85,15 @@ public class Enchanting { @ConfigAccordionId(id = 1) public int enchantOrdering = 0; + @Expose + @ConfigOption( + name = "Use highest level from /et in /hex", + desc = "Show max level from /et in hex instead of highest possible" + ) + @ConfigEditorBoolean() + @ConfigAccordionId(id = 1) + public boolean maxEnchLevel = false; + @ConfigOption( name = "Enchanting Solvers", desc = "" @@ -114,7 +132,7 @@ public class Enchanting { @Expose @ConfigOption( name = "Ultrasequencer Numbers", - desc = "Replace the items in the supersequencer with only numbers" + desc = "Replace the items in the Ultrasequencer with only numbers" ) @ConfigEditorBoolean @ConfigAccordionId(id = 0) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Itemlist.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Itemlist.java index c83f370f..72a45930 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Itemlist.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Itemlist.java @@ -53,6 +53,15 @@ public class Itemlist { @Expose @ConfigOption( + name = "Open when searching", + desc = "Open the Itemlist when in container search mode by double clicking the search bar" + ) + @ConfigEditorBoolean + public boolean openWhenSearching = true; + + + @Expose + @ConfigOption( name = "Item Style", desc = "Sets the style of the background behind items" ) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index 84e2322e..c6f00182 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -229,4 +229,12 @@ public class Misc { @ConfigEditorBoolean public boolean abiphoneWarning = true; + @Expose + @ConfigOption( + name = "Enable Coop Warning", + desc = "Asks for confirmation when clicking the coop diamond in profile menu" + ) + @ConfigEditorBoolean + public boolean coopWarning = true; + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java index 4ad6767d..d73b5eb2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/CombatSkillOverlay.java @@ -82,6 +82,7 @@ public class CombatSkillOverlay public void update() { if (!NotEnoughUpdates.INSTANCE.config.skillOverlays.combatSkillOverlay) { kill = -1; + championXp = -1; overlayStrings = null; return; } @@ -91,6 +92,7 @@ public class CombatSkillOverlay championXpLast = championXp; xpGainHourLast = xpGainHour; kill = -1; + championXp = -1; if (Minecraft.getMinecraft().thePlayer == null) return; @@ -216,7 +218,7 @@ public class CombatSkillOverlay killQueue.removeLast(); } - if (kill != -1) { + if (kill != -1 || championXp != -1) { overlayStrings = new ArrayList<>(); } else { overlayStrings = null; @@ -228,7 +230,7 @@ public class CombatSkillOverlay public void updateFrequent() { super.updateFrequent(); - if ((kill < 0 || championXp < 0) && !NotEnoughUpdates.INSTANCE.config.skillOverlays.alwaysShowCombatOverlay) { + if ((kill < 0 && championXp < 0) && !NotEnoughUpdates.INSTANCE.config.skillOverlays.alwaysShowCombatOverlay) { overlayStrings = null; } else { HashMap<Integer, String> lineMap = new HashMap<>(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java new file mode 100644 index 00000000..e6e8cb3b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java @@ -0,0 +1,462 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.overlays; + +import com.google.common.collect.Lists; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.GuiInventoryBackgroundDrawnEvent; +import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; +import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; +import io.github.moulberry.notenoughupdates.options.NEUConfig; +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.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.Side; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class EquipmentOverlay { + public static EquipmentOverlay INSTANCE = new EquipmentOverlay(); + + // <editor-fold desc="resources"> + private static final ResourceLocation ARMOR_DISPLAY = new ResourceLocation( + "notenoughupdates:armordisplay/armordisplay.png"); + private static final ResourceLocation ARMOR_DISPLAY_GREY = new ResourceLocation( + "notenoughupdates:armordisplay/armordisplay_grey.png"); + private static final ResourceLocation ARMOR_DISPLAY_DARK = new ResourceLocation( + "notenoughupdates:armordisplay/armordisplay_phq_dark.png"); + private static final ResourceLocation ARMOR_DISPLAY_FSR = new ResourceLocation( + "notenoughupdates:armordisplay/armordisplay_fsr.png"); + private static final ResourceLocation ARMOR_DISPLAY_TRANSPARENT = new ResourceLocation( + "notenoughupdates:armordisplay/armordisplay_transparent.png"); + private static final ResourceLocation ARMOR_DISPLAY_TRANSPARENT_PET = new ResourceLocation( + "notenoughupdates:armordisplay/armordisplay_transparent_pet.png"); + + private static final ResourceLocation QUESTION_MARK = new ResourceLocation("notenoughupdates:pv_unknown.png"); + + private static final ResourceLocation PET_DISPLAY = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplaysolo.png"); + private static final ResourceLocation PET_DISPLAY_GREY = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplaysolo_dark.png"); + private static final ResourceLocation PET_DISPLAY_DARK = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplaysolo_phqdark.png"); + private static final ResourceLocation PET_DISPLAY_FSR = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplaysolo_fsr.png"); + private static final ResourceLocation PET_DISPLAY_TRANSPARENT = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplaysolo_transparent.png"); + + private static final ResourceLocation PET_ARMOR_DISPLAY = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplayarmor.png"); + private static final ResourceLocation PET_ARMOR_DISPLAY_GREY = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplayarmor_dark.png"); + private static final ResourceLocation PET_ARMOR_DISPLAY_DARK = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplayarmor_phqdark.png"); + private static final ResourceLocation PET_ARMOR_DISPLAY_FSR = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplayarmor_fsr.png"); + private static final ResourceLocation PET_ARMOR_DISPLAY_TRANSPARENT = new ResourceLocation( + "notenoughupdates:petdisplay/petdisplayarmor_transparent.png"); + //</editor-fold> + + //<editor-fold desc="dynamic resources"> + public ResourceLocation getCustomEquipmentTexture(boolean isPetRendering) { + switch (NotEnoughUpdates.INSTANCE.config.customArmour.colourStyle) { + case 0: + return ARMOR_DISPLAY; + case 1: + return ARMOR_DISPLAY_GREY; + case 2: + return ARMOR_DISPLAY_DARK; + case 3: + return NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 3 && isPetRendering ? ARMOR_DISPLAY_TRANSPARENT_PET : ARMOR_DISPLAY_TRANSPARENT; + case 4: + return ARMOR_DISPLAY_FSR; + } + return null; + } + + public ResourceLocation getCustomPetTexture(boolean isArmorRendering) { + switch (NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle) { + case 0: + return isArmorRendering ? PET_ARMOR_DISPLAY : PET_DISPLAY; + case 1: + return isArmorRendering ? PET_ARMOR_DISPLAY_GREY : PET_DISPLAY_GREY; + case 2: + return isArmorRendering ? PET_ARMOR_DISPLAY_DARK : PET_DISPLAY_DARK; + case 3: + return isArmorRendering ? PET_ARMOR_DISPLAY_TRANSPARENT : PET_DISPLAY_TRANSPARENT; + case 4: + return isArmorRendering ? PET_ARMOR_DISPLAY_FSR : PET_DISPLAY_FSR; + } + return null; + } + //</editor-fold> + + //<editor-fold desc="pixel constants"> + public static final int EQUIPMENT_SLOT_OFFSET_Y = 8; + public static final int ARMOR_OVERLAY_OVERHAND_WIDTH = 24; + public static final int ARMOR_OVERLAY_HEIGHT = 86; + public static final int ARMOR_OVERLAY_WIDTH = 31; + final static int PET_OVERLAY_HEIGHT = 32; + final static int PET_OVERLAY_WIDTH = 31; + public static final int PET_OVERLAY_OFFSET_Y = ARMOR_OVERLAY_HEIGHT - 14 /* overlaying pixels */; + //</editor-fold> + + public boolean isRenderingPet; + + public boolean shouldRenderPets; + public boolean shouldRenderArmorHud; + + public ItemStack petStack; + + //<editor-fold desc="events"> + + @SubscribeEvent + public void onGuiTick(TickEvent.ClientTickEvent event) { + if (event.phase != TickEvent.Phase.START || event.side != Side.CLIENT) return; + updateGuiInfo(Minecraft.getMinecraft().currentScreen); + } + + @SubscribeEvent + public void onGuiInit(GuiScreenEvent.InitGuiEvent event) { + updateGuiInfo(event.gui); + } + + @SubscribeEvent + public void onRenderGuiPost(GuiInventoryBackgroundDrawnEvent event) { + if (!(event.getContainer() instanceof GuiInventory)) return; + GuiInventory inventory = ((GuiInventory) event.getContainer()); + renderGuis(inventory); + } + + //</editor-fold> + + public void renderGuis(GuiInventory inventory) { + int width = Utils.peekGuiScale().getScaledWidth(); + int height = Utils.peekGuiScale().getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + GL11.glColor4f(1F, 1F, 1F, 1F); + if (shouldRenderArmorHud) { + renderEquipmentGui(inventory, mouseX, mouseY, width, height); + } + + if (shouldRenderPets) { + renderPets(inventory, mouseX, mouseY, width, height); + } + } + + public void renderEquipmentGui(GuiInventory guiScreen, int mouseX, int mouseY, int width, int height) { + AccessorGuiContainer container = ((AccessorGuiContainer) guiScreen); + + int overlayLeft = container.getGuiLeft() - ARMOR_OVERLAY_OVERHAND_WIDTH; + int overlayTop = container.getGuiTop(); + + ResourceLocation equipmentTexture = getCustomEquipmentTexture(shouldRenderPets); + Minecraft.getMinecraft().getTextureManager().bindTexture(equipmentTexture); + + Utils.drawTexturedRect(overlayLeft, overlayTop, ARMOR_OVERLAY_WIDTH, ARMOR_OVERLAY_HEIGHT, GL11.GL_NEAREST); + + List<String> tooltipToDisplay = new ArrayList<>(); + drawSlot(slot1, overlayLeft + 8, overlayTop + EQUIPMENT_SLOT_OFFSET_Y, mouseX, mouseY, tooltipToDisplay); + drawSlot(slot2, overlayLeft + 8, overlayTop + EQUIPMENT_SLOT_OFFSET_Y + 18, mouseX, mouseY, tooltipToDisplay); + drawSlot(slot3, overlayLeft + 8, overlayTop + EQUIPMENT_SLOT_OFFSET_Y + 36, mouseX, mouseY, tooltipToDisplay); + drawSlot(slot4, overlayLeft + 8, overlayTop + EQUIPMENT_SLOT_OFFSET_Y + 54, mouseX, mouseY, tooltipToDisplay); + + if (slot1 == null) { + Minecraft.getMinecraft().getTextureManager().bindTexture(QUESTION_MARK); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(overlayLeft + 8, overlayTop + EQUIPMENT_SLOT_OFFSET_Y, 16, 16, GL11.GL_NEAREST); + + tooltipToDisplay = Lists.newArrayList( + EnumChatFormatting.RED + "Warning", + EnumChatFormatting.GREEN + "You need to open /equipment", + EnumChatFormatting.GREEN + "to cache your armour" + ); + if (Utils.isWithinRect(mouseX, mouseY, overlayLeft + 8, overlayTop + 8, 16, 16) + && NotEnoughUpdates.INSTANCE.config.customArmour.sendWardrobeCommand + && Mouse.getEventButtonState() + && Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null) { + NotEnoughUpdates.INSTANCE.trySendCommand("/equipment"); + } + + } + if (tooltipToDisplay.size() > 0 && + Utils.isWithinRect( + mouseX, mouseY, + overlayLeft, overlayTop, + ARMOR_OVERLAY_OVERHAND_WIDTH, ARMOR_OVERLAY_HEIGHT + )) { + Utils.drawHoveringText( + tooltipToDisplay, + mouseX - calculateTooltipXOffset(tooltipToDisplay, Minecraft.getMinecraft().fontRendererObj), + mouseY, + width, + height, + -1, + Minecraft.getMinecraft().fontRendererObj + ); + } + + } + + private ItemStack getRepoPetStack() { + NEUManager manager = NotEnoughUpdates.INSTANCE.manager; + PetInfoOverlay.Pet currentPet = PetInfoOverlay.getCurrentPet(); + if (currentPet == null) return null; + + ItemStack item = ItemUtils.createPetItemstackFromPetInfo(currentPet); + item = ItemUtils.petToolTipXPExtendPetOverlay(item); + + if (item != null) { + return item; + } + item = manager.createItem(currentPet.getPetId(true)); + return item; + } + + private void updateGuiInfo(GuiScreen screen) { + if (getWardrobeSlot(10) != null) { + slot1 = getWardrobeSlot(10); + slot2 = getWardrobeSlot(19); + slot3 = getWardrobeSlot(28); + slot4 = getWardrobeSlot(37); + } + + if ((screen instanceof GuiChest || screen instanceof GuiInventory) && NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay){ + petStack = getRepoPetStack(); + } + if ((!(screen instanceof GuiInventory) && !(screen instanceof GuiInvButtonEditor)) + || !NotEnoughUpdates.INSTANCE.config.misc.hidePotionEffect + || !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + shouldRenderPets = shouldRenderArmorHud = false; + return; + } + shouldRenderPets = NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay && petStack != null; + shouldRenderArmorHud = NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud; + } + + private void drawSlot(ItemStack stack, int x, int y, int mouseX, int mouseY, List<String> tooltip) { + if (stack == null) return; + Utils.drawItemStack(stack, x, y, true); + if (Utils.isWithinRect(mouseX, mouseY, x, y, 16, 16)) { + List<String> tt = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + if (shouldShowEquipmentTooltip(tt)) + tooltip.addAll(tt); + if (NotEnoughUpdates.INSTANCE.config.customArmour.sendWardrobeCommand + && Mouse.getEventButtonState()) { + NotEnoughUpdates.INSTANCE.trySendCommand("/equipment"); + } + } + } + + public void renderPets(GuiInventory inventory, int mouseX, int mouseY, int width, int height) { + ItemUtils.getOrCreateTag(petStack).setBoolean( + "NEUHIDEPETTOOLTIP", + NotEnoughUpdates.INSTANCE.config.petOverlay.hidePetTooltip + ); + ItemStack petInfo = petStack; + + ResourceLocation customPetTexture = getCustomPetTexture(isRenderingArmorHud()); + Minecraft.getMinecraft().getTextureManager().bindTexture(customPetTexture); + GlStateManager.color(1, 1, 1, 1); + + AccessorGuiContainer container = ((AccessorGuiContainer) inventory); + + int overlayLeft = container.getGuiLeft() - ARMOR_OVERLAY_OVERHAND_WIDTH; + int overlayTop = container.getGuiTop() + PET_OVERLAY_OFFSET_Y; + + Utils.drawTexturedRect(overlayLeft, overlayTop, PET_OVERLAY_WIDTH, PET_OVERLAY_HEIGHT, GL11.GL_NEAREST); + GlStateManager.bindTexture(0); + + Utils.drawItemStack(petInfo, overlayLeft + 8, overlayTop + 8, true); + + List<String> tooltipToDisplay; + if (Utils.isWithinRect(mouseX, mouseY, overlayLeft + 8, overlayTop + 8, 16, 16)) { + if (NotEnoughUpdates.INSTANCE.config.petOverlay.sendPetsCommand + && Minecraft.getMinecraft().thePlayer.inventory.getItemStack() == null + && Mouse.getEventButtonState()) { + NotEnoughUpdates.INSTANCE.trySendCommand("/pets"); + } + tooltipToDisplay = petInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false); + Utils.drawHoveringText( + tooltipToDisplay, + mouseX - calculateTooltipXOffset(tooltipToDisplay, Minecraft.getMinecraft().fontRendererObj), + mouseY, + width, + height, + -1, + Minecraft.getMinecraft().fontRendererObj + ); + } + } + + private ItemStack getWardrobeSlot(int armourSlot) { + if (SBInfo.getInstance().currentProfile == null) { + return null; + } + + if (!Objects.equals(SBInfo.getInstance().currentProfile, lastProfile)) { + lastProfile = SBInfo.getInstance().currentProfile; + slot1 = null; + slot2 = null; + slot3 = null; + slot4 = null; + } + + NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (profileSpecific == null) return null; + + if (isInNamedGui("Your Equipment")) { + ItemStack itemStack = getChestSlotsAsItemStack(armourSlot); + if (itemStack != null) { + JsonObject itemToSave = NotEnoughUpdates.INSTANCE.manager.getJsonForItem(itemStack); + if (!itemToSave.has("internalname")) { + //would crash without internalName when trying to construct the ItemStack again + itemToSave.add("internalname", new JsonPrimitive("_")); + } + profileSpecific.savedEquipment.put(armourSlot, itemToSave); + return itemStack; + } + } else { + if (profileSpecific.savedEquipment.containsKey(armourSlot)) { + //don't use cache since the internalName is identical in most cases + JsonObject jsonObject = profileSpecific.savedEquipment + .get(armourSlot); + if (jsonObject != null) return NotEnoughUpdates.INSTANCE.manager.jsonToStack(jsonObject + .getAsJsonObject(), false); + } + } + return null; + } + + private boolean wardrobeOpen = false; + + private boolean isInNamedGui(String guiName) { + GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; + if (guiScreen instanceof GuiChest) { + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest container = (ContainerChest) chest.inventorySlots; + IInventory lower = container.getLowerChestInventory(); + String containerName = lower.getDisplayName().getUnformattedText(); + wardrobeOpen = containerName.contains(guiName); + } + if (guiScreen instanceof GuiInventory) { + wardrobeOpen = false; + } + return wardrobeOpen; + } + + private ItemStack getChestSlotsAsItemStack(int slot) { + GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; + if (guiScreen instanceof GuiChest) { + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + return chest.inventorySlots.getSlot(slot).getStack(); + } else { + return null; + } + } + + public static boolean isRenderingArmorHud() { + return INSTANCE.shouldRenderArmorHud; + } + + public static boolean isRenderingPetHud() { + return INSTANCE.shouldRenderPets; + } + + private boolean shouldShowEquipmentTooltip(List<String> toolTip) { + return !toolTip.get(0).equals("§o§7Empty Equipment Slot§r"); + } + + /** + * Calculates the width of the longest String in the tooltip, which can be used to offset the entire tooltip to the left more precisely + * + * @param tooltipToDisplay tooltip + * @param fr FontRenderer object + * @return offset to apply + */ + private int calculateTooltipXOffset(List<String> tooltipToDisplay, FontRenderer fr) { + int offset = 0; + if (tooltipToDisplay != null) { + for (String line : tooltipToDisplay) { + int lineWidth = fr.getStringWidth(line); + if (lineWidth > offset) { + offset = lineWidth; + } + } + } + return offset + 20; + } + + public void renderPreviewArmorHud() { + if (!NotEnoughUpdates.INSTANCE.config.customArmour.enableArmourHud || !(Minecraft.getMinecraft().currentScreen instanceof GuiInvButtonEditor)) return; + GuiInvButtonEditor container = (GuiInvButtonEditor) Minecraft.getMinecraft().currentScreen; + + int overlayLeft = container.getGuiLeft() - ARMOR_OVERLAY_OVERHAND_WIDTH; + int overlayTop = container.getGuiTop(); + + ResourceLocation equipmentTexture = getCustomEquipmentTexture(shouldRenderPets); + Minecraft.getMinecraft().getTextureManager().bindTexture(equipmentTexture); + + Utils.drawTexturedRect(overlayLeft, overlayTop, ARMOR_OVERLAY_WIDTH, ARMOR_OVERLAY_HEIGHT, GL11.GL_NEAREST); + } + + public void renderPreviewPetInvHud() { + if (!NotEnoughUpdates.INSTANCE.config.petOverlay.petInvDisplay || !(Minecraft.getMinecraft().currentScreen instanceof GuiInvButtonEditor)) return; + GuiInvButtonEditor container = (GuiInvButtonEditor) Minecraft.getMinecraft().currentScreen; + int overlayLeft = container.getGuiLeft() - ARMOR_OVERLAY_OVERHAND_WIDTH; + int overlayTop = container.getGuiTop() + PET_OVERLAY_OFFSET_Y; + + ResourceLocation petHudTexture = getCustomPetTexture(shouldRenderArmorHud); + Minecraft.getMinecraft().getTextureManager().bindTexture(petHudTexture); + + Utils.drawTexturedRect(overlayLeft, overlayTop, PET_OVERLAY_WIDTH, PET_OVERLAY_HEIGHT, GL11.GL_NEAREST); + } + + public ItemStack slot1 = null; + public ItemStack slot2 = null; + public ItemStack slot3 = null; + public ItemStack slot4 = null; + private String lastProfile; + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index d24f005d..03fe9eff 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -806,6 +806,7 @@ public class MiningOverlay extends TextTabOverlay { .getItemInformation() .get("ANVIL")) ); + put("First Event", new ItemStack(Items.fireworks, 1, 0)); }}; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java index 69a0cd00..fa263db7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextTabOverlay.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.overlays; import io.github.moulberry.notenoughupdates.core.config.Position; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiChat; import org.lwjgl.input.Keyboard; import java.util.List; @@ -36,12 +37,43 @@ public abstract class TextTabOverlay extends TextOverlay { } private boolean lastTabState = false; + private boolean shouldUpdateOverlay = true; - public void realTick() { - boolean currentTabState = Keyboard.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindPlayerList.getKeyCode()); - if (lastTabState != currentTabState) { - lastTabState = currentTabState; + @Override + public void tick() { + if (shouldUpdateOverlay) { update(); } } + + public void realTick() { + shouldUpdateOverlay = shouldUpdate(); + if (shouldUpdateOverlay) { + int keycode = Minecraft.getMinecraft().gameSettings.keyBindPlayerList.getKeyCode(); + boolean currentTabState; + if (keycode > 0) { + currentTabState = Keyboard.isKeyDown(keycode); + } else { + currentTabState = false; + } + if (lastTabState != currentTabState) { + lastTabState = currentTabState; + update(); + } + } + } + + private boolean shouldUpdate() { + //prevent rendering when tab completing a command + if (Minecraft.getMinecraft().currentScreen instanceof GuiChat) { + return false; + } + + //prevent rendering when tab completing in ah search overlay + if (AuctionSearchOverlay.shouldReplace()) { + return false; + } + + return true; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index 86df47ff..4d82ebaf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -660,7 +660,7 @@ public class TimersOverlay extends TextTabOverlay { 6, DARK_AQUA + "Experiments: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.verySoonColour] + - Utils.prettyTime(catacombsReset) + Utils.prettyTime(catacombsReset + 86400000 - currentTime) ); } else if (NotEnoughUpdates.INSTANCE.config.miscOverlays.experimentationDisplay >= DISPLAYTYPE.SOON.ordinal() && (hidden.experimentsCompleted < (midnightReset - TimeEnums.HOUR.time))) { @@ -668,7 +668,7 @@ public class TimersOverlay extends TextTabOverlay { 6, DARK_AQUA + "Experiments: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.soonColour] + - Utils.prettyTime(catacombsReset) + Utils.prettyTime(catacombsReset + 86400000 - currentTime) ); } else if ( NotEnoughUpdates.INSTANCE.config.miscOverlays.experimentationDisplay >= DISPLAYTYPE.KINDASOON.ordinal() && @@ -677,14 +677,14 @@ public class TimersOverlay extends TextTabOverlay { 6, DARK_AQUA + "Experiments: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.kindaSoonColour] + - Utils.prettyTime(catacombsReset) + Utils.prettyTime(catacombsReset + 86400000 - currentTime) ); } else if (NotEnoughUpdates.INSTANCE.config.miscOverlays.experimentationDisplay >= DISPLAYTYPE.ALWAYS.ordinal()) { map.put( 6, DARK_AQUA + "Experiments: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.defaultColour] + - Utils.prettyTime(catacombsReset) + Utils.prettyTime(catacombsReset + 86400000 - currentTime) ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java index c707f7fc..15a70ded 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/DungeonPage.java @@ -196,9 +196,9 @@ public class DungeonPage extends GuiProfileViewerPage { if (F7 > 50) { F7 = 50; } - float xpF5 = 2000 * (F5 / 100 + 1); - float xpF6 = 4000 * (F6 / 100 + 1); - float xpF7 = 20000 * (F7 / 100 + 1); + float xpF5 = 2400 * (F5 / 100 + 1); + float xpF6 = 4880 * (F6 / 100 + 1); + float xpF7 = 28000 * (F7 / 100 + 1); if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { xpF5 *= 1.1; xpF6 *= 1.1; @@ -306,6 +306,13 @@ public class DungeonPage extends GuiProfileViewerPage { 0 ) ); + float M7 = + ( + Utils.getElementAsFloat( + Utils.getElement(profileInfo, "dungeons.dungeon_types.master_catacombs.tier_completions." + 7), + 0 + ) + ); if (M3 > 50) { M3 = 50; } @@ -318,22 +325,28 @@ public class DungeonPage extends GuiProfileViewerPage { if (M6 > 50) { M6 = 50; } - float xpM3 = 36500 * (M3 / 100 + 1); - float xpM4 = 48500 * (M4 / 100 + 1); + if (M7 > 50) { + M7 = 50; + } + float xpM3 = 35000 * (M3 / 100 + 1); + float xpM4 = 55000 * (M4 / 100 + 1); float xpM5 = 70000 * (M5 / 100 + 1); float xpM6 = 100000 * (M6 / 100 + 1); + float xpM7 = 300000 * (M7 / 100 + 1); //No clue if M3 or M4 xp values are right if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { xpM3 *= 1.1; xpM4 *= 1.1; xpM5 *= 1.1; xpM6 *= 1.1; + xpM7 *= 1.1; } long runsM3 = (int) Math.ceil(floorLevelToXP / xpM3); long runsM4 = (int) Math.ceil(floorLevelToXP / xpM4); long runsM5 = (int) Math.ceil(floorLevelToXP / xpM5); long runsM6 = (int) Math.ceil(floorLevelToXP / xpM6); + long runsM7 = (int) Math.ceil(floorLevelToXP / xpM7); float timeM3 = Utils.getElementAsFloat( Utils.getElement(profileInfo, "dungeons.dungeon_types.master_catacombs.fastest_time_s_plus.3"), @@ -351,6 +364,10 @@ public class DungeonPage extends GuiProfileViewerPage { Utils.getElement(profileInfo, "dungeons.dungeon_types.master_catacombs.fastest_time_s_plus.6"), 0 ); + float timeM7 = Utils.getElementAsFloat( + Utils.getElement(profileInfo, "dungeons.dungeon_types.master_catacombs.fastest_time_s_plus.7"), + 0 + ); getInstance().tooltipToDisplay = Lists.newArrayList( @@ -358,6 +375,7 @@ public class DungeonPage extends GuiProfileViewerPage { String.format("# M4 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM4), runsM4), String.format("# M5 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM5), runsM5), String.format("# M6 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM6), runsM6), + String.format("# M7 Runs (%s xp) : %d", StringUtils.shortNumberFormat(xpM7), runsM7), "" ); boolean hasTime = false; @@ -381,6 +399,11 @@ public class DungeonPage extends GuiProfileViewerPage { .tooltipToDisplay.add(String.format("Expected Time (M6) : %s", Utils.prettyTime(runsM6 * (long) (timeM6 * 1.2)))); hasTime = true; } + if (timeM7 > 1000) { + getInstance() + .tooltipToDisplay.add(String.format("Expected Time (M7) : %s", Utils.prettyTime(runsM7 * (long) (timeM7 * 1.2)))); + hasTime = true; + } if (hasTime) { getInstance().tooltipToDisplay.add(""); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java index 0f9d1b4a..8576f141 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -61,6 +61,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -749,6 +750,30 @@ public class GuiProfileViewer extends GuiScreen { lastTime = currentTime; + if (currentPage != ProfileViewerPage.LOADING && currentPage != ProfileViewerPage.INVALID_NAME) { + int ignoredTabs = 0; + List<Integer> configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; + for (int i = 0; i < configList.size(); i++) { + ProfileViewerPage iPage = ProfileViewerPage.getById(configList.get(i)); + if (iPage == null) continue; + if (iPage.stack == null || (iPage == ProfileViewerPage.BINGO && !showBingoPage)) { + ignoredTabs++; + continue; + } + int i2 = i - ignoredTabs; + int x = guiLeft + i2 * 28; + int y = guiTop - 28; + + if (mouseX > x && mouseX < x + 28) { + if (mouseY > y && mouseY < y + 32) { + tooltipToDisplay = Collections.singletonList(iPage.stack + .getTooltip(Minecraft.getMinecraft().thePlayer, false) + .get(0)); + } + } + } + } + if (tooltipToDisplay != null) { List<String> grayTooltip = new ArrayList<>(tooltipToDisplay.size()); for (String line : tooltipToDisplay) { @@ -1232,16 +1257,16 @@ public class GuiProfileViewer extends GuiScreen { LOADING(), INVALID_NAME(), NO_SKYBLOCK(), - BASIC(0, Items.paper, "Your Skills"), - DUNGEON(1, Item.getItemFromBlock(Blocks.deadbush), "Dungeoneering"), - EXTRA(2, Items.book, "Profile Stats"), - INVENTORIES(3, Item.getItemFromBlock(Blocks.ender_chest), "Storage"), - COLLECTIONS(4, Items.painting, "Collections"), - PETS(5, Items.bone, "Pets"), - MINING(6, Items.iron_pickaxe, "Heart of the Mountain"), - BINGO(7, Items.filled_map, "Bingo"), - TROPHY_FISH(8, Items.fishing_rod, "Trophy Fish"), - BESTIARY(9, Items.iron_sword, "Bestiary"); + BASIC(0, Items.paper, "§9Your Skills"), + DUNGEON(1, Item.getItemFromBlock(Blocks.deadbush), "§eDungeoneering"), + EXTRA(2, Items.book, "§7Profile Stats"), + INVENTORIES(3, Item.getItemFromBlock(Blocks.ender_chest), "§bStorage"), + COLLECTIONS(4, Items.painting, "§6Collections"), + PETS(5, Items.bone, "§aPets"), + MINING(6, Items.iron_pickaxe, "§5Heart of the Mountain"), + BINGO(7, Items.filled_map, "§zBingo"), + TROPHY_FISH(8, Items.fishing_rod, "§3Trophy Fish"), + BESTIARY(9, Items.iron_sword, "§cBestiary"); public final ItemStack stack; public final int id; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java index c98792ee..b4f1da30 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/InventoriesPage.java @@ -240,28 +240,6 @@ public class InventoriesPage extends GuiProfileViewerPage { if (currentInventoryIndex < 0) currentInventoryIndex = 0; ItemStack[][] inventory = inventories[currentInventoryIndex]; - if (inventory == null) { - if (selectedInventory.equalsIgnoreCase("personal_vault_contents")) { - Utils.drawStringCentered( - EnumChatFormatting.RED + "Personal Vault API not enabled!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 317, - guiTop + 101, - true, - 0 - ); - } else { - Utils.drawStringCentered( - EnumChatFormatting.RED + "Inventory API not enabled!", - Minecraft.getMinecraft().fontRendererObj, - guiLeft + 317, - guiTop + 101, - true, - 0 - ); - } - return; - } if (bestWeapons == null) { bestWeapons = @@ -363,6 +341,32 @@ public class InventoriesPage extends GuiProfileViewerPage { } } + if (inventory == null) { + String strToRender = "Inventory API not enabled!"; + if (selectedInventory.equalsIgnoreCase("personal_vault_contents")) { + strToRender = "Personal Vault API not enabled!"; + } else if (selectedInventory.equalsIgnoreCase("backpack_contents")) { + strToRender = "Inventory API not enabled"; + Utils.drawStringCentered( + EnumChatFormatting.RED + "Or has no backpacks!", + Minecraft.getMinecraft().fontRendererObj, + guiLeft + 317, + guiTop + 112, + true, + 0 + ); + } + Utils.drawStringCentered( + EnumChatFormatting.RED + strToRender, + Minecraft.getMinecraft().fontRendererObj, + guiLeft + 317, + guiTop + 101, + true, + 0 + ); + return; + } + int inventoryRows = inventory.length; GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java index c32310b7..94dbdc1e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/MiningPage.java @@ -868,8 +868,7 @@ public class MiningPage extends GuiProfileViewerPage { "Seasoned Mineman", "§7Level " + seasonMine + "§8/100", "", - "§7Increases your Mining", - "§7experience gain by " + EnumChatFormatting.GREEN + seasonMineStat + "%§7.", + "§7Grants §3+" + EnumChatFormatting.DARK_AQUA + seasonMineStat + "☯ Mining Wisdom§7.", "", EnumChatFormatting.GRAY + "Cost", EnumChatFormatting.DARK_GREEN + @@ -881,8 +880,7 @@ public class MiningPage extends GuiProfileViewerPage { "Seasoned Mineman", "§7Level " + seasonMine + "§8/100", "", - "§7Increases your Mining", - "§7experience gain by " + EnumChatFormatting.GREEN + seasonMineStat + "%§7." + "§7Grants §3+" + EnumChatFormatting.DARK_AQUA + seasonMineStat + "☯ Mining Wisdom§7." ), 100 ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java index 25751ab8..cb85bf79 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PetsPage.java @@ -22,22 +22,17 @@ package io.github.moulberry.notenoughupdates.profileviewer; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.util.Constants; +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.GuiScreen; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.init.Items; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.JsonToNBT; -import net.minecraft.nbt.NBTException; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; @@ -46,11 +41,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.IOException; import java.util.ArrayList; -import java.util.Base64; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.UUID; public class PetsPage extends GuiProfileViewerPage { @@ -91,7 +82,8 @@ public class PetsPage extends GuiProfileViewerPage { String panoramaIdentifier = "day"; if (SBInfo.getInstance().currentTimeDate != null) { - if (SBInfo.getInstance().currentTimeDate.getHours() <= 6 || SBInfo.getInstance().currentTimeDate.getHours() >= 20) { + if (SBInfo.getInstance().currentTimeDate.getHours() <= 6 || + SBInfo.getInstance().currentTimeDate.getHours() >= 20) { panoramaIdentifier = "night"; } } @@ -123,201 +115,22 @@ public class PetsPage extends GuiProfileViewerPage { } }); for (JsonObject pet : sortedPets) { - String petname = pet.get("type").getAsString(); - String tier = pet.get("tier").getAsString(); - String heldItem = Utils.getElementAsString(pet.get("heldItem"), null); - String skin = Utils.getElementAsString(pet.get("skin"), null); - int candy = pet.get("candyUsed").getAsInt(); - JsonObject heldItemJson = heldItem == null ? null : NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(heldItem); - String tierNum = GuiProfileViewer.MINION_RARITY_TO_NUM.get(tier); - float exp = pet.get("exp").getAsFloat(); - if (tierNum == null) continue; - - if ( - pet.has("heldItem") && - !pet.get("heldItem").isJsonNull() && - pet.get("heldItem").getAsString().equals("PET_ITEM_TIER_BOOST") - ) { - tierNum = "" + (Integer.parseInt(tierNum) + 1); - } - - GuiProfileViewer.PetLevel levelObj = GuiProfileViewer.getPetLevel(petname, tier, exp); - - float level = levelObj.level; - float currentLevelRequirement = levelObj.currentLevelRequirement; - float maxXP = levelObj.maxXP; - pet.addProperty("level", level); - pet.addProperty("currentLevelRequirement", currentLevelRequirement); - pet.addProperty("maxXP", maxXP); - - JsonObject petItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(petname + ";" + tierNum); - ItemStack stack; - if (petItem == null) { - stack = getQuestionmarkSkull(); - NBTTagCompound display = new NBTTagCompound(); - if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("display")) { - display = stack.getTagCompound().getCompoundTag("display"); - } - NBTTagList lore = new NBTTagList(); - lore.appendTag(new NBTTagString(EnumChatFormatting.RED + "This pet is not saved in the repository")); - lore.appendTag(new NBTTagString("")); - lore.appendTag(new NBTTagString(EnumChatFormatting.RED + "If you expected it to be there please send a message in")); - lore.appendTag( - new NBTTagString( - EnumChatFormatting.RED.toString() + - EnumChatFormatting.BOLD + - "#neu-support " + - EnumChatFormatting.RESET + - EnumChatFormatting.RED + - "on " + - EnumChatFormatting.BOLD + - "discord.gg/moulberry" - ) - ); - - display.setTag("Lore", lore); - NBTTagCompound tag = stack.getTagCompound() != null ? stack.getTagCompound() : new NBTTagCompound(); - tag.setTag("display", display); - stack.setTagCompound(tag); - } else { - stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(petItem, false, false); - HashMap<String, String> replacements = NotEnoughUpdates.INSTANCE.manager.getLoreReplacements( - petname, - tier, - (int) Math.floor(level) - ); - - if (heldItem != null) { - HashMap<String, Float> petStatBoots = GuiProfileViewer.PET_STAT_BOOSTS.get(heldItem); - HashMap<String, Float> petStatBootsMult = GuiProfileViewer.PET_STAT_BOOSTS_MULT.get(heldItem); - if (petStatBoots != null) { - for (Map.Entry<String, Float> entryBoost : petStatBoots.entrySet()) { - try { - float value = Float.parseFloat(replacements.get(entryBoost.getKey())); - replacements.put(entryBoost.getKey(), String.valueOf((int) Math.floor(value + entryBoost.getValue()))); - } catch (Exception ignored) {} - } - } - if (petStatBootsMult != null) { - for (Map.Entry<String, Float> entryBoost : petStatBootsMult.entrySet()) { - try { - float value = Float.parseFloat(replacements.get(entryBoost.getKey())); - replacements.put(entryBoost.getKey(), String.valueOf((int) Math.floor(value * entryBoost.getValue()))); - } catch (Exception ignored) {} - } - } - } - - NBTTagCompound tag = stack.getTagCompound() == null ? new NBTTagCompound() : stack.getTagCompound(); - if (tag.hasKey("display", 10)) { - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList newLore = new NBTTagList(); - NBTTagList lore = display.getTagList("Lore", 8); - HashMap<Integer, Integer> blankLocations = new HashMap<>(); - for (int j = 0; j < lore.tagCount(); j++) { - String line = lore.getStringTagAt(j); - if (line.trim().isEmpty()) { - blankLocations.put(blankLocations.size(), j); - } - for (Map.Entry<String, String> replacement : replacements.entrySet()) { - line = line.replace("{" + replacement.getKey() + "}", replacement.getValue()); - } - newLore.appendTag(new NBTTagString(line)); - } - Integer secondLastBlank = blankLocations.get(blankLocations.size() - 2); - if (skin != null) { - JsonObject petSkin = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("PET_SKIN_" + skin); - if (petSkin != null) { - try { - NBTTagCompound nbt = JsonToNBT.getTagFromJson(petSkin.get("nbttag").getAsString()); - tag.setTag("SkullOwner", nbt.getTag("SkullOwner")); - String name = petSkin.get("displayname").getAsString(); - if (name != null) { - name = Utils.cleanColour(name); - newLore.set(0, new NBTTagString(newLore.get(0).toString().replace("\"", "") + ", " + name)); - } - } catch (NBTException e) { - e.printStackTrace(); - } - } - } - for (int i = 0; i < newLore.tagCount(); i++) { - String cleaned = Utils.cleanColour(newLore.get(i).toString()); - if (cleaned.equals("\"Right-click to add this pet to\"")) { - newLore.removeTag(i + 1); - newLore.removeTag(i); - secondLastBlank = i - 1; - break; - } - } - NBTTagList temp = new NBTTagList(); - for (int i = 0; i < newLore.tagCount(); i++) { - temp.appendTag(newLore.get(i)); - if (secondLastBlank != null && i == secondLastBlank) { - if (heldItem != null) { - temp.appendTag( - new NBTTagString( - EnumChatFormatting.GOLD + "Held Item: " + heldItemJson.get("displayname").getAsString() - ) - ); - int blanks = 0; - JsonArray heldItemLore = heldItemJson.get("lore").getAsJsonArray(); - for (int k = 0; k < heldItemLore.size(); k++) { - String heldItemLine = heldItemLore.get(k).getAsString(); - if (heldItemLine.trim().isEmpty()) { - blanks++; - } else if (blanks == 2) { - temp.appendTag(new NBTTagString(heldItemLine)); - } else if (blanks > 2) { - break; - } - } - temp.appendTag(new NBTTagString()); - } - if (candy != 0) { - temp.appendTag(new NBTTagString(EnumChatFormatting.GREEN + "(" + candy + "/10) Pet Candy Used")); - temp.appendTag(new NBTTagString()); - } - temp.removeTag(temp.tagCount() - 1); - } - } - newLore = temp; - display.setTag("Lore", newLore); - } - if (display.hasKey("Name", 8)) { - String displayName = display.getString("Name"); - for (Map.Entry<String, String> replacement : replacements.entrySet()) { - displayName = displayName.replace("{" + replacement.getKey() + "}", replacement.getValue()); - } - display.setTag("Name", new NBTTagString(displayName)); - } - tag.setTag("display", display); - } - - // Adds the missing pet fields to the tag - NBTTagCompound extraAttributes = new NBTTagCompound(); - JsonObject petInfo = new JsonObject(); - if(tag.hasKey("ExtraAttributes", 10)) { - extraAttributes = tag.getCompoundTag("ExtraAttributes"); - if (extraAttributes.hasKey("petInfo", 8)) { - petInfo = new JsonParser().parse(extraAttributes.getString("petInfo")).getAsJsonObject(); - } - } - petInfo.addProperty("exp", exp); - petInfo.addProperty("tier", tier); - petInfo.addProperty("type", petname); - if (heldItem != null) { - petInfo.addProperty("heldItem", heldItem); - } - if (skin != null) { - petInfo.addProperty("skin", skin); - } - extraAttributes.setString("petInfo", petInfo.toString()); - tag.setTag("ExtraAttributes", extraAttributes); - stack.setTagCompound(tag); - } - sortedPetsStack.add(stack); + PetInfoOverlay.Pet parsedPet = new PetInfoOverlay.Pet(); + parsedPet.petType = pet.get("type").getAsString(); + parsedPet.rarity = PetInfoOverlay.Rarity.valueOf(pet.get("tier").getAsString()); + parsedPet.petLevel = GuiProfileViewer.getPetLevel( + parsedPet.petType, + parsedPet.rarity.name(), + pet.get("exp").getAsFloat() + ); + parsedPet.petXpType = "unknown"; + parsedPet.petItem = Utils.getElementAsString(pet.get("heldItem"), null); + parsedPet.skin = Utils.getElementAsString(pet.get("skin"), null); + parsedPet.candyUsed = pet.get("candyUsed").getAsInt(); + sortedPetsStack.add(ItemUtils.createPetItemstackFromPetInfo(parsedPet)); + pet.addProperty("level", parsedPet.petLevel.level); + pet.addProperty("currentLevelRequirement", parsedPet.petLevel.currentLevelRequirement); + pet.addProperty("maxXP", parsedPet.petLevel.maxXP); } } @@ -396,7 +209,11 @@ public class PetsPage extends GuiProfileViewerPage { ); } - for (int i = petsPage * 20; i < Math.min(petsPage * 20 + 20, Math.min(sortedPetsStack.size(), sortedPets.size())); i++) { + for ( + int i = petsPage * 20; + i < Math.min(petsPage * 20 + 20, Math.min(sortedPetsStack.size(), sortedPets.size())); + i++ + ) { JsonObject pet = sortedPets.get(i); ItemStack stack = sortedPetsStack.get(i); @@ -433,7 +250,7 @@ public class PetsPage extends GuiProfileViewerPage { if (selectedPet >= 0) { ItemStack petStack; if (sortedPetsStack.size() <= selectedPet) { - petStack = getQuestionmarkSkull(); + petStack = ItemUtils.createQuestionMarkSkull("§cInvalid pet selection"); } else { petStack = sortedPetsStack.get(selectedPet); } @@ -441,7 +258,8 @@ public class PetsPage extends GuiProfileViewerPage { JsonObject pet = sortedPets.get(selectedPet); int x = guiLeft + 280; - float y = guiTop + 67 + 15 * (float) Math.sin(((getInstance().currentTime - getInstance().startTime) / 800f) % (2 * Math.PI)); + float y = guiTop + 67 + 15 * (float) Math.sin( + ((getInstance().currentTime - getInstance().startTime) / 800f) % (2 * Math.PI)); int displayLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(display); int halfDisplayLen = displayLen / 2; @@ -568,32 +386,4 @@ public class PetsPage extends GuiProfileViewerPage { sortedPetsStack = null; selectedPet = -1; } - - private ItemStack getQuestionmarkSkull() { - String textureLink = "bc8ea1f51f253ff5142ca11ae45193a4ad8c3ab5e9c6eec8ba7a4fcb7bac40"; - - String b64Decoded = "{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + textureLink + "\"}}}"; - String b64Encoded = new String(Base64.getEncoder().encode(b64Decoded.getBytes())); - - ItemStack stack = new ItemStack(Items.skull, 1, 3); - NBTTagCompound nbt = new NBTTagCompound(); - NBTTagCompound skullOwner = new NBTTagCompound(); - NBTTagCompound properties = new NBTTagCompound(); - NBTTagList textures = new NBTTagList(); - NBTTagCompound textures_0 = new NBTTagCompound(); - - String uuid = UUID.nameUUIDFromBytes(b64Encoded.getBytes()).toString(); - skullOwner.setString("Id", uuid); - skullOwner.setString("Name", uuid); - - textures_0.setString("Value", b64Encoded); - textures.appendTag(textures_0); - - properties.setTag("textures", textures); - skullOwner.setTag("Properties", properties); - nbt.setTag("SkullOwner", skullOwner); - stack.setTagCompound(nbt); - stack.setStackDisplayName(EnumChatFormatting.RED + "Unknown Pet"); - return stack; - } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index b6e56743..c9bd92a3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -282,10 +282,10 @@ public class ProfileViewer { put("SUGAR_CANE", Utils.createItemStack(Items.reeds, EnumChatFormatting.YELLOW + "Sugar Cane")); put("FEATHER", Utils.createItemStack(Items.feather, EnumChatFormatting.YELLOW + "Feather")); put("LEATHER", Utils.createItemStack(Items.leather, EnumChatFormatting.YELLOW + "Leather")); - put("PORK", Utils.createItemStack(Items.porkchop, EnumChatFormatting.YELLOW + "Porkchop")); - put("RAW_CHICKEN", Utils.createItemStack(Items.chicken, EnumChatFormatting.YELLOW + "Chicken")); + put("PORK", Utils.createItemStack(Items.porkchop, EnumChatFormatting.YELLOW + "Raw Porkchop")); + put("RAW_CHICKEN", Utils.createItemStack(Items.chicken, EnumChatFormatting.YELLOW + "Raw Chicken")); put("MUTTON", Utils.createItemStack(Items.mutton, EnumChatFormatting.YELLOW + "Mutton")); - put("RABBIT", Utils.createItemStack(Items.rabbit, EnumChatFormatting.YELLOW + "Rabbit")); + put("RABBIT", Utils.createItemStack(Items.rabbit, EnumChatFormatting.YELLOW + "Raw Rabbit")); put("NETHER_STALK", Utils.createItemStack(Items.nether_wart, EnumChatFormatting.YELLOW + "Nether Wart")); /* MINING COLLECTIONS */ @@ -299,7 +299,7 @@ public class ProfileViewer { put("REDSTONE", Utils.createItemStack(Items.redstone, EnumChatFormatting.GRAY + "Redstone")); put("QUARTZ", Utils.createItemStack(Items.quartz, EnumChatFormatting.GRAY + "Nether Quartz")); put("OBSIDIAN", Utils.createItemStack(Item.getItemFromBlock(Blocks.obsidian), EnumChatFormatting.GRAY + "Obsidian")); - put("GLOWSTONE_DUST", Utils.createItemStack(Items.glowstone_dust, EnumChatFormatting.GRAY + "Glowstone")); + put("GLOWSTONE_DUST", Utils.createItemStack(Items.glowstone_dust, EnumChatFormatting.GRAY + "Glowstone Dust")); put("GRAVEL", Utils.createItemStack(Item.getItemFromBlock(Blocks.gravel), EnumChatFormatting.GRAY + "Gravel")); put("ICE", Utils.createItemStack(Item.getItemFromBlock(Blocks.ice), EnumChatFormatting.GRAY + "Ice")); put("NETHERRACK", Utils.createItemStack(Item.getItemFromBlock(Blocks.netherrack), EnumChatFormatting.GRAY + "Netherrack")); @@ -340,23 +340,23 @@ public class ProfileViewer { ); /* FORAGING COLLECTIONS */ - put("LOG", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Oak")); - put("LOG:1", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Spruce", 1)); - put("LOG:2", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Birch", 2)); - put("LOG_2:1", Utils.createItemStack(Item.getItemFromBlock(Blocks.log2), EnumChatFormatting.DARK_GREEN + "Dark Oak", 1)); - put("LOG_2", Utils.createItemStack(Item.getItemFromBlock(Blocks.log2), EnumChatFormatting.DARK_GREEN + "Acacia")); - put("LOG:3", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Jungle", 3)); + put("LOG", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Oak Wood")); + put("LOG:1", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Spruce Wood", 1)); + put("LOG:2", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Birch Wood", 2)); + put("LOG_2:1", Utils.createItemStack(Item.getItemFromBlock(Blocks.log2), EnumChatFormatting.DARK_GREEN + "Dark Oak Wood", 1)); + put("LOG_2", Utils.createItemStack(Item.getItemFromBlock(Blocks.log2), EnumChatFormatting.DARK_GREEN + "Acacia Wood")); + put("LOG:3", Utils.createItemStack(Item.getItemFromBlock(Blocks.log), EnumChatFormatting.DARK_GREEN + "Jungle Wood", 3)); /* FISHING COLLECTIONS */ - put("RAW_FISH", Utils.createItemStack(Items.fish, EnumChatFormatting.AQUA + "Fish")); - put("RAW_FISH:1", Utils.createItemStack(Items.fish, EnumChatFormatting.AQUA + "Salmon", 1)); + put("RAW_FISH", Utils.createItemStack(Items.fish, EnumChatFormatting.AQUA + "Raw Fish")); + put("RAW_FISH:1", Utils.createItemStack(Items.fish, EnumChatFormatting.AQUA + "Raw Salmon", 1)); put("RAW_FISH:2", Utils.createItemStack(Items.fish, EnumChatFormatting.AQUA + "Clownfish", 2)); put("RAW_FISH:3", Utils.createItemStack(Items.fish, EnumChatFormatting.AQUA + "Pufferfish", 3)); put("PRISMARINE_SHARD", Utils.createItemStack(Items.prismarine_shard, EnumChatFormatting.AQUA + "Prismarine Shard")); put("PRISMARINE_CRYSTALS", Utils.createItemStack(Items.prismarine_crystals, EnumChatFormatting.AQUA + "Prismarine Crystals")); put("CLAY_BALL", Utils.createItemStack(Items.clay_ball, EnumChatFormatting.AQUA + "Clay")); - put("WATER_LILY", Utils.createItemStack(Item.getItemFromBlock(Blocks.waterlily), EnumChatFormatting.AQUA + "Lilypad")); - put("INK_SACK", Utils.createItemStack(Items.dye, EnumChatFormatting.AQUA + "Ink Sack")); + put("WATER_LILY", Utils.createItemStack(Item.getItemFromBlock(Blocks.waterlily), EnumChatFormatting.AQUA + "Lily Pad")); + put("INK_SACK", Utils.createItemStack(Items.dye, EnumChatFormatting.AQUA + "Ink Sac")); put("SPONGE", Utils.createItemStack(Item.getItemFromBlock(Blocks.sponge), EnumChatFormatting.AQUA + "Sponge")); put( "MAGMA_FISH", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java index efa94ee5..70ea051a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.java @@ -71,6 +71,11 @@ public class BestiaryPage extends GuiProfileViewerPage { int yIndex = 0; for (ItemStack stack : BestiaryData.getBestiaryLocations().keySet()) { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + if (mouseX > guiLeft + 30 + bestiaryXSize * yIndex && mouseX < guiLeft + 30 + bestiaryXSize * yIndex + 20) { + if (mouseY > guiTop + 10 && mouseY < guiTop + 10 + 20) { + tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } if (stack == selectedBestiaryLocation) { Utils.drawTexturedRect( guiLeft + 30 + bestiaryXSize * yIndex, @@ -109,10 +114,6 @@ public class BestiaryPage extends GuiProfileViewerPage { Utils.drawTexturedRect(guiLeft, guiTop, 431, 202, GL11.GL_NEAREST); GlStateManager.color(1, 1, 1, 1); - GlStateManager.disableLighting(); - RenderHelper.enableGUIStandardItemLighting(); - - List<String> mobs = BestiaryData.getBestiaryLocations().get(selectedBestiaryLocation); Color color = new Color(128, 128, 128, 255); Utils.renderAlignedString( EnumChatFormatting.RED + "Bestiary Level: ", @@ -121,6 +122,10 @@ public class BestiaryPage extends GuiProfileViewerPage { guiTop + 50, 110 ); + + GlStateManager.disableLighting(); + RenderHelper.enableGUIStandardItemLighting(); + List<String> mobs = BestiaryData.getBestiaryLocations().get(selectedBestiaryLocation); if (mobs != null) { for (int i = 0; i < mobs.size(); i++) { String mob = mobs.get(i); @@ -148,7 +153,7 @@ public class BestiaryPage extends GuiProfileViewerPage { 20 * (1 - completedness) / 256f, GL11.GL_NEAREST ); - GlStateManager.color(1, 185 / 255f, 0, 1); + //GlStateManager.color(1, 185 / 255f, 0, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); Utils.drawTexturedRect( guiLeft + x, @@ -202,7 +207,7 @@ public class BestiaryPage extends GuiProfileViewerPage { if (level.maxed) { progressStr = EnumChatFormatting.GOLD + "MAXED!"; } else { - progressStr =EnumChatFormatting.AQUA + + progressStr = EnumChatFormatting.AQUA + StringUtils.shortNumberFormat(Math.round((levelNum % 1) * level.maxXpForLevel)) + "/" + StringUtils.shortNumberFormat(level.maxXpForLevel); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java index 1d226dc8..ef030367 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java @@ -71,6 +71,7 @@ public class Constants { public static JsonObject REFORGESTONES; public static JsonObject TROPHYFISH; public static JsonObject WEIGHT; + public static JsonObject RNGSCORE; private static final ReentrantLock lock = new ReentrantLock(); @@ -92,6 +93,7 @@ public class Constants { REFORGESTONES = Utils.getConstant("reforgestones", gson); TROPHYFISH = Utils.getConstant("trophyfish", gson); WEIGHT = Utils.getConstant("weight", gson); + RNGSCORE = Utils.getConstant("rngscore", gson); } catch (Exception ex) { ex.printStackTrace(); } finally { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java index 5d7bfa6d..c97a37d9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java @@ -195,7 +195,10 @@ public class HotmInformation { Tree tree = new Tree(); JsonObject nodes = miningCore.getAsJsonObject("nodes"); for (Map.Entry<String, JsonElement> node : nodes.entrySet()) { - tree.levels.put(node.getKey(), node.getValue().getAsInt()); + String key = node.getKey(); + if (!key.startsWith("toggle_")) { + tree.levels.put(key, node.getValue().getAsInt()); + } } if (miningCore.has("powder_mithril_total")) { tree.totalMithrilPowder = miningCore.get("powder_mithril_total").getAsInt(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java index 48eb6fad..4d3b4645 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java @@ -19,10 +19,11 @@ package io.github.moulberry.notenoughupdates.util; -import com.google.common.collect.Iterables; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.inventory.GuiChest; @@ -37,6 +38,7 @@ import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -136,6 +138,13 @@ public class ItemResolutionQuery { return manager.jsonToStack(jsonObject); } + @Nullable + public ItemStack resolveToItemStack(boolean useReplacements) { + JsonObject jsonObject = resolveToItemListJson(); + if (jsonObject == null) return null; + return manager.jsonToStack(jsonObject, false, useReplacements); + } + // <editor-fold desc="Resolution Helpers"> private boolean isBazaar(IInventory chest) { if (chest.getDisplayName().getFormattedText().startsWith("Bazaar ➜ ")) { @@ -170,6 +179,40 @@ public class ItemResolutionQuery { } return null; } + if (guiName.equals("Catacombs RNG Meter")) { + return resolveItemInCatacombsRngMeter(); + } + return null; + } + + private String resolveItemInCatacombsRngMeter() { + List<String> lore = ItemUtils.getLore(compound); + if (lore.size() > 16) { + String s = lore.get(15); + if (s.equals("§7Selected Drop")) { + String displayName = lore.get(16); + return getInternalNameByDisplayName(displayName); + } + } + + return null; + } + + private String getInternalNameByDisplayName(String displayName) { + String cleanDisplayName = StringUtils.cleanColour(displayName); + for (Map.Entry<String, JsonObject> entry : NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .entrySet()) { + + JsonObject object = entry.getValue(); + if (object.has("displayname")) { + String name = object.get("displayname").getAsString(); + if (StringUtils.cleanColour(name).equals(cleanDisplayName)) { + return entry.getKey(); + } + } + } + return null; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java index cffdd164..c6bc7538 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java @@ -19,16 +19,32 @@ package io.github.moulberry.notenoughupdates.util; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.listener.ItemTooltipListener; +import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; +import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Map; +import java.util.function.BiFunction; public class ItemUtils { @@ -57,6 +73,21 @@ public class ItemUtils { return skull; } + public static ItemStack createQuestionMarkSkull(String label) { + return Utils.createSkull( + label, + "00000000-0000-0000-0000-000000000000", + "bc8ea1f51f253ff5142ca11ae45193a4ad8c3ab5e9c6eec8ba7a4fcb7bac40" + ); + } + + public static NBTTagCompound getOrCreateTag(ItemStack is) { + if (is.hasTagCompound()) return is.getTagCompound(); + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + is.setTagCompound(nbtTagCompound); + return nbtTagCompound; + } + public static void appendLore(ItemStack is, List<String> moreLore) { NBTTagCompound tagCompound = is.getTagCompound(); if (tagCompound == null) { @@ -96,4 +127,276 @@ public class ItemUtils { return string; } + public static String fixEnchantId(String enchId, boolean useId) { + if (Constants.ENCHANTS != null && Constants.ENCHANTS.has("enchant_mapping_id") && + Constants.ENCHANTS.has("enchant_mapping_item")) { + JsonArray mappingFrom = Constants.ENCHANTS.getAsJsonArray("enchant_mapping_" + (useId ? "id" : "item")); + JsonArray mappingTo = Constants.ENCHANTS.getAsJsonArray("enchant_mapping_" + (useId ? "item" : "id")); + + for (int i = 0; i < mappingFrom.size(); i++) { + if (mappingFrom.get(i).getAsString().equals(enchId)) { + return mappingTo.get(i).getAsString(); + } + } + + } + return enchId; + } + + /** + * Mutates baseValues + */ + public static <T> void modifyReplacement( + Map<String, String> baseValues, + Map<String, T> modifiers, + BiFunction<String, T, String> mapper + ) { + if (modifiers == null || baseValues == null) return; + for (Map.Entry<String, T> modifier : modifiers.entrySet()) { + String baseValue = baseValues.get(modifier.getKey()); + if (baseValue == null) continue; + try { + baseValues.put(modifier.getKey(), mapper.apply(baseValue, modifier.getValue())); + } catch (Exception e) { + System.out.println("Exception during replacement mapping: "); + e.printStackTrace(); + } + } + } + + public static String applyReplacements(Map<String, String> replacements, String text) { + for (Map.Entry<String, String> replacement : replacements.entrySet()) { + String search = "{" + replacement.getKey() + "}"; + text = text.replace(search, replacement.getValue()); + } + return text; + } + + public static ItemStack createPetItemstackFromPetInfo(PetInfoOverlay.Pet currentPet) { + String petname = currentPet.petType; + String tier = Utils.getRarityFromInt(currentPet.rarity.petId).toUpperCase(); + String heldItem = currentPet.petItem; + String skin = currentPet.skin; + JsonObject heldItemJson = heldItem == null ? null : NotEnoughUpdates.INSTANCE.manager.getItemInformation().get( + heldItem); + String petId = currentPet.getPetId(false); + float exp = currentPet.petLevel.totalXp; + + GuiProfileViewer.PetLevel levelObj = GuiProfileViewer.getPetLevel(petname, tier, exp); + + float level = levelObj.level; + + ItemStack petItemstack = NotEnoughUpdates.INSTANCE.manager + .createItemResolutionQuery() + .withKnownInternalName(petId) + .resolveToItemStack(false); + if (petItemstack == null) { + petItemstack = ItemUtils.createQuestionMarkSkull(EnumChatFormatting.RED + "Unknown Pet"); + appendLore(petItemstack, Arrays.asList( + "§cThis pet is not saved in the repository", + "", + "§cIf you expected it to be there please send a message in", + "§c§l#neu-support §r§con §ldiscord.gg/moulberry" + )); + } + Map<String, String> replacements = NotEnoughUpdates.INSTANCE.manager.getPetLoreReplacements( + petname, + tier, + MathHelper.floor_float(level) + ); + + if (heldItem != null) { + modifyReplacement(replacements, GuiProfileViewer.PET_STAT_BOOSTS.get(heldItem), (original, modifier) -> + "" + MathHelper.floor_float(Float.parseFloat(original) + modifier)); + modifyReplacement(replacements, GuiProfileViewer.PET_STAT_BOOSTS_MULT.get(heldItem), (original, modifier) -> + "" + MathHelper.floor_float(Float.parseFloat(original) * modifier)); + } + + NBTTagCompound tag = getOrCreateTag(petItemstack); + if (tag.hasKey("display", 10)) { + NBTTagCompound displayTag = tag.getCompoundTag("display"); + if (displayTag.hasKey("Lore", 9)) { + List<String> newLore = new ArrayList<>(); + NBTTagList lore = displayTag.getTagList("Lore", 8); + int secondLastBlankLine = -1, lastBlankLine = -1; + for (int j = 0; j < lore.tagCount(); j++) { + String line = lore.getStringTagAt(j); + if (line.trim().isEmpty()) { + secondLastBlankLine = lastBlankLine; + lastBlankLine = j; + } + line = applyReplacements(replacements, line); + newLore.add(line); + } + if (skin != null) { + JsonObject petSkin = NotEnoughUpdates.INSTANCE.manager + .createItemResolutionQuery() + .withKnownInternalName("PET_SKIN_" + skin) + .resolveToItemListJson(); + if (petSkin != null) { + try { + NBTTagCompound nbt = JsonToNBT.getTagFromJson(petSkin.get("nbttag").getAsString()); + tag.setTag("SkullOwner", nbt.getTag("SkullOwner")); + String name = petSkin.get("displayname").getAsString(); + if (name != null) { + name = Utils.cleanColour(name); + newLore.set(0, newLore.get(0) + ", " + name); + } + } catch (NBTException e) { + e.printStackTrace(); + } + } + } + for (int i = 0; i < newLore.size(); i++) { + String cleaned = Utils.cleanColour(newLore.get(i)); + if (cleaned.equals("Right-click to add this pet to")) { + newLore.remove(i + 1); + newLore.remove(i); + secondLastBlankLine = i - 1; + break; + } + } + if (secondLastBlankLine != -1) { + List<String> petItemLore = new ArrayList<>(); + if (heldItem != null) { + petItemLore.add(EnumChatFormatting.GOLD + "Held Item: " + heldItemJson.get("displayname").getAsString()); + List<String> heldItemLore = JsonUtils.getJsonArrayOrEmpty(heldItemJson, "lore", JsonElement::getAsString); + int blanks = 0; + for (String heldItemLoreLine : heldItemLore) { + if (heldItemLoreLine.trim().isEmpty()) { + blanks++; + } else if (blanks == 2) { + petItemLore.add(heldItemLoreLine); + } else if (blanks > 2) { + break; + } + } + } + if (currentPet.candyUsed > 0) { + if (petItemLore.size() > 0) { + petItemLore.add(""); + } + petItemLore.add("§a(" + currentPet.candyUsed + "/10) Pet Candy Used"); + } + newLore.addAll(secondLastBlankLine + 1, petItemLore); + } + NBTTagList temp = new NBTTagList(); + for (String loreLine : newLore) { + temp.appendTag(new NBTTagString(loreLine)); + } + displayTag.setTag("Lore", temp); + } + + if (displayTag.hasKey("Name", 8)) { + String displayName = displayTag.getString("Name"); + displayName = applyReplacements(replacements, displayName); + displayTag.setTag("Name", new NBTTagString(displayName)); + } + tag.setTag("display", displayTag); + } + + // Adds the missing pet fields to the tag + NBTTagCompound extraAttributes = new NBTTagCompound(); + JsonObject petInfo = new JsonObject(); + if (tag.hasKey("ExtraAttributes", 10)) { + extraAttributes = tag.getCompoundTag("ExtraAttributes"); + if (extraAttributes.hasKey("petInfo", 8)) { + petInfo = new JsonParser().parse(extraAttributes.getString("petInfo")).getAsJsonObject(); + } + } + petInfo.addProperty("exp", exp); + petInfo.addProperty("tier", tier); + petInfo.addProperty("type", petname); + if (heldItem != null) { + petInfo.addProperty("heldItem", heldItem); + } + if (skin != null) { + petInfo.addProperty("skin", skin); + } + extraAttributes.setString("petInfo", petInfo.toString()); + tag.setTag("ExtraAttributes", extraAttributes); + petItemstack.setTagCompound(tag); + return petItemstack; + } + + private static final DecimalFormat decimalFormatter = new DecimalFormat("#,###,###.###"); + + public static ItemStack petToolTipXPExtendPetOverlay(ItemStack stack) { + NBTTagCompound tag = stack.getTagCompound() == null ? new NBTTagCompound() : stack.getTagCompound(); + if (tag.hasKey("display", 10)) { + NBTTagCompound display = tag.getCompoundTag("display"); + if (display.hasKey("Lore", 9)) { + NBTTagList lore = display.getTagList("Lore", 8); + if (Utils.cleanColour(lore.getStringTagAt(0)).matches(ItemTooltipListener.petToolTipRegex) && + lore.tagCount() > 7) { + + GuiProfileViewer.PetLevel petLevel; + + PetInfoOverlay.Pet pet = PetInfoOverlay.getPetFromStack( + stack.getTagCompound() + ); + if (pet == null) return stack; + petLevel = pet.petLevel; + if (petLevel == null) return stack; + + NBTTagList newLore = new NBTTagList(); + int maxLvl = 100; + if (Constants.PETS != null && Constants.PETS.has("custom_pet_leveling") && + Constants.PETS.getAsJsonObject("custom_pet_leveling").has(pet.petType.toUpperCase()) && + Constants.PETS.getAsJsonObject("custom_pet_leveling").getAsJsonObject(pet.petType.toUpperCase()).has( + "max_level")) { + maxLvl = + Constants.PETS + .getAsJsonObject("custom_pet_leveling") + .getAsJsonObject(pet.petType.toUpperCase()) + .get("max_level") + .getAsInt(); + } + for (int i = 0; i < lore.tagCount(); i++) { + if (i == lore.tagCount() - 2) { + newLore.appendTag(new NBTTagString("")); + if (petLevel.level >= maxLvl) { + newLore.appendTag(new NBTTagString( + EnumChatFormatting.AQUA + "" + EnumChatFormatting.BOLD + "MAX LEVEL")); + } else { + double levelPercent = (Math.round(petLevel.levelPercentage * 1000) / 10.0); + newLore.appendTag(new NBTTagString( + EnumChatFormatting.GRAY + "Progress to Level " + (int) (petLevel.level + 1) + ": " + + EnumChatFormatting.YELLOW + levelPercent + "%")); + StringBuilder sb = new StringBuilder(); + + for (int j = 0; j < 20; j++) { + if (j < (levelPercent / 5)) { + sb.append(EnumChatFormatting.DARK_GREEN); + } else { + sb.append(EnumChatFormatting.GRAY); + } + sb.append("-"); + } + newLore.appendTag(new NBTTagString(sb.toString())); + newLore.appendTag(new NBTTagString( + EnumChatFormatting.GRAY + "EXP: " + EnumChatFormatting.YELLOW + + decimalFormatter.format(petLevel.levelXp) + + EnumChatFormatting.GOLD + "/" + EnumChatFormatting.YELLOW + + decimalFormatter.format(petLevel.currentLevelRequirement) + )); + } + } + newLore.appendTag(lore.get(i)); + } + display.setTag("Lore", newLore); + tag.setTag("display", display); + } + } + } + stack.setTagCompound(tag); + return stack; + } + + public static boolean isSoulbound(ItemStack item) { + return ItemUtils.getLore(item).stream() + .anyMatch(line -> line.equals("§8§l* §8Co-op Soulbound §8§l*") || + line.equals("§8§l* Soulbound §8§l*")); + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java index 58794e07..81eea343 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java @@ -187,6 +187,7 @@ public class XPInformation { skillInfo.currentXp += updateWithPercentage.get(skill) / 100f * cap; skillInfo.totalXp += skillInfo.currentXp; skillInfo.currentXpMax = cap; + break; } else { skillInfo.totalXp += cap; } diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index 0a547b4b..ed1ba55a 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -40,7 +40,6 @@ "MixinRenderGlobal", "MixinRenderItem", "MixinRenderList", - "MixinSkyclientCosmetics", "MixinTextureManager", "MixinTileEntitySkullRenderer", "MixinTileEntitySpecialRenderer", |