diff options
Diffstat (limited to 'src/main/java/io')
75 files changed, 20782 insertions, 3147 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java new file mode 100644 index 00000000..5ca25082 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java @@ -0,0 +1,824 @@ +package io.github.moulberry.notenoughupdates; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; +import io.github.moulberry.notenoughupdates.util.Constants; +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.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +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.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import java.awt.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.*; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static io.github.moulberry.notenoughupdates.GuiTextures.*; + +public class AccessoryBagOverlay { + + private static final int TAB_BASIC = 0; + private static final int TAB_TOTAL = 1; + private static final int TAB_BONUS = 2; + private static final int TAB_DUP = 3; + private static final int TAB_MISSING = 4; + private static final int TAB_OPTIMIZER = 5; + + private static final ItemStack[] TAB_STACKS = new ItemStack[] { + Utils.createItemStack(Items.dye, EnumChatFormatting.DARK_AQUA+"Basic Information", + 10, EnumChatFormatting.GREEN+"- Talis count by rarity"), + Utils.createItemStack(Items.diamond_sword, EnumChatFormatting.DARK_AQUA+"Total Stat Bonuses", + 0), + Utils.createItemStack(Item.getItemFromBlock(Blocks.anvil), EnumChatFormatting.DARK_AQUA+"Total Stat Bonuses (from reforges)", + 0), + Utils.createItemStack(Items.dye, EnumChatFormatting.DARK_AQUA+"Duplicates", + 8), + Utils.createItemStack(Item.getItemFromBlock(Blocks.barrier), EnumChatFormatting.DARK_AQUA+"Missing", + 0), + Utils.createItemStack(Item.getItemFromBlock(Blocks.redstone_block), EnumChatFormatting.DARK_AQUA+"Optimizer", + 0), + }; + + private static int currentTab = TAB_BASIC; + + public static boolean mouseClick() { + if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if(!containerName.trim().startsWith("Accessory Bag")) { + return false; + } + } else { + return false; + } + + if(!Mouse.getEventButtonState()) return false; + try { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + int mouseX = Mouse.getX() / scaledResolution.getScaleFactor(); + int mouseY = height - Mouse.getY() / scaledResolution.getScaleFactor(); + + int xSize = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "xSize", "field_146999_f"); + int ySize = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "ySize", "field_147000_g"); + int guiLeft = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "guiLeft", "field_147003_i"); + int guiTop = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "guiTop", "field_147009_r"); + + if(mouseX < guiLeft+xSize+3 || mouseX > guiLeft+xSize+80+28) return false; + if(mouseY < guiTop || mouseY > guiTop+166) return false; + + if(mouseX > guiLeft+xSize+83 && mouseY < guiTop+20*TAB_MISSING+22) { + currentTab = (mouseY - guiTop)/20; + if(currentTab < 0) currentTab = 0; + if(currentTab > TAB_MISSING) currentTab = TAB_MISSING; + } + + if(currentTab == TAB_OPTIMIZER) { + int x = guiLeft+xSize+3; + int y = guiTop; + + if(mouseY > y+92 && mouseY < y+103) { + if(mouseX > x+5 && mouseX < x+75) { + mainWeapon = (int)Math.floor((mouseX-x-5)/70f*9); + if(mainWeapon < 1) { + mainWeapon = 1; + } else if(mainWeapon > 9) { + mainWeapon = 9; + } + } + } + + if(mouseX > x+5 && mouseX < x+35 || mouseX > x+45 && mouseX < x+75) { + boolean set = mouseX > x+5 && mouseX < x+35; + + if(mouseY > y+32 && mouseY < y+43) { + forceCC = set; + } else if(mouseY > y+52 && mouseY < y+63) { + forceAS = set; + } else if(mouseY > y+72 && mouseY < y+83) { + useGodPot = set; + } else if(mouseY > y+92 && mouseY < y+103) { + allowShaded = set; + } + } + } + + return true; + } catch(Exception e) { + return false; + } + } + + public static void resetCache() { + accessoryStacks = new HashSet<>(); + pagesVisited = new HashSet<>(); + talismanCountRarity = null; + totalStats = null; + reforgeStats = null; + duplicates = null; + missing = null; + } + + private static Set<ItemStack> accessoryStacks = new HashSet<>(); + private static Set<Integer> pagesVisited = new HashSet<>(); + + public static void renderVisitOverlay(int x, int y) { + Utils.drawStringCenteredScaledMaxWidth("Please visit all", Minecraft.getMinecraft().fontRendererObj, x+40, y+78, true, 70, -1); + Utils.drawStringCenteredScaledMaxWidth("pages of the bag", Minecraft.getMinecraft().fontRendererObj, x+40, y+86, true, 70, -1); + } + + private static TreeMap<Integer, Integer> talismanCountRarity = null; + public static void renderBasicOverlay(int x, int y) { + if(talismanCountRarity == null) { + talismanCountRarity = new TreeMap<>(); + for(ItemStack stack : accessoryStacks) { + int rarity = getRarity(stack); + if(rarity >= 0) { + talismanCountRarity.put(rarity, talismanCountRarity.getOrDefault(rarity, 0)+1); + } + } + } + + Utils.drawStringCenteredScaledMaxWidth("# By Rarity", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + + int yIndex = 0; + for(Map.Entry<Integer, Integer> entry : talismanCountRarity.descendingMap().entrySet()) { + String rarityName = rarityArrC[entry.getKey()]; + renderAlignedString(rarityName, EnumChatFormatting.WHITE.toString()+entry.getValue(), x+5, y+20+11*yIndex, 70); + yIndex++; + } + } + + + private static PlayerStats.Stats totalStats = null; + public static void renderTotalStatsOverlay(int x, int y) { + if(totalStats == null) { + totalStats = new PlayerStats.Stats(); + for(ItemStack stack : accessoryStacks) { + if(stack != null) totalStats.add(getStatForItem(stack, STAT_PATTERN_MAP, true)); + } + } + + Utils.drawStringCenteredScaledMaxWidth("Total Stats", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + int yIndex = 0; + for(int i=0; i<PlayerStats.defaultStatNames.length; i++) { + String statName = PlayerStats.defaultStatNames[i]; + String statNamePretty = PlayerStats.defaultStatNamesPretty[i]; + + int val = Math.round(totalStats.get(statName)); + + if(Math.abs(val) < 1E-5) continue; + + GlStateManager.color(1, 1, 1, 1); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + renderAlignedString(statNamePretty, EnumChatFormatting.WHITE.toString()+val, x+5, y+20+11*yIndex, 70); + + yIndex++; + } + } + + private static PlayerStats.Stats reforgeStats = null; + public static void renderReforgeStatsOverlay(int x, int y) { + if(reforgeStats == null) { + reforgeStats = new PlayerStats.Stats(); + for(ItemStack stack : accessoryStacks) { + if(stack != null) reforgeStats.add(getStatForItem(stack, STAT_PATTERN_MAP_BONUS, false)); + } + } + + Utils.drawStringCenteredScaledMaxWidth("Reforge Stats", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + int yIndex = 0; + for(int i=0; i<PlayerStats.defaultStatNames.length; i++) { + String statName = PlayerStats.defaultStatNames[i]; + String statNamePretty = PlayerStats.defaultStatNamesPretty[i]; + + int val = Math.round(reforgeStats.get(statName)); + + if(Math.abs(val) < 1E-5) continue; + + GlStateManager.color(1, 1, 1, 1); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + renderAlignedString(statNamePretty, EnumChatFormatting.WHITE.toString()+val, x+5, y+20+11*yIndex, 70); + + yIndex++; + } + } + + private static Set<ItemStack> duplicates = null; + public static void renderDuplicatesOverlay(int x, int y) { + if(duplicates == null) { + JsonObject misc = Constants.MISC; + if(misc == null) { + Utils.drawStringCenteredScaledMaxWidth("Duplicates: ERROR", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + return; + } + JsonElement talisman_upgrades_element = misc.get("talisman_upgrades"); + if(talisman_upgrades_element == null) { + Utils.drawStringCenteredScaledMaxWidth("Duplicates: ERROR", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + return; + } + JsonObject talisman_upgrades = talisman_upgrades_element.getAsJsonObject(); + + duplicates = new HashSet<>(); + + Set<String> prevInternalnames = new HashSet<>(); + for(ItemStack stack : accessoryStacks) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + + if(prevInternalnames.contains(internalname)) { + duplicates.add(stack); + continue; + } + prevInternalnames.add(internalname); + + if(talisman_upgrades.has(internalname)) { + JsonArray upgrades = talisman_upgrades.get(internalname).getAsJsonArray(); + for(ItemStack stack2 : accessoryStacks) { + if(stack != stack2) { + String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack2); + for(int j=0; j<upgrades.size(); j++) { + String upgrade = upgrades.get(j).getAsString(); |
