From f7d3491def0f7498d7bf0d547445f75f0c515912 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Fri, 17 Jul 2020 05:57:11 +0800 Subject: REL-1.0.0 --- .../moulberry/notenoughupdates/GuiItemRecipe.java | 254 ++++++-- .../moulberry/notenoughupdates/GuiItemUsages.java | 170 ----- .../moulberry/notenoughupdates/GuiTextures.java | 3 + .../github/moulberry/notenoughupdates/NEUIO.java | 27 +- .../moulberry/notenoughupdates/NEUManager.java | 203 +++--- .../moulberry/notenoughupdates/NEUOverlay.java | 699 +++++++++++++-------- .../notenoughupdates/NEUOverlayPlacements.java | 185 ++++++ .../notenoughupdates/NotEnoughUpdates.java | 227 ++++++- .../moulberry/notenoughupdates/StreamerMode.java | 29 +- .../notenoughupdates/auction/APIManager.java | 598 ++++++++++++++++++ .../notenoughupdates/auction/AuctionManager.java | 437 ------------- .../notenoughupdates/auction/CustomAH.java | 66 +- .../notenoughupdates/cosmetics/CapeManager.java | 28 +- .../notenoughupdates/cosmetics/NEUCape.java | 4 +- .../infopanes/CollectionLogInfoPane.java | 108 ++-- .../infopanes/CosmeticsInfoPane.java | 8 +- .../notenoughupdates/infopanes/QOLInfoPane.java | 341 ---------- .../infopanes/SettingsInfoPane.java | 55 +- .../notenoughupdates/mbgui/MBAnchorPoint.java | 48 ++ .../notenoughupdates/mbgui/MBGuiElement.java | 12 + .../notenoughupdates/mbgui/MBGuiGroup.java | 64 ++ .../notenoughupdates/mbgui/MBGuiGroupFloating.java | 42 ++ .../notenoughupdates/mbgui/MBGuiGroupHorz.java | 47 ++ .../notenoughupdates/options/Options.java | 106 +++- .../notenoughupdates/questing/GuiQuestLine.java | 27 + .../notenoughupdates/questing/NEUQuesting.java | 67 ++ .../notenoughupdates/questing/QuestLine.java | 226 +++++++ .../questing/requirements/Requirement.java | 29 + .../questing/requirements/RequirementApi.java | 111 ++++ .../questing/requirements/RequirementGuiOpen.java | 28 + .../requirements/RequirementIslandType.java | 19 + .../requirements/RequirementItemObtained.java | 29 + .../questing/requirements/RequirementLocation.java | 26 + .../requirements/RequirementLocationRect.java | 34 + .../moulberry/notenoughupdates/util/Utils.java | 59 +- 35 files changed, 2918 insertions(+), 1498 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/auction/AuctionManager.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBAnchorPoint.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiElement.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupHorz.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/GuiQuestLine.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/NEUQuesting.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/QuestLine.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/Requirement.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementApi.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementGuiOpen.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementIslandType.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementItemObtained.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementLocation.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementLocationRect.java (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java index 613ebe5f..200569df 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java @@ -1,89 +1,241 @@ package io.github.moulberry.notenoughupdates; import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.util.TexLoc; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiCrafting; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.vector.Vector2f; +import org.lwjgl.util.vector.Vector3f; -public class GuiItemRecipe extends GuiCrafting { +import java.awt.*; +import java.io.IOException; +import java.util.List; - private ItemStack[] craftMatrix; - private JsonObject result; - private String text; - private String craftText = ""; +public class GuiItemRecipe extends GuiScreen { + + private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation("textures/gui/container/crafting_table.png"); + + private List craftMatrices; + private List results; + private int currentIndex = 0; + + private String title; private NEUManager manager; - public GuiItemRecipe(ItemStack[] craftMatrix, JsonObject result, String text, NEUManager manager) { - super(Minecraft.getMinecraft().thePlayer.inventory, Minecraft.getMinecraft().theWorld); - this.craftMatrix = craftMatrix; - this.result = result; - this.text = text; + private int guiLeft = 0; + private int guiTop = 0; + private int xSize = 176; + private int ySize = 166; + + public GuiItemRecipe(String title, List craftMatrices, List results, NEUManager manager) { + this.craftMatrices = craftMatrices; + this.results = results; this.manager = manager; + this.title = title; + } - setContents(); + private String getCraftText() { + if(results.get(currentIndex).has("crafttext")) { + return results.get(currentIndex).get("crafttext").getAsString(); + } else { + return ""; + } } - public void setContents() { - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - for(int i=0; i= craftMatrices.size()) { + currentIndex = craftMatrices.size()-1; } - if(result.has("crafttext")) { - craftText = result.get("crafttext").getAsString(); + + FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; + + this.guiLeft = (width - this.xSize) / 2; + this.guiTop = (height - this.ySize) / 2; + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(craftingTableGuiTextures); + this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); + + List tooltipToRender = null; + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + Utils.drawItemStack(getStackForIndex(index), (int)pos.x, (int)pos.y); + + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + tooltipToRender = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + } } - cw.craftResult.setInventorySlotContents(0, manager.jsonToStack(result)); - } - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - setContents(); + if(craftMatrices.size() > 1) { + int guiX = mouseX - guiLeft; + int guiY = mouseY - guiTop; + + int buttonWidth = 7; + int buttonHeight = 11; + + boolean leftSelected = false; + boolean rightSelected = false; + + if(guiY > + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + leftSelected = true; + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + rightSelected = true; + } + } - String t = text.equals("") ? I18n.format("container.crafting", new Object[0]) : text; + Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); + //Left arrow + Utils.drawTexturedRect(guiLeft+110, guiTop+63, 7, 11, 34/256f, 48/256f, + 5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0)); + //Right arrow + Utils.drawTexturedRect(guiLeft+147, guiTop+63, 7, 11, 10/256f, 24/256f, + 5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0)); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - Utils.drawStringScaledMaxWidth(t, fontRendererObj, 28, 6, t.contains("\u00a7"), xSize-38, 4210752); - this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); + String str = (currentIndex+1)+"/"+craftMatrices.size(); + Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, guiLeft+132, guiTop+69, + false, 24, Color.BLACK.getRGB()); + } - Utils.drawStringCenteredScaledMaxWidth(craftText, fontRendererObj, 132, 25, + Utils.drawStringCenteredScaledMaxWidth(getCraftText(), fontRendererObj, guiLeft+132, guiTop+25, false, 75, 4210752); + + Utils.drawStringScaledMaxWidth(title, fontRendererObj, guiLeft+28, guiTop+6, title.contains("\u00a7"), xSize-38, 4210752); + + if(tooltipToRender != null) { + Utils.drawHoveringText(tooltipToRender, mouseX, mouseY, width, height, -1, fontRendererObj); + } } - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + public ItemStack getStackForIndex(int index) { + if(index == 0) { + return manager.jsonToStack(results.get(currentIndex)); + } else if(index >= 1 && index <= 9) { + return craftMatrices.get(currentIndex)[index-1]; + } else { + return Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(index-10); + } } - protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - ItemStack click = null; - if(slotId >= 1 && slotId <= 9) { - click = craftMatrix[slotId-1]; - } else if(slotId == 0) { - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - click = cw.craftResult.getStackInSlot(0); + public Vector2f getPositionForIndex(int index) { + //0 = result + //1-9 = craft matrix + //10-18 = hotbar + //19-45 = player inv + + if(index == 0) { + return new Vector2f(guiLeft+124, guiTop+35); + } else if(index >= 1 && index <= 9) { + index -= 1; + int x = index % 3; + int y = index / 3; + return new Vector2f(guiLeft+30 + x*18, guiTop+17 + y * 18); + } else if(index >= 10 && index <= 18) { + index -= 10; + return new Vector2f(guiLeft+8 + index*18, guiTop+142); + } else if(index >= 19 && index <= 45) { + index -= 19; + int x = index % 9; + int y = index / 9; + return new Vector2f(guiLeft+8 + x*18, guiTop+84 + y*18); } - if(click != null) { - if(clickedButton == 0) { - manager.displayGuiItemRecipe(manager.getInternalNameForItem(click), ""); - } else if(clickedButton == 1) { - manager.displayGuiItemUsages(manager.getInternalNameForItem(click), ""); + return null; + } + + @Override + public void handleKeyboardInput() throws IOException { + super.handleKeyboardInput(); //TODO: r and u + + 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; + + int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter()+256 : Keyboard.getEventKey(); + + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + if(keyPressed == manager.keybindViewRecipe.getKeyCode()) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); + } else if(keyPressed == manager.keybindViewUsages.getKeyCode()) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); + } + } + return; + } } } } - /*public void handleMouseInput() throws IOException { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int height = scaledresolution.getScaledHeight(); + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + + int guiX = mouseX - guiLeft; + int guiY = mouseY - guiTop; - int mouseX = Mouse.getX() / scaledresolution.getScaleFactor(); - int mouseY = height - Mouse.getY() / scaledresolution.getScaleFactor(); - if(mouseY > this.guiTop + this.ySize - 94 || mouseY < this.guiTop || - mouseX < this.guiLeft || mouseX > this.guiLeft+this.xSize) { - //Potentially allow mouse input in the future. For now this is still broken. - //super.handleMouseInput(); + int buttonWidth = 7; + int buttonHeight = 11; + + if(guiY > + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + currentIndex--; + Utils.playPressSound(); + return; + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + currentIndex++; + Utils.playPressSound(); + return; + } } - }*/ - public void onCraftMatrixChanged(IInventory inventoryIn){} + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + if(mouseButton == 0) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); + } else if(mouseButton == 1) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); + } + } + return; + } + } + } + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java deleted file mode 100644 index a56293e9..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java +++ /dev/null @@ -1,170 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.util.TexLoc; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiCrafting; -import net.minecraft.client.resources.I18n; -import net.minecraft.inventory.ContainerWorkbench; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -import java.awt.*; -import java.io.IOException; -import java.util.List; - -public class GuiItemUsages extends GuiCrafting { - private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); - - private List craftMatrices; - private List results; - private int currentIndex = 0; - - private String text; - private String craftText = ""; - private String collectionText = ""; - private NEUManager manager; - - private TexLoc left = new TexLoc(0, 0, Keyboard.KEY_N); - private TexLoc right = new TexLoc(0, 0, Keyboard.KEY_M); - - public GuiItemUsages(List craftMatrices, List results, String text, NEUManager manager) { - super(Minecraft.getMinecraft().thePlayer.inventory, Minecraft.getMinecraft().theWorld); - - this.craftMatrices = craftMatrices; - this.results = results; - this.text = text; - this.manager = manager; - - setIndex(0); - } - - private void setIndex(int index) { - if(index < 0 || index >= craftMatrices.size()) { - return; - } else { - currentIndex = index; - - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - for(int i=0; i + 63 && guiY < + 63 + buttonHeight) { - if(guiX > + 110 && guiX < 110 + buttonWidth) { - leftSelected = true; - } else if(guiX > 147 && guiX < 147 + buttonWidth) { - rightSelected = true; - } - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); - //Left arrow - Utils.drawTexturedRect(110, 63, 7, 11, 34/256f, 48/256f, - 5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0)); - //Right arrow - Utils.drawTexturedRect(147, 63, 7, 11, 10/256f, 24/256f, - 5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0)); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - - String str = (currentIndex+1)+"/"+craftMatrices.size(); - Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, 132, 69, - false, 24, Color.BLACK.getRGB()); - - - Utils.drawStringCenteredScaledMaxWidth(craftText, fontRendererObj, 132, 25, - false, 75, 4210752); - - - Utils.drawStringScaledMaxWidth(t, fontRendererObj, 28, 6, t.contains("\u00a7"), xSize-38, 4210752); - this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); - } - - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - } - - @Override - public void handleKeyboardInput() throws IOException { - super.handleKeyboardInput(); //TODO: r and u - left.handleKeyboardInput(); - right.handleKeyboardInput(); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); - - int guiX = mouseX - guiLeft; - int guiY = mouseY - guiTop; - - int buttonWidth = 7; - int buttonHeight = 11; - - if(guiY > + 63 && guiY < + 63 + buttonHeight) { - if(guiX > + 110 && guiX < 110 + buttonWidth) { - setIndex(currentIndex-1); - } else if(guiX > 147 && guiX < 147 + buttonWidth) { - setIndex(currentIndex+1); - } - } - } - - protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - ItemStack click = null; - if(slotId >= 1 && slotId <= 9) { - click = craftMatrices.get(currentIndex)[slotId-1]; - } else if(slotId == 0) { - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - click = cw.craftResult.getStackInSlot(0); - } - if(click != null) { - if(clickedButton == 0) { - manager.displayGuiItemRecipe(manager.getInternalNameForItem(click), ""); - } else if(clickedButton == 1) { - manager.displayGuiItemUsages(manager.getInternalNameForItem(click), ""); - } - } - } - - /*public void handleMouseInput() throws IOException { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int height = scaledresolution.getScaledHeight(); - - int mouseX = Mouse.getX() / scaledresolution.getScaleFactor(); - int mouseY = height - Mouse.getY() / scaledresolution.getScaleFactor(); - if(mouseY > this.guiTop + this.ySize - 94 || mouseY < this.guiTop || - mouseX < this.guiLeft || mouseX > this.guiLeft+this.xSize) { - //Potentially allow mouse input in the future. For now this is still broken. - //super.handleMouseInput(); - } - }*/ - - public void onCraftMatrixChanged(IInventory inventoryIn){} -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java index 573e20cf..1f87018b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java @@ -22,6 +22,9 @@ public class GuiTextures { public static final ResourceLocation slider_button = new ResourceLocation("notenoughupdates:slider_button.png"); public static final ResourceLocation item_mask = new ResourceLocation("notenoughupdates:item_mask.png"); + public static final ResourceLocation button_tex = new ResourceLocation("notenoughupdates:button.png"); + + public static final ResourceLocation dungeon_chest_worth = new ResourceLocation("notenoughupdates:dungeon_chest_worth.png"); public static final ResourceLocation auction_view = new ResourceLocation("notenoughupdates:auction_view.png"); public static final ResourceLocation auction_accept = new ResourceLocation("notenoughupdates:auction_accept.png"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java index d2190425..b9f086a4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java @@ -74,13 +74,10 @@ public class NEUIO { GHRepository repo = github.getRepositoryById("247692460"); for(GHTreeEntry treeEntry : repo.getTreeRecursive("master", 1).getTree()) { - if(treeEntry.getPath().startsWith("items/")) { - String[] split = treeEntry.getPath().split("/"); - String name = split[split.length-1]; - - String oldSha = oldShas.get(name); + if(treeEntry.getPath().contains(".")) { + String oldSha = oldShas.get(treeEntry.getPath()); if(!treeEntry.getSha().equals(oldSha)) { - changedFiles.put(name, treeEntry.getSha()); + changedFiles.put(treeEntry.getPath(), treeEntry.getSha()); } } } @@ -109,22 +106,4 @@ public class NEUIO { removedItems.removeAll(repoItems); return removedItems; } - - /** - * Takes set of filename (eg. BOW.json) and returns map from that filename to the individual download link. - */ - public Map getItemsDownload(Set filename) { - HashMap downloadUrls = new HashMap<>(); - try { - GitHub github = new GitHubBuilder().withOAuthToken(accessToken).build(); - GHRepository repo = github.getRepositoryById("247692460"); - - for(GHContent content : repo.getDirectoryContent("items")) { - if(filename.contains(content.getName())) { - downloadUrls.put(content.getName(), content.getDownloadUrl()); - } - } - } catch(IOException e) { } - return downloadUrls; - } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 77d3be7f..8d625c14 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -1,14 +1,15 @@ package io.github.moulberry.notenoughupdates; +import com.google.common.collect.Lists; import com.google.gson.*; -import io.github.moulberry.notenoughupdates.auction.AuctionManager; -import io.github.moulberry.notenoughupdates.auction.CustomAH; +import io.github.moulberry.notenoughupdates.auction.APIManager; +import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.options.Options; import io.github.moulberry.notenoughupdates.util.HypixelApi; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; @@ -22,10 +23,6 @@ import java.io.*; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -35,7 +32,7 @@ public class NEUManager { private final NotEnoughUpdates neu; public final NEUIO neuio; public final Gson gson; - public final AuctionManager auctionManager; + public final APIManager auctionManager; private TreeMap itemMap = new TreeMap<>(); @@ -53,7 +50,8 @@ public class NEUManager { public String viewItemAttemptID = null; public long viewItemAttemptTime = 0; - public String currentProfile = ""; + private String currentProfile = ""; + private String currentProfileBackup = ""; public final HypixelApi hypixelApi = new HypixelApi(); private ResourceLocation wkZip = new ResourceLocation("notenoughupdates:wkhtmltox.zip"); @@ -67,17 +65,17 @@ public class NEUManager { private HashMap> usagesMap = new HashMap<>(); public File configLocation; - private File itemsLocation; + public File repoLocation; private File itemShaLocation; private JsonObject itemShaConfig; - private File configFile; + public File configFile; public Options config; public NEUManager(NotEnoughUpdates neu, NEUIO neuio, File configLocation) { this.neu = neu; this.configLocation = configLocation; this.neuio = neuio; - this.auctionManager = new AuctionManager(this); + this.auctionManager = new APIManager(this); GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting(); gsonBuilder.registerTypeAdapter(Options.Option.class, Options.createSerializer()); @@ -86,8 +84,8 @@ public class NEUManager { this.loadConfig(); - this.itemsLocation = new File(configLocation, "items"); - itemsLocation.mkdir(); + this.repoLocation = new File(configLocation, "repo"); + repoLocation.mkdir(); this.itemShaLocation = new File(configLocation, "itemSha.json"); try { @@ -112,6 +110,22 @@ public class NEUManager { public float craftCost = -1; } + public void setCurrentProfile(String currentProfile) { + this.currentProfile = currentProfile; + } + + public void setCurrentProfileBackup(String currentProfile) { + this.currentProfileBackup = currentProfile; + } + + public String getCurrentProfile() { + if(currentProfile == null || currentProfile.length() == 0) { + return currentProfileBackup; + } else { + return currentProfile; + } + } + public boolean isVanillaItem(String internalname) { //Removes trailing numbers and underscores, eg. LEAVES_2-3 -> LEAVES String vanillaName = internalname.split("-")[0]; @@ -344,54 +358,83 @@ public class NEUManager { * repository. */ public void loadItemInformation() { - if(config.autoupdate.value) { - JOptionPane pane = new JOptionPane("Getting items to download from remote repository."); - JDialog dialog = pane.createDialog("NotEnoughUpdates Remote Sync"); - dialog.setModal(false); - //dialog.setVisible(true); + try { + if(config.autoupdate.value) { + JOptionPane pane = new JOptionPane("Getting items to download from remote repository."); + JDialog dialog = pane.createDialog("NotEnoughUpdates Remote Sync"); + dialog.setModal(false); + //dialog.setVisible(true); - if (Display.isActive()) dialog.toFront(); + if (Display.isActive()) dialog.toFront(); - HashMap oldShas = new HashMap<>(); - for (Map.Entry entry : itemShaConfig.entrySet()) { - if (new File(itemsLocation, entry.getKey() + ".json").exists()) { - oldShas.put(entry.getKey() + ".json", entry.getValue().getAsString()); + HashMap oldShas = new HashMap<>(); + for (Map.Entry entry : itemShaConfig.entrySet()) { + if (new File(repoLocation, entry.getKey() + ".json").exists()) { + oldShas.put(entry.getKey() + ".json", entry.getValue().getAsString()); + } } - } - Map changedFiles = neuio.getChangedItems(oldShas); + Map changedFiles = neuio.getChangedItems(oldShas); - if (changedFiles != null) { - for (Map.Entry changedFile : changedFiles.entrySet()) { - itemShaConfig.addProperty(changedFile.getKey().substring(0, changedFile.getKey().length() - 5), - changedFile.getValue()); - } - try { - writeJson(itemShaConfig, itemShaLocation); - } catch (IOException e) { + if (changedFiles != null) { + for (Map.Entry changedFile : changedFiles.entrySet()) { + itemShaConfig.addProperty(changedFile.getKey().substring(0, changedFile.getKey().length() - 5), + changedFile.getValue()); + } + try { + writeJson(itemShaConfig, itemShaLocation); + } catch (IOException e) { + } } - } - if (Display.isActive()) dialog.toFront(); + if (Display.isActive()) dialog.toFront(); + + if (changedFiles != null && changedFiles.size() <= 20) { + + String startMessage = "NotEnoughUpdates: Syncing with remote repository ("; + int downloaded = 0; - if (changedFiles != null && changedFiles.size() <= 20) { - Map downloads = neuio.getItemsDownload(changedFiles.keySet()); + String dlUrl = "https://raw.githubusercontent.com/Moulberry/NotEnoughUpdates-REPO/master/"; - String startMessage = "NotEnoughUpdates: Syncing with remote repository ("; - int downloaded = 0; + for (String name : changedFiles.keySet()) { + pane.setMessage(startMessage + (++downloaded) + "/" + changedFiles.size() + ")\nCurrent: " + name); + dialog.pack(); + dialog.setVisible(true); + if (Display.isActive()) dialog.toFront(); - for (Map.Entry entry : downloads.entrySet()) { - pane.setMessage(startMessage + (++downloaded) + "/" + downloads.size() + ")\nCurrent: " + entry.getKey()); + File item = new File(repoLocation, name); + try { + item.createNewFile(); + } catch (IOException e) { + } + try (BufferedInputStream inStream = new BufferedInputStream(new URL(dlUrl+name).openStream()); + FileOutputStream fileOutputStream = new FileOutputStream(item)) { + byte dataBuffer[] = new byte[1024]; + int bytesRead; + while ((bytesRead = inStream.read(dataBuffer, 0, 1024)) != -1) { + fileOutputStream.write(dataBuffer, 0, bytesRead); + } + } catch (IOException e) { + } + } + } else { + Utils.recursiveDelete(repoLocation); + repoLocation.mkdirs(); + + //TODO: Store hard-coded value somewhere else + String dlUrl = "https://github.com/Moulberry/NotEnoughUpdates-REPO/archive/master.zip"; + + pane.setMessage("Downloading NEU Master Archive. (DL# >20)"); dialog.pack(); dialog.setVisible(true); if (Display.isActive()) dialog.toFront(); - File item = new File(itemsLocation, entry.getKey()); + File itemsZip = new File(repoLocation, "neu-items-master.zip"); try { - item.createNewFile(); + itemsZip.createNewFile(); } catch (IOException e) { } - try (BufferedInputStream inStream = new BufferedInputStream(new URL(entry.getValue()).openStream()); - FileOutputStream fileOutputStream = new FileOutputStream(item)) { + try (BufferedInputStream inStream = new BufferedInputStream(new URL(dlUrl).openStream()); + FileOutputStream fileOutputStream = new FileOutputStream(itemsZip)) { byte dataBuffer[] = new byte[1024]; int bytesRead; while ((bytesRead = inStream.read(dataBuffer, 0, 1024)) != -1) { @@ -400,45 +443,21 @@ public class NEUManager { } catch (IOException e) { e.printStackTrace(); } - } - } else { - //TODO: Store hard-coded value somewhere else - String dlUrl = "https://github.com/Moulberry/NotEnoughUpdates-REPO/archive/master.zip"; - pane.setMessage("Downloading NEU Master Archive. (DL# >20)"); - dialog.pack(); - dialog.setVisible(true); - if (Display.isActive()) dialog.toFront(); + pane.setMessage("Unzipping NEU Master Archive."); + dialog.pack(); + dialog.setVisible(true); + if (Display.isActive()) dialog.toFront(); - File itemsZip = new File(configLocation, "neu-items-master.zip"); - try { - itemsZip.createNewFile(); - } catch (IOException e) { - } - try (BufferedInputStream inStream = new BufferedInputStream(new URL(dlUrl).openStream()); - FileOutputStream fileOutputStream = new FileOutputStream(itemsZip)) { - byte dataBuffer[] = new byte[1024]; - int bytesRead; - while ((bytesRead = inStream.read(dataBuffer, 0, 1024)) != -1) { - fileOutputStream.write(dataBuffer, 0, bytesRead); - } - } catch (IOException e) { - e.printStackTrace(); + unzipIgnoreFirstFolder(itemsZip.getAbsolutePath(), repoLocation.getAbsolutePath()); } - pane.setMessage("Unzipping NEU Master Archive."); - dialog.pack(); - dialog.setVisible(true); - if (Display.isActive()) dialog.toFront(); - - unzipIgnoreFirstFolder(itemsZip.getAbsolutePath(), configLocation.getAbsolutePath()); + dialog.dispose(); } - - dialog.dispose(); - } + } catch(Exception e) {} Set currentlyInstalledItems = new HashSet<>(); - for(File f : itemsLocation.listFiles()) { + for(File f : new File(repoLocation, "items").listFiles()) { currentlyInstalledItems.add(f.getName().substring(0, f.getName().length()-5)); } @@ -448,7 +467,7 @@ public class NEUManager { } else { removedItems = new HashSet<>(); } - for(File f : itemsLocation.listFiles()) { + for(File f : new File(repoLocation, "items").listFiles()) { String internalname = f.getName().substring(0, f.getName().length()-5); if(!removedItems.contains(internalname)) { loadItem(internalname); @@ -464,7 +483,7 @@ public class NEUManager { public void loadItem(String internalName) { itemstackCache.remove(internalName); try { - JsonObject json = getJsonFromFile(new File(itemsLocation, internalName + ".json")); + JsonObject json = getJsonFromFile(new File(new File(repoLocation, "items"), internalName + ".json")); if(json == null) { return; } @@ -826,6 +845,14 @@ public class NEUManager { } } } + if("ENCHANTED_BOOK".equals(internalname)) { + NBTTagCompound enchants = ea.getCompoundTag("enchantments"); + + for(String enchname : enchants.getKeySet()) { + internalname = enchname.toUpperCase() + ";" + enchants.getInteger(enchname); + break; + } + } } return internalname; @@ -966,11 +993,11 @@ public class NEUManager { } public String getInternalNameForItem(ItemStack stack) { + if(stack == null) return null; NBTTagCompound tag = stack.getTagCompound(); return getInternalnameFromNBT(tag); } - //Currently unused in production. public void writeItemToFile(ItemStack stack) { String internalname = getInternalNameForItem(stack); @@ -984,7 +1011,7 @@ public class NEUManager { json.addProperty("modver", NotEnoughUpdates.VERSION); try { - writeJson(json, new File(itemsLocation, internalname+".json")); + writeJson(json, new File(new File(repoLocation, "items"), internalname+".json")); } catch (IOException e) {} loadItem(internalname); @@ -993,7 +1020,7 @@ public class NEUManager { /** * Constructs a GuiItemUsages from the recipe usage data (see #usagesMap) of a given item */ - public boolean displayGuiItemUsages(String internalName, String text) { + public boolean displayGuiItemUsages(String internalName) { List craftMatrices = new ArrayList<>(); List results = new ArrayList<>(); @@ -1035,14 +1062,14 @@ public class NEUManager { if(craftMatrices.size() > 0) { Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow( Minecraft.getMinecraft().thePlayer.openContainer.windowId)); - Minecraft.getMinecraft().displayGuiScreen(new GuiItemUsages(craftMatrices, results, text, this)); + Minecraft.getMinecraft().displayGuiScreen(new GuiItemRecipe("Item Usages", craftMatrices, results, this)); return true; } return false; } /** - * Constructs a GuiItemRecipe from the recipe data of a given item. + * Constructs a GuiItemRecipeOld from the recipe data of a given item. */ public boolean displayGuiItemRecipe(String internalName, String text) { JsonObject item = getItemInformation().get(internalName); @@ -1071,7 +1098,8 @@ public class NEUManager { Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow( Minecraft.getMinecraft().thePlayer.openContainer.windowId)); - Minecraft.getMinecraft().displayGuiScreen(new GuiItemRecipe(craftMatrix, item, text, this)); + Minecraft.getMinecraft().displayGuiScreen(new GuiItemRecipe(text!=null?text:"Item Recipe", + Lists.newArrayList(craftMatrix), Lists.newArrayList(item), this)); return true; } return false; @@ -1299,7 +1327,7 @@ public class NEUManager { } public void writeJsonDefaultDir(JsonObject json, String filename) throws IOException { - File file = new File(itemsLocation, filename); + File file = new File(new File(repoLocation, "items"), filename); writeJson(json, file); } @@ -1335,6 +1363,7 @@ public class NEUManager { NBTTagCompound tag = JsonToNBT.getTagFromJson(json.get("nbttag").getAsString()); stack.setTagCompound(tag); } catch(NBTException e) { + if(json.get("internalname").getAsString().equalsIgnoreCase("ROCK;0")) e.printStackTrace(); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 475f6a99..23def271 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1,9 +1,14 @@ package io.github.moulberry.notenoughupdates; +import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.infopanes.*; import io.github.moulberry.notenoughupdates.itemeditor.NEUItemEditor; +import io.github.moulberry.notenoughupdates.mbgui.MBAnchorPoint; +import io.github.moulberry.notenoughupdates.mbgui.MBGuiElement; +import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupFloating; +import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupHorz; import io.github.moulberry.notenoughupdates.util.LerpingFloat; import io.github.moulberry.notenoughupdates.util.LerpingInteger; import io.github.moulberry.notenoughupdates.util.Utils; @@ -37,6 +42,7 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; +import org.lwjgl.util.vector.Vector2f; import java.awt.*; import java.lang.reflect.InvocationTargetException; @@ -72,8 +78,8 @@ public class NEUOverlay extends Gui { //Various constants used for GUI structure private int searchBarXSize = 200; - private final int searchBarYOffset = 10; private final int searchBarYSize = 40; + private final int searchBarYOffset = 10; private final int searchBarPadding = 2; private float oldWidthMult = 0; @@ -109,7 +115,7 @@ public class NEUOverlay extends Gui { private boolean redrawItems = false; private boolean searchBarHasFocus = false; - GuiTextField textField = new GuiTextField(0, null, 0, 0, 0, 0); + private GuiTextField textField = new GuiTextField(0, null, 0, 0, 0, 0); private static final int COMPARE_MODE_ALPHABETICAL = 0; private static final int COMPARE_MODE_RARITY = 1; @@ -126,10 +132,403 @@ public class NEUOverlay extends Gui { private boolean disabled = false; + private int lastScreenWidth; + private int lastScreenHeight; + private int lastScale; + + private List textToDisplay = null; + + public MBGuiGroupFloating guiGroup = null; + public NEUOverlay(NEUManager manager) { this.manager = manager; textField.setFocused(true); textField.setCanLoseFocus(false); + + guiGroup = createGuiGroup(); + } + + private MBGuiElement createSearchBar() { + return new MBGuiElement() { + public int getWidth() { + int paddingUnscaled = getPaddingUnscaled(); + + return getSearchBarXSize() + 2*paddingUnscaled; + } + + public int getHeight() { + int paddingUnscaled = getPaddingUnscaled(); + + return getSearchBarYSize() + 2*paddingUnscaled; + } + + @Override + public void mouseClick(float x, float y, int mouseX, int mouseY) { + if(Mouse.getEventButtonState()) { + setSearchBarFocus(true); + if(Mouse.getEventButton() == 1) { //Right mouse button down + textField.setText(""); + updateSearch(); + } else { + if(System.currentTimeMillis() - millisLastLeftClick < 300) { + searchMode = !searchMode; + } + textField.setCursorPosition(getClickedIndex(mouseX, mouseY)); + millisLastLeftClick = System.currentTimeMillis(); + } + } + } + + @Override + public void mouseClickOutside() { + setSearchBarFocus(false); + } + + @Override + public void render(float x, float y) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int paddingUnscaled = getPaddingUnscaled(); + + //Search bar background + drawRect((int)x, (int)y, + (int)x + getWidth(), (int)y + getHeight(), + searchMode ? Color.YELLOW.getRGB() : Color.WHITE.getRGB()); + + drawRect((int)x + paddingUnscaled, (int)y + paddingUnscaled, + (int)x - paddingUnscaled + getWidth(), (int)y - paddingUnscaled + getHeight(), + Color.BLACK.getRGB()); + + //Search bar text + fr.drawString(textField.getText(), (int)x + 5, + (int) y-4 + getHeight()/2, Color.WHITE.getRGB()); + + //Determines position of cursor. Cursor blinks on and off every 500ms. + if(searchBarHasFocus && System.currentTimeMillis()%1000>500) { + String textBeforeCursor = textField.getText().substring(0, textField.getCursorPosition()); + int textBeforeCursorWidth = fr.getStringWidth(textBeforeCursor); + drawRect((int)x + 5 + textBeforeCursorWidth, + (int)y-5 + getHeight()/2, + (int)x + 5 + textBeforeCursorWidth+1, + (int)y-4+9 + getHeight()/2, Color.WHITE.getRGB()); + } + + String selectedText = textField.getSelectedText(); + if(!selectedText.isEmpty()) { + int selectionWidth = fr.getStringWidth(selectedText); + + int leftIndex = Math.min(textField.getCursorPosition(), textField.getSelectionEnd()); + String textBeforeSelection = textField.getText().substring(0, leftIndex); + int textBeforeSelectionWidth = fr.getStringWidth(textBeforeSelection); + + drawRect((int)x + 5 + textBeforeSelectionWidth, + (int)y-5 + getHeight()/2, + (int)x + 5 + textBeforeSelectionWidth + selectionWidth, + (int)y-4+9 + getHeight()/2, Color.LIGHT_GRAY.getRGB()); + + fr.drawString(selectedText, + (int)x + 5 + textBeforeSelectionWidth, + (int)y-4 + getHeight()/2, Color.BLACK.getRGB()); + } + } + + @Override + public void recalculate() { + } + }; + } + + private MBGuiElement createSettingsButton(NEUOverlay overlay) { + return new MBGuiElement() { + @Override + public int getWidth() { + return getSearchBarYSize()+getPaddingUnscaled()*2; + } + + @Override + public int getHeight() { + return getWidth(); + } + + @Override + public void recalculate() { + } + + @Override + public void mouseClick(float x, float y, int mouseX, int mouseY) { + if(Mouse.getEventButtonState()) { + if(activeInfoPane instanceof SettingsInfoPane) { + displayInformationPane(null); + } else { + displayInformationPane(new SettingsInfoPane(overlay, manager)); + } + Utils.playPressSound(); + } + } + + @Override + public void mouseClickOutside() { + } + + @Override + public void render(float x, float y) { + int paddingUnscaled = getPaddingUnscaled(); + + Minecraft.getMinecraft().getTextureManager().bindTexture(settings); + drawRect((int)x, (int)y, + (int)x + getWidth(), (int)y + getHeight(), + Color.WHITE.getRGB()); + + + drawRect((int)x + paddingUnscaled, (int)y + paddingUnscaled, + (int)x + getWidth() - paddingUnscaled, (int)y + getHeight() - paddingUnscaled, + Color.GRAY.getRGB()); + + GlStateManager.color(1f, 1f, 1f, 1f); + Utils.drawTexturedRect((int)x + paddingUnscaled, (int)y + paddingUnscaled, + getSearchBarYSize(), getSearchBarYSize()); + GlStateManager.bindTexture(0); + } + }; + } + + private MBGuiElement createHelpButton(NEUOverlay overlay) { + return new MBGuiElement() { + @Override + public int getWidth() { + return getSearchBarYSize()+getPaddingUnscaled()*2; + } + + @Override + public int getHeight() { + return getWidth(); + } + + @Override + public void recalculate() { + } + + @Override + public void mouseClick(float x, float y, int mouseX, int mouseY) { + if(Mouse.getEventButtonState()) { + displayInformationPane(HTMLInfoPane.createFromWikiUrl(overlay, manager, "Help", + "https://moulberry.github.io/files/neu_help.html")); + Utils.playPressSound(); + } + } + + @Override + public void mouseClickOutside() { + } + + @Override + public void render(float x, float y) { + int paddingUnscaled = getPaddingUnscaled(); + + Minecraft.getMinecraft().getTextureManager().bindTexture(help); + drawRect((int)x, (int)y, + (int)x + getWidth(), (int)y + getHeight(), + Color.WHITE.getRGB()); + + drawRect((int)x + paddingUnscaled, (int)y + paddingUnscaled, + (int)x + getWidth() - paddingUnscaled, (int)y + getHeight() - paddingUnscaled, + Color.GRAY.getRGB()); + + GlStateManager.color(1f, 1f, 1f, 1f); + Utils.drawTexturedRect((int)x + paddingUnscaled, (int)y + paddingUnscaled, + getSearchBarYSize(), getSearchBarYSize()); + GlStateManager.bindTexture(0); + } + }; + } + + private MBGuiElement createQuickCommand(String quickCommandStr) { + return new MBGuiElement() { + @Override + public int getWidth() { + return getSearchBarYSize()+getPaddingUnscaled()*2; + } + + @Override + public int getHeight() { + return getWidth(); + } + + @Override + public void recalculate() { + } + + @Override + public void mouseClick(float x, float y, int mouseX, int mouseY) { + if(!manager.config.showQuickCommands.value) return; + + if((manager.config.quickcommandMousePress.value && Mouse.getEventButtonState()) || + (!manager.config.quickcommandMousePress.value && !Mouse.getEventButtonState() && Mouse.getEventButton() != -1)) { + if(quickCommandStr.contains(":")) { + String command = quickCommandStr.split(":")[0].trim(); + if(command.startsWith("/")) { + NotEnoughUpdates.INSTANCE.sendChatMessage(command); + Utils.playPressSound(); + } else { + ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/"+command); //Need to add '/' because of sk1er's patcher being unbelievably shit + Utils.playPressSound(); + } + } + } + } + + @Override + public void mouseClickOutside() { + } + + @Override + public void render(float x, float y) { + if(!manager.config.showQuickCommands.value) return; + + int paddingUnscaled = getPaddingUnscaled(); + int bigItemSize = getSearchBarYSize(); + + if(quickCommandStr.split(":").length!=3) { + return; + } + String display = quickCommandStr.split(":")[2]; + ItemStack render = null; + float extraScale = 1; + if(display.length() > 20) { //Custom head + render = 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(display.getBytes()).toString(); + skullOwner.setString("Id", uuid); + skullOwner.setString("Name", uuid); + + textures_0.setString("Value", display); + textures.appendTag(textures_0); + + properties.setTag("textures", textures); + skullOwner.setTag("Properties", properties); + nbt.setTag("SkullOwner", skullOwner); + render.setTagCompound(nbt); + + extraScale = 1.3f; + } else if(manager.getItemInformation().containsKey(display)) { + render = manager.jsonToStack(manager.getItemInformation().get(display)); + } else { + Item item = Item.itemRegistry.getObject(new ResourceLocation(display.toLowerCase())); + if(item != null) { + render = new ItemStack(item); + } + } + if(render != null) { + Minecraft.getMinecraft().getTextureManager().bindTexture(item_mask); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(x, y, + bigItemSize + paddingUnscaled*2, bigItemSize + paddingUnscaled*2, GL11.GL_LINEAR); + GlStateManager.color(fg.getRed() / 255f,fg.getGreen() / 255f, + fg.getBlue() / 255f, fg.getAlpha() / 255f); + Utils.drawTexturedRect(x+paddingUnscaled, y+paddingUnscaled, bigItemSize, bigItemSize, GL11.GL_LINEAR); + + int mouseX = Mouse.getX() * scaledresolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; + int mouseY = scaledresolution.getScaledHeight() - Mouse.getY() * scaledresolution.getScaledHeight() / Minecraft.getMinecraft().displayHeight - 1; + + if(mouseX > x && mouseX < x+bigItemSize) { + if(mouseY > y && mouseY < y+bigItemSize) { + textToDisplay = new ArrayList<>(); + textToDisplay.add(EnumChatFormatting.GRAY+quickCommandStr.split(":")[1]); + } + } + + float itemScale = bigItemSize/(float)ITEM_SIZE*extraScale; + GlStateManager.pushMatrix(); + GlStateManager.scale(itemScale, itemScale, 1); + GlStateManager.translate((x-(extraScale-1)*bigItemSize/2+paddingUnscaled) /itemScale, + (y-(extraScale-1)*bigItemSize/2+paddingUnscaled)/itemScale, 0f); + Utils.drawItemStack(render, 0, 0); + GlStateManager.popMatrix(); + } + } + }; + } + + private MBGuiGroupHorz createQuickCommandGroup() { + List children = new ArrayList<>(); + for(String quickCommand : manager.config.quickCommands.value) { + children.add(createQuickCommand(quickCommand)); + } + return new MBGuiGroupHorz(children) { + public int getPadding() { + return getPaddingUnscaled()*4; + } + }; + } + + private MBGuiGroupHorz createSearchBarGroup() { + List children = Lists.newArrayList(createSettingsButton(this), createSearchBar(), createHelpButton(this)); + return new MBGuiGroupHorz(children) { + public int getPadding() { + return getPaddingUnscaled()*4; + } + }; + } + + private MBGuiGroupFloating createGuiGroup() { + LinkedHashMap map = new LinkedHashMap<>(); + + MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(manager.config.overlaySearchBar.value); + MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(manager.config.overlayQuickCommand.value); + + searchBarAnchor = searchBarAnchor != null ? searchBarAnchor : + new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, -searchBarYOffset)); + quickCommandAnchor = quickCommandAnchor != null ? quickCommandAnchor : + new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, + -searchBarYOffset-getSearchBarYSize()-getPaddingUnscaled()*4)); + + map.put(createSearchBarGroup(), searchBarAnchor); + map.put(createQuickCommandGroup(), quickCommandAnchor); + + return new MBGuiGroupFloating(scaledresolution.getScaledWidth(), scaledresolution.getScaledHeight(), map); + } + + public void resetAnchors(boolean onlyIfNull) { + MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(manager.config.overlaySearchBar.value); + MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(manager.config.overlayQuickCommand.value); + + if(onlyIfNull) { + searchBarAnchor = searchBarAnchor != null ? null : + new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, -searchBarYOffset)); + quickCommandAnchor = quickCommandAnchor != null ? null : + new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, + -searchBarYOffset-getSearchBarYSize()-getPaddingUnscaled()*4)); + } else { + searchBarAnchor = searchBarAnchor != null ? searchBarAnchor : + new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, -searchBarYOffset)); + quickCommandAnchor = quickCommandAnchor != null ? quickCommandAnchor : + new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, + -searchBarYOffset-getSearchBarYSize()-getPaddingUnscaled()*4)); + } + + + int index = 0; + Set set = new LinkedHashSet<>(guiGroup.getChildrenMap().keySet()); + for(MBGuiElement element : set) { + switch(index) { + case 0: + if(searchBarAnchor == null) continue; + guiGroup.getChildrenMap().get(element).anchorPoint = searchBarAnchor.anchorPoint; + guiGroup.getChildrenMap().get(element).offset = searchBarAnchor.offset; + break; + case 1: + if(quickCommandAnchor == null) continue; + guiGroup.getChildrenMap().get(element).anchorPoint = quickCommandAnchor.anchorPoint; + guiGroup.getChildrenMap().get(element).offset = quickCommandAnchor.offset; + break; + } + index++; + } } /** @@ -201,6 +600,8 @@ public class NEUOverlay extends Gui { //Unfocuses the search bar by default. Search bar is focused if the click is on the bar itself. if(Mouse.getEventButtonState()) setSearchBarFocus(false); + guiGroup.mouseClick(0, 0, mouseX, mouseY); + //Item selection (right) gui if(mouseX > width*getItemPaneOffsetFactor()) { if(!Mouse.getEventButtonState()) return true; //End early if the mouse isn't pressed, but still cancel event. @@ -318,89 +719,6 @@ public class NEUOverlay extends Gui { } } } - - - //Quickcommands - int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); - if(paddingUnscaled < 1) paddingUnscaled = 1; - int topTextBox = height - searchBarYOffset - getSearchBarYSize(); - - if(Mouse.getEventButtonState() && manager.config.showQuickCommands.value) { - ArrayList quickCommands = manager.config.quickCommands.value; - int bigItemSize = getSearchBarYSize(); - int bigItemPadding = paddingUnscaled*4; - int xStart = width/2 + bigItemPadding/2 - (bigItemSize+bigItemPadding)*quickCommands.size()/2; - int xEnd = width/2 - bigItemPadding/2 + (bigItemSize+bigItemPadding)*quickCommands.size()/2; - int y = topTextBox - bigItemSize - bigItemPadding - paddingUnscaled*2; - - if(mouseY >= y && mouseY <= topTextBox-paddingUnscaled*2) { - if(mouseX > xStart && mouseX < xEnd) { - if((mouseX - xStart)%(bigItemSize+bigItemPadding) < bigItemSize) { - int index = (mouseX - xStart)/(bigItemSize+bigItemPadding); - if(index >= 0 && index < quickCommands.size()) { - String quickCommand = quickCommands.get(index); - if(quickCommand.contains(":")) { - String command = quickCommand.split(":")[0].trim(); - if(command.startsWith("/")) { - NotEnoughUpdates.INSTANCE.sendChatMessage(command); - Utils.playPressSound(); - return true; - } else { - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/"+command); //Need to add '/' because of sk1er's patcher being unbelievably shit - Utils.playPressSound(); - return true; - } - } - } - } - } - } - } - - //Search bar - if(mouseX >= width/2 - getSearchBarXSize()/2 && mouseX <= width/2 + getSearchBarXSize()/2) { - if(mouseY >= height - searchBarYOffset - getSearchBarYSize() && - mouseY <= height - searchBarYOffset) { - if(Mouse.getEventButtonState()) { - setSearchBarFocus(true); - if(Mouse.getEventButton() == 1) { //Right mouse button down - textField.setText(""); - updateSearch(); - } else { - if(System.currentTimeMillis() - millisLastLeftClick < 300) { - searchMode = !searchMode; - } - textField.setCursorPosition(getClickedIndex(mouseX, mouseY)); - millisLastLeftClick = System.currentTimeMillis(); - } - } - return true; - } - } - - int iconSize = getSearchBarYSize()+paddingUnscaled*2; - - if(mouseY > topTextBox - paddingUnscaled && mouseY < topTextBox - paddingUnscaled + iconSize) { - if(mouseX > width/2 + getSearchBarXSize()/2 + paddingUnscaled*6 && - mouseX < width/2 + getSearchBarXSize()/2 + paddingUnscaled*6 + iconSize) { - if(Mouse.getEventButtonState()) { - displayInformationPane(HTMLInfoPane.createFromWikiUrl(this, manager, "Help", - "https://moulberry.github.io/files/neu_help.html")); - Utils.playPressSound(); - } - } else if(mouseX > width/2 - getSearchBarXSize()/2 - paddingUnscaled*6 - iconSize && - mouseX < width/2 - getSearchBarXSize()/2 - paddingUnscaled*6) { - if(Mouse.getEventButtonState()) { - if(activeInfoPane instanceof SettingsInfoPane) { - displayInformationPane(null); - } else { - displayInformationPane(new SettingsInfoPane(this, manager)); - } - Utils.playPressSound(); - } - } - } - if(activeInfoPane != null) { if(mouseX < width*getInfoPaneOffsetFactor()) { activeInfoPane.mouseInput(width, height, mouseX, mouseY, mouseDown); @@ -413,6 +731,13 @@ public class NEUOverlay extends Gui { return false; } + public int getPaddingUnscaled() { + int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); + if(paddingUnscaled < 1) paddingUnscaled = 1; + + return paddingUnscaled; + } + /** * Returns searchBarXSize, scaled by 0.8 if gui scale == AUTO. */ @@ -554,7 +879,7 @@ public class NEUOverlay extends Gui { JsonObject item = manager.getItemInformation().get(internalname.get()); if(item != null) { if(keyPressed == manager.keybindViewUsages.getKeyCode()) { - manager.displayGuiItemUsages(internalname.get(), ""); + manager.displayGuiItemUsages(internalname.get()); return true; } else if(keyPressed == manager.keybindFavourite.getKeyCode()) { toggleFavourite(item.get("internalname").getAsString()); @@ -660,8 +985,11 @@ public class NEUOverlay extends Gui { if(rarity1 < rarity2) return mult; if(rarity1 > rarity2) return -mult; } else if(getCompareMode() == COMPARE_MODE_VALUE) { - float cost1 = manager.getCraftCost(o1.get("internalname").getAsString()).craftCost; - float cost2 = manager.getCraftCost(o2.get("internalname").getAsString()).craftCost; + float cost1 = manager.auctionManager.getLowestBin(o1.get("internalname").getAsString()); + float cost2 = manager.auctionManager.getLowestBin(o2.get("internalname").getAsString()); + + if(cost1 == -1) cost1 = manager.getCraftCost(o1.get("internalname").getAsString()).craftCost; + if(cost2 == -1) cost2 = manager.getCraftCost(o2.get("internalname").getAsString()).craftCost; if(cost1 < cost2) return mult; if(cost1 > cost2) return -mult; @@ -1203,6 +1531,24 @@ public class NEUOverlay extends Gui { blurOutputVert.unbindFramebufferTexture(); } + public void updateGuiGroupSize() { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledresolution.getScaledWidth(); + int height = scaledresolution.getScaledHeight(); + + if(lastScreenWidth != width || lastScreenHeight != height || scaledresolution.getScaleFactor() != lastScale) { + guiGroup.width = width; + guiGroup.height = height; + + resetAnchors(true); + guiGroup.recalculate(); + + lastScreenWidth = width; + lastScreenHeight = height; + lastScale = scaledresolution.getScaleFactor(); + } + } + int guiScaleLast = 0; /** @@ -1217,6 +1563,8 @@ public class NEUOverlay extends Gui { int width = scaledresolution.getScaledWidth(); int height = scaledresolution.getScaledHeight(); + updateGuiGroupSize(); + if(guiScaleLast != scaledresolution.getScaleFactor()) { guiScaleLast = scaledresolution.getScaleFactor(); redrawItems = true; @@ -1285,7 +1633,6 @@ public class NEUOverlay extends Gui { int rightSide = leftSide+paneWidth-getBoxPadding()-getItemBoxXPadding(); //Tab - Minecraft.getMinecraft().getTextureManager().bindTexture(itemPaneTabArrow); GlStateManager.color(1f, 1f, 1f, 0.3f); Utils.drawTexturedRect(width-itemPaneTabOffset.getValue(), height/2 - 50, 20, 100); @@ -1294,7 +1641,9 @@ public class NEUOverlay extends Gui { if(mouseX > width-itemPaneTabOffset.getValue() && mouseY > height/2 - 50 && mouseY < height/2 + 50) { if(!hoveringItemPaneToggle) { - itemPaneOpen = !itemPaneOpen; + if(!manager.config.disableItemTabOpen.value) { + itemPaneOpen = !itemPaneOpen; + } hoveringItemPaneToggle = true; } } else { @@ -1303,7 +1652,6 @@ public class NEUOverlay extends Gui { //Atomic reference used so that below lambda doesn't complain about non-effectively-final variable AtomicReference tooltipToDisplay = new AtomicReference<>(null); - List textToDisplay = null; if(itemPaneOffsetFactor.getValue() < 1) { renderBlurredBackground(width, height, leftSide+getBoxPadding()-5, getBoxPadding()-5, @@ -1430,159 +1778,10 @@ public class NEUOverlay extends Gui { } /** - * Search bar + * Search bar & quickcommand elements */ - int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); - if(paddingUnscaled < 1) paddingUnscaled = 1; - - int topTextBox = height - searchBarYOffset - getSearchBarYSize(); - - //Search bar background - drawRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled, - topTextBox - paddingUnscaled, - width/2 + getSearchBarXSize()/2 + paddingUnscaled, - height - searchBarYOffset + paddingUnscaled, searchMode ? Color.YELLOW.getRGB() : Color.WHITE.getRGB()); - drawRect(width/2 - getSearchBarXSize()/2, - topTextBox, - width/2 + getSearchBarXSize()/2, - height - searchBarYOffset, Color.BLACK.getRGB()); - - //Quickcommands - if(manager.config.showQuickCommands.value) { - ArrayList quickCommands = manager.config.quickCommands.value; - int bigItemSize = getSearchBarYSize(); - int bigItemPadding = paddingUnscaled*4; - int x = width/2 + bigItemPadding/2 - (bigItemSize+bigItemPadding)*quickCommands.size()/2; - int y = topTextBox - bigItemSize - bigItemPadding - paddingUnscaled*2; - - for(String quickCommand : quickCommands) { - if(quickCommand.split(":").length!=3) { - continue; - } - String display = quickCommand.split(":")[2]; - ItemStack render = null; - float extraScale = 1; - if(display.length() > 20) { //Custom head - render = 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(display.getBytes()).toString(); - skullOwner.setString("Id", uuid); - skullOwner.setString("Name", uuid); - - textures_0.setString("Value", display); - textures.appendTag(textures_0); - - properties.setTag("textures", textures); - skullOwner.setTag("Properties", properties); - nbt.setTag("SkullOwner", skullOwner); - render.setTagCompound(nbt); - - extraScale = 1.3f; - } else if(manager.getItemInformation().containsKey(display)) { - render = manager.jsonToStack(manager.getItemInformation().get(display)); - } else { - Item item = Item.itemRegistry.getObject(new ResourceLocation(display.toLowerCase())); - if(item != null) { - render = new ItemStack(item); - } - } - if(render != null) { - Minecraft.getMinecraft().getTextureManager().bindTexture(item_mask); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(x - paddingUnscaled, y - paddingUnscaled, - bigItemSize + paddingUnscaled*2, bigItemSize + paddingUnscaled*2, GL11.GL_NEAREST); - GlStateManager.color(fg.getRed() / 255f,fg.getGreen() / 255f, - fg.getBlue() / 255f, fg.getAlpha() / 255f); - Utils.drawTexturedRect(x, y, bigItemSize, bigItemSize, GL11.GL_NEAREST); - - if(mouseX > x && mouseX < x+bigItemSize) { - if(mouseY > y && mouseY < y+bigItemSize) { - textToDisplay = new ArrayList<>(); - textToDisplay.add(EnumChatFormatting.GRAY+quickCommand.split(":")[1]); - } - } - - float itemScale = bigItemSize/(float)ITEM_SIZE*extraScale; - GlStateManager.pushMatrix(); - GlStateManager.scale(itemScale, itemScale, 1); - GlStateManager.translate((x-(extraScale-1)*bigItemSize/2) /itemScale, - (y-(extraScale-1)*bigItemSize/2)/itemScale, 0f); - Utils.drawItemStack(render, 0, 0); - GlStateManager.popMatrix(); - } - x += bigItemSize + bigItemPadding; - } - } - - //Settings - int iconSize = getSearchBarYSize()+paddingUnscaled*2; - Minecraft.getMinecraft().getTextureManager().bindTexture(settings); - drawRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled*6 - iconSize, - topTextBox - paddingUnscaled, - width/2 - getSearchBarXSize()/2 - paddingUnscaled*6, - topTextBox - paddingUnscaled + iconSize, Color.WHITE.getRGB()); - - drawRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled*5 - iconSize, - topTextBox, - width/2 - getSearchBarXSize()/2 - paddingUnscaled*7, - topTextBox - paddingUnscaled*2 + iconSize, Color.GRAY.getRGB()); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect(width/2 - getSearchBarXSize()/2 - paddingUnscaled*6 - iconSize, topTextBox - paddingUnscaled, iconSize, iconSize); - GlStateManager.bindTexture(0); - - //Help - Minecraft.getMinecraft().getTextureManager().bindTexture(help); - drawRect(width/2 + getSearchBarXSize()/2 + paddingUnscaled*6, - topTextBox - paddingUnscaled, - width/2 + getSearchBarXSize()/2 + paddingUnscaled*6 + iconSize, - topTextBox - paddingUnscaled + iconSize, Color.WHITE.getRGB()); - - drawRect(width/2 + getSearchBarXSize()/2 + paddingUnscaled*7, - topTextBox, - width/2 + getSearchBarXSize()/2 + paddingUnscaled*5 + iconSize, - topTextBox - paddingUnscaled*2 + iconSize, Color.GRAY.getRGB()); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect(width/2 + getSearchBarXSize()/2 + paddingUnscaled*7, topTextBox, - iconSize-paddingUnscaled*2, iconSize-paddingUnscaled*2); - GlStateManager.bindTexture(0); - - //Search bar text - fr.drawString(textField.getText(), width/2 - getSearchBarXSize()/2 + 5, - topTextBox+(getSearchBarYSize()-8)/2, Color.WHITE.getRGB()); - - //Determines position of cursor. Cursor blinks on and off every 500ms. - if(searchBarHasFocus && System.currentTimeMillis()%1000>500) { - String textBeforeCursor = textField.getText().substring(0, textField.getCursorPosition()); - int textBeforeCursorWidth = fr.getStringWidth(textBeforeCursor); - drawRect(width/2 - getSearchBarXSize()/2 + 5 + textBeforeCursorWidth, - topTextBox+(getSearchBarYSize()-8)/2-1, - width/2 - getSearchBarXSize()/2 + 5 + textBeforeCursorWidth+1, - topTextBox+(getSearchBarYSize()-8)/2+9, Color.WHITE.getRGB()); - } - - String selectedText = textField.getSelectedText(); - if(!selectedText.isEmpty()) { - int selectionWidth = fr.getStringWidth(selectedText); - - int leftIndex = Math.min(textField.getCursorPosition(), textField.getSelectionEnd()); - String textBeforeSelection = textField.getText().substring(0, leftIndex); - int textBeforeSelectionWidth = fr.getStringWidth(textBeforeSelection); - - drawRect(width/2 - getSearchBarXSize()/2 + 5 + textBeforeSelectionWidth, - topTextBox+(getSearchBarYSize()-8)/2-1, - width/2 - getSearchBarXSize()/2 + 5 + textBeforeSelectionWidth + selectionWidth, - topTextBox+(getSearchBarYSize()-8)/2+9, Color.LIGHT_GRAY.getRGB()); - - fr.drawString(selectedText, - width/2 - getSearchBarXSize()/2 + 5 + textBeforeSelectionWidth, - topTextBox+(getSearchBarYSize()-8)/2, Color.BLACK.getRGB()); - } + guiGroup.render(0, 0); + resetAnchors(true); /** * Item info (left) gui element rendering @@ -1611,17 +1810,24 @@ public class NEUOverlay extends Gui { text.add(lore.get(i).getAsString()); } - JsonObject auctionInfo = manager.getItemAuctionInfo(json.get("internalname").getAsString()); - JsonObject bazaarInfo = manager.getBazaarInfo(json.get("internalname").getAsString()); + String internalname = json.get("internalname").getAsString(); + JsonObject auctionInfo = manager.getItemAuctionInfo(internalname); + JsonObject bazaarInfo = manager.getBazaarInfo(internalname); boolean hasAuctionPrice = auctionInfo != null; boolean hasBazaarPrice = bazaarInfo != null; + int lowestBin = manager.auctionManager.getLowestBin(internalname); + NumberFormat format = NumberFormat.getInstance(Locale.US); NEUManager.CraftInfo craftCost = manager.getCraftCost(json.get("internalname").getAsString()); - if(hasAuctionPrice || hasBazaarPrice || craftCost.fromRecipe) text.add(""); + if(hasAuctionPrice || hasBazaarPrice || craftCost.fromRecipe || lowestBin > 0) text.add(""); + if(lowestBin > 0) { + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); + } if(hasBazaarPrice) { int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat(); text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy: "+ @@ -1665,6 +1871,7 @@ public class NEUOverlay extends Gui { } if(textToDisplay != null) { Utils.drawHoveringText(textToDisplay, mouseX, mouseY, width, height, -1, fr); + textToDisplay = null; } GlStateManager.enableBlend(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java new file mode 100644 index 00000000..28ecbc8e --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java @@ -0,0 +1,185 @@ +package io.github.moulberry.notenoughupdates; + +import io.github.moulberry.notenoughupdates.mbgui.MBAnchorPoint; +import io.github.moulberry.notenoughupdates.mbgui.MBGuiElement; +import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroup; +import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupFloating; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import org.lwjgl.input.Keyboard; +import org.lwjgl.util.vector.Vector2f; + +import java.awt.*; +import java.io.IOException; + +public class NEUOverlayPlacements extends GuiScreen { + + private int clickedX; + private int clickedY; + private int clickedAnchorX; + private int clickedAnchorY; + private MBGuiElement clickedElement; + private GuiButton guiButton = new GuiButton(0, 5, 5, "Reset to Default"); + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + drawDefaultBackground(); + + if(mouseX < 300 && mouseY < 300 && clickedElement != null) { + guiButton.yPosition = height - 5 - guiButton.height; + } else { + guiButton.yPosition = 5; + } + + guiButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); + + NotEnoughUpdates.INSTANCE.overlay.updateGuiGroupSize(); + + MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; + for(MBGuiElement element : mainGroup.getChildren()) { + MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(element); + Vector2f position = mainGroup.getChildrenPosition().get(element); + + drawRect((int)position.x, (int)position.y, + (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), new Color(100, 100, 100, 200).getRGB()); + + + switch(anchorPoint.anchorPoint) { + case TOPLEFT: + case TOPRIGHT: + case BOTLEFT: + case BOTRIGHT: + drawRect((int)(position.x+element.getWidth()*anchorPoint.anchorPoint.x*0.9f), + (int)(position.y+element.getHeight()*anchorPoint.anchorPoint.y*0.9f), + (int)(position.x+element.getWidth()*anchorPoint.anchorPoint.x*0.9f+element.getWidth()*0.1f), + (int)(position.y+element.getHeight()*anchorPoint.anchorPoint.y*0.9f+element.getHeight()*0.1f), + new Color(200, 200, 200, 100).getRGB()); + break; + case TOPMID: + drawRect((int)position.x, (int)position.y, + (int)position.x+element.getWidth(), (int)(position.y+element.getHeight()*0.1f), + new Color(200, 200, 200, 100).getRGB()); + break; + case MIDLEFT: + drawRect((int)position.x, (int)position.y, + (int)(position.x+element.getWidth()*0.1f), (int)position.y+element.getHeight(), + new Color(200, 200, 200, 100).getRGB()); + break; + case MIDRIGHT: + drawRect((int)(position.x+element.getWidth()*0.9f), (int)position.y, + (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), + new Color(200, 200, 200, 100).getRGB()); + break; + case BOTMID: + drawRect((int)position.x, (int)(position.y+element.getHeight()*0.9f), + (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), + new Color(200, 200, 200, 100).getRGB()); + break; + case MIDMID: + drawRect((int)(position.x+element.getWidth()*0.45f), (int)(position.y+element.getHeight()*0.45f), + (int)(position.x+element.getWidth()*0.55f), (int)(position.y+element.getHeight()*0.55f), + new Color(200, 200, 200, 100).getRGB()); + break; + + } + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; + for(MBGuiElement element : mainGroup.getChildren()) { + MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(element); + Vector2f position = mainGroup.getChildrenPosition().get(element); + + if(mouseX > position.x && mouseX < position.x + element.getWidth()) { + if(mouseY > position.y && mouseY < position.y + element.getHeight()) { + if(mouseButton == 0) { + clickedElement = element; + clickedX = mouseX; + clickedY = mouseY; + clickedAnchorX = (int)anchorPoint.offset.x; + clickedAnchorY = (int)anchorPoint.offset.y; + } else { + float anchorX = (width-element.getWidth()) * anchorPoint.anchorPoint.x + anchorPoint.offset.x; + float anchorY = (height-element.getHeight()) * anchorPoint.anchorPoint.y + anchorPoint.offset.y; + + MBAnchorPoint.AnchorPoint[] vals = MBAnchorPoint.AnchorPoint.values(); + anchorPoint.anchorPoint = vals[(anchorPoint.anchorPoint.ordinal()+1)%vals.length]; + + float screenX = (width-element.getWidth()) * anchorPoint.anchorPoint.x; + float screenY = (height-element.getHeight()) * anchorPoint.anchorPoint.y; + anchorPoint.offset.x = anchorX - screenX; + anchorPoint.offset.y = anchorY - screenY; + + mainGroup.recalculate(); + } + return; + } + } + } + + if(guiButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { + NotEnoughUpdates.INSTANCE.manager.config.overlayQuickCommand.value = ""; + NotEnoughUpdates.INSTANCE.manager.config.overlaySearchBar.value = ""; + try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} + NotEnoughUpdates.INSTANCE.overlay.resetAnchors(false); + + mainGroup.recalculate(); + } + clickedElement = null; + } + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + clickedElement = null; + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + if(clickedElement != null) { + MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; + MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(clickedElement); + + if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { + int dX = mouseX - clickedX; + int dY = mouseY - clickedY; + if(Math.abs(dX) > Math.abs(dY)) { + anchorPoint.offset.x = mouseX - clickedX + clickedAnchorX; + anchorPoint.offset.y = clickedAnchorY; + } else { + anchorPoint.offset.x = clickedAnchorX; + anchorPoint.offset.y = mouseY - clickedY + clickedAnchorY; + } + } else { + anchorPoint.offset.x = mouseX - clickedX + clickedAnchorX; + anchorPoint.offset.y = mouseY - clickedY + clickedAnchorY; + } + + int index = 0; + for(MBGuiElement element : mainGroup.getChildren()) { + if(element == clickedElement) { + if(index == 0) { + NotEnoughUpdates.INSTANCE.manager.config.overlaySearchBar.value = anchorPoint.toString(); + } else if(index == 1) { + NotEnoughUpdates.INSTANCE.manager.config.overlayQuickCommand.value = anchorPoint.toString(); + } + try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} + break; + } + index++; + } + + mainGroup.recalculate(); + } + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 0724a132..a589fe2b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -11,14 +11,19 @@ import io.github.moulberry.notenoughupdates.commands.SimpleCommand; import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.infopanes.CollectionLogInfoPane; import io.github.moulberry.notenoughupdates.infopanes.CosmeticsInfoPane; +import io.github.moulberry.notenoughupdates.questing.GuiQuestLine; +import io.github.moulberry.notenoughupdates.questing.NEUQuesting; 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.ScaledResolution; import net.minecraft.client.gui.inventory.*; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.settings.KeyBinding; import net.minecraft.command.ICommandSender; +import net.minecraft.event.ClickEvent; import net.minecraft.init.Blocks; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; @@ -29,6 +34,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Session; import net.minecraftforge.client.ClientCommandHandler; @@ -62,15 +68,17 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import static io.github.moulberry.notenoughupdates.GuiTextures.*; + @Mod(modid = NotEnoughUpdates.MODID, version = NotEnoughUpdates.VERSION) public class NotEnoughUpdates { public static final String MODID = "notenoughupdates"; - public static final String VERSION = "1.0.0"; + public static final String VERSION = "REL-1.0.0"; public static NotEnoughUpdates INSTANCE = null; public NEUManager manager; - private NEUOverlay overlay; + public NEUOverlay overlay; private NEUIO neuio; private static final long CHAT_MSG_COOLDOWN = 200; @@ -81,6 +89,8 @@ public class NotEnoughUpdates { private boolean hoverInv = false; private boolean focusInv = false; + private boolean joinedSB = false; + //Stolen from Biscut and used for detecting whether in skyblock private static final Set SKYBLOCK_IN_ALL_LANGUAGES = Sets.newHashSet("SKYBLOCK","\u7A7A\u5C9B\u751F\u5B58"); @@ -100,7 +110,7 @@ public class NotEnoughUpdates { SimpleCommand collectionLogCommand = new SimpleCommand("neucl", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if(!OpenGlHelper.isFramebufferEnabled()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This feature requires FBOs to work. Try disabling Optifine's 'Fast Render'.")); } else { if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { @@ -112,6 +122,19 @@ public class NotEnoughUpdates { } }); + + SimpleCommand questingCommand = new SimpleCommand("neuquest", new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + openGui = new GuiQuestLine(); + } + }); + + SimpleCommand overlayPlacementsCommand = new SimpleCommand("neuoverlay", new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + openGui = new NEUOverlayPlacements(); + } + }); + SimpleCommand cosmeticsCommand = new SimpleCommand("neucosmetics", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { @@ -126,7 +149,7 @@ public class NotEnoughUpdates { if(!hasSkyblockScoreboard()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ "You must be on Skyblock to use this feature.")); - } else if(manager.config.apiKey.value == null || manager.config.apiKey.value.isEmpty()) { + } else if(manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ "Can't open NeuAH, Api Key is not set. Run /api new and put the result in settings.")); } else { @@ -152,6 +175,8 @@ public class NotEnoughUpdates { f.mkdirs(); ClientCommandHandler.instance.registerCommand(collectionLogCommand); ClientCommandHandler.instance.registerCommand(cosmeticsCommand); + ClientCommandHandler.instance.registerCommand(overlayPlacementsCommand); + //ClientCommandHandler.instance.registerCommand(questingCommand); ClientCommandHandler.instance.registerCommand(neuAhCommand); neuio = new NEUIO(getAccessToken()); @@ -178,7 +203,7 @@ public class NotEnoughUpdates { })); //TODO: login code. Ignore this, used for testing. - try { + /*try { Field field = Minecraft.class.getDeclaredField("session"); YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()) @@ -207,7 +232,7 @@ public class NotEnoughUpdates { field.setAccessible(true); field.set(Minecraft.getMinecraft(), session); } catch (NoSuchFieldException | AuthenticationException | IllegalAccessException e) { - } + }*/ } /** @@ -239,17 +264,93 @@ public class NotEnoughUpdates { } if(hasSkyblockScoreboard()) { manager.auctionManager.tick(); + if(!joinedSB && manager.config.showUpdateMsg.value) { + File repo = manager.repoLocation; + if(repo.exists()) { + File updateJson = new File(repo, "update.json"); + try { + JsonObject o = manager.getJsonFromFile(updateJson); + + String version = o.get("version").getAsString(); + + if(!VERSION.equalsIgnoreCase(version)) { + String update_msg = o.get("update_msg").getAsString(); + String discord_link = o.get("discord_link").getAsString(); + String youtube_link = o.get("youtube_link").getAsString(); + String update_link = o.get("update_link").getAsString(); + String github_link = o.get("github_link").getAsString(); + String other_text = o.get("other_text").getAsString(); + String other_link = o.get("other_link").getAsString(); + + int first_len = -1; + for(String line : update_msg.split("\n")) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int len = fr.getStringWidth(line); + if(first_len == -1) { + first_len = len; + } + int missing_len = first_len-len; + if(missing_len > 0) { + StringBuilder sb = new StringBuilder(line); + for(int i=0; i 0) { + other = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.BLUE+other_text+EnumChatFormatting.GRAY+"]"); + other.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, other_link)); + } + ChatComponentText links = new ChatComponentText(""); + ChatComponentText separator = new ChatComponentText( + EnumChatFormatting.GRAY+EnumChatFormatting.BOLD.toString()+EnumChatFormatting.STRIKETHROUGH+(other==null?"---":"--")); + ChatComponentText discord = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.BLUE+"Discord"+EnumChatFormatting.GRAY+"]"); + discord.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, discord_link)); + ChatComponentText youtube = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.RED+"YouTube"+EnumChatFormatting.GRAY+"]"); + youtube.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, youtube_link)); + ChatComponentText release = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.GREEN+"Release"+EnumChatFormatting.GRAY+"]"); + release.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, update_link)); + ChatComponentText github = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.DARK_PURPLE+"GitHub"+EnumChatFormatting.GRAY+"]"); + github.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, github_link)); + + + links.appendSibling(separator); + links.appendSibling(discord); + links.appendSibling(separator); + links.appendSibling(youtube); + links.appendSibling(separator); + links.appendSibling(release); + links.appendSibling(separator); + links.appendSibling(github); + links.appendSibling(separator); + if(other != null) { + links.appendSibling(other); + links.appendSibling(separator); + } + + Minecraft.getMinecraft().thePlayer.addChatMessage(links); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + + } + + joinedSB = true; + } catch(Exception ignored) {} + } + } + //NEUQuesting.getInstance().tick(); + //GuiQuestLine.questLine.tick(); } if(currChatMessage != null && System.currentTimeMillis() - lastChatMessage > CHAT_MSG_COOLDOWN) { lastChatMessage = System.currentTimeMillis(); Minecraft.getMinecraft().thePlayer.sendChatMessage(currChatMessage); currChatMessage = null; } - if(hasSkyblockScoreboard() && manager.currentProfile != null && manager.currentProfile.length() > 0) { + if(hasSkyblockScoreboard() && manager.getCurrentProfile() != null && manager.getCurrentProfile().length() > 0) { HashSet newItem = new HashSet<>(); - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - processUniqueStack(stack, newItem); - } if(Minecraft.getMinecraft().currentScreen instanceof GuiContainer && !(Minecraft.getMinecraft().currentScreen instanceof GuiCrafting)) { boolean usableContainer = true; @@ -281,6 +382,14 @@ public class NotEnoughUpdates { for(ItemStack stack : Minecraft.getMinecraft().thePlayer.openContainer.getInventory()) { processUniqueStack(stack, newItem); } + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + processUniqueStack(stack, newItem); + } + } + } else { + + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + processUniqueStack(stack, newItem); } } newItemAddMap.keySet().retainAll(newItem); @@ -292,7 +401,7 @@ public class NotEnoughUpdates { String internalname = manager.getInternalNameForItem(stack); if(internalname != null) { ArrayList log = manager.config.collectionLog.value.computeIfAbsent( - manager.currentProfile, k -> new ArrayList<>()); + manager.getCurrentProfile(), k -> new ArrayList<>()); if(!log.contains(internalname)) { newItem.add(internalname); if(newItemAddMap.containsKey(internalname)) { @@ -464,11 +573,14 @@ public class NotEnoughUpdates { @SubscribeEvent(priority = EventPriority.LOW) public void onGuiChat(ClientChatReceivedEvent e) { String r = null; - String unformatted = e.message.getUnformattedText().replaceAll("(?i)\\u00A7.", ""); + String unformatted = Utils.cleanColour(e.message.getUnformattedText()); if(unformatted.startsWith("You are playing on profile: ")) { - manager.currentProfile = unformatted.substring("You are playing on profile: ".length()).split(" ")[0].trim(); + manager.setCurrentProfile(unformatted.substring("You are playing on profile: ".length()).split(" ")[0].trim()); } else if(unformatted.startsWith("Your profile was changed to: ")) {//Your profile was changed to: - manager.currentProfile = unformatted.substring("Your profile was changed to: ".length()).split(" ")[0].trim(); + manager.setCurrentProfile(unformatted.substring("Your profile was changed to: ".length()).split(" ")[0].trim()); + } else if(unformatted.startsWith("Your new API key is ")) { + manager.config.apiKey.value = unformatted.substring("Your new API key is ".length()); + try { manager.saveConfig(); } catch(IOException ioe) {} } if(e.message.getFormattedText().equals(EnumChatFormatting.RESET.toString()+ EnumChatFormatting.RED+"You haven't unlocked this recipe!"+EnumChatFormatting.RESET)) { @@ -574,6 +686,9 @@ public class NotEnoughUpdates { public void onGuiScreenDrawPost(GuiScreenEvent.DrawScreenEvent.Post event) { if(!(event.gui instanceof CustomAHGui || manager.auctionManager.customAH.isRenderOverAuctionView())) { if(event.gui instanceof GuiContainer && isOnSkyblock()) { + + renderDungeonChestOverlay(event.gui); + if(!focusInv) { GL11.glTranslatef(0, 0, 300); overlay.render(event.mouseX, event.mouseY, hoverInv && focusInv); @@ -584,6 +699,86 @@ public class NotEnoughUpdates { } } + private void renderDungeonChestOverlay(GuiScreen gui) { + if(gui instanceof GuiChest && manager.auctionManager.activeAuctions > 0) { + try { + int xSize = (int) Utils.getField(GuiContainer.class, gui, "xSize", "field_146999_f"); + int ySize = (int) Utils.getField(GuiContainer.class, gui, "ySize", "field_147000_g"); + int guiLeft = (int) Utils.getField(GuiContainer.class, gui, "guiLeft", "field_147003_i"); + int guiTop = (int) Utils.getField(GuiContainer.class, gui, "guiTop", "field_147009_r"); + + GuiChest eventGui = (GuiChest) gui; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + IInventory lower = cc.getLowerChestInventory(); + + ItemStack rewardChest = lower.getStackInSlot(31); + if (rewardChest != null && rewardChest.getDisplayName().endsWith(EnumChatFormatting.GREEN+"Open Reward Chest")) { + int chestCost = 0; + String line6 = Utils.cleanColour(manager.getLoreFromNBT(rewardChest.getTagCompound())[6]); + StringBuilder cost = new StringBuilder(); + for(int i=0; i= 0) { + cost.append(c); + } + } + if(cost.length() > 0) { + chestCost = Integer.parseInt(cost.toString()); + } + + boolean missing = false; + int totalValue = 0; + for(int i=0; i<5; i++) { + ItemStack item = lower.getStackInSlot(11+i); + String internal = manager.getInternalNameForItem(item); + if(internal != null) { + int worth = manager.auctionManager.getLowestBin(internal); + if(worth > 0) { + totalValue += worth; + } else { + missing = true; + break; + } + } + } + int profitLoss = totalValue - chestCost; + + NumberFormat format = NumberFormat.getInstance(Locale.US); + String valueString; + if(!missing) { + valueString = EnumChatFormatting.BLUE+"Chest value: " + EnumChatFormatting.GOLD + + EnumChatFormatting.BOLD + format.format(totalValue) + " coins"; + } else { + valueString = EnumChatFormatting.BLUE+"Couldn't find item on AH. Item is very rare!"; + } + String plString; + if(missing) { + plString = ""; + } else if(profitLoss >= 0) { + plString = EnumChatFormatting.BLUE+"Profit/loss: " + EnumChatFormatting.DARK_GREEN + + EnumChatFormatting.BOLD + "+" + format.format(profitLoss) + " coins"; + } else { + plString = EnumChatFormatting.BLUE+"Profit/loss: " + EnumChatFormatting.RED + + EnumChatFormatting.BOLD + "-" + format.format(-profitLoss) + " coins"; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(dungeon_chest_worth); + GL11.glColor4f(1, 1, 1, 1); + GlStateManager.disableLighting(); + Utils.drawTexturedRect(guiLeft+xSize+4, guiTop, 180, 45, 0, 180/256f, 0, 45/256f, GL11.GL_NEAREST); + + Utils.drawStringCenteredScaledMaxWidth(valueString, Minecraft.getMinecraft().fontRendererObj, guiLeft+xSize+4+90, + guiTop+14, true, 170, Color.BLACK.getRGB()); + Utils.drawStringCenteredScaledMaxWidth(plString, Minecraft.getMinecraft().fontRendererObj, guiLeft+xSize+4+90, + guiTop+28, true, 170, Color.BLACK.getRGB()); + + } + } catch(Exception e) { + e.printStackTrace(); + } + } + } + /** * Sends a mouse event to NEUOverlay if the inventory isn't hovered AND focused. * Will also cancel the event if if NEUOverlay#mouseInput returns true. @@ -757,7 +952,7 @@ public class NotEnoughUpdates { } } //AH prices - if(Minecraft.getMinecraft().currentScreen != null) { + /*if(Minecraft.getMinecraft().currentScreen != null) { if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; ContainerChest container = (ContainerChest) chest.inventorySlots; @@ -804,7 +999,7 @@ public class NotEnoughUpdates { } } } - } + }*/ if(!Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || !manager.config.dev.value) return; if(event.toolTip.size()>0&&event.toolTip.get(event.toolTip.size()-1).startsWith(EnumChatFormatting.DARK_GRAY + "NBT: ")) { event.toolTip.remove(event.toolTip.size()-1); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java b/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java index 3ad2eba6..051313d1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java @@ -1,5 +1,7 @@ package io.github.moulberry.notenoughupdates; +import io.github.moulberry.notenoughupdates.util.Utils; + import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -26,7 +28,7 @@ public class StreamerMode { } public static String filterScoreboard(String line) { - line = filterLobbyNames(cleanDuplicateColourCodes(line)); + line = filterLobbyNames(Utils.cleanDuplicateColourCodes(line)); return line; } @@ -35,29 +37,4 @@ public class StreamerMode { return line; } - private static String cleanDuplicateColourCodes(String line) { - StringBuilder sb = new StringBuilder(); - char currentColourCode = 'r'; - boolean sectionSymbolLast = false; - for(char c : line.toCharArray()) { - if((int)c > 50000) continue; - - if(c == '\u00a7') { - sectionSymbolLast = true; - } else { - if(sectionSymbolLast) { - if(currentColourCode != c) { - sb.append('\u00a7'); - sb.append(c); - currentColourCode = c; - } - sectionSymbolLast = false; - } else { - sb.append(c); - } - } - } - return sb.toString(); - } - } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java new file mode 100644 index 00000000..20ac86ba --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -0,0 +1,598 @@ +package io.github.moulberry.notenoughupdates.auction; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.event.ClickEvent; +import net.minecraft.event.HoverEvent; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.*; + +public class APIManager { + + private NEUManager manager; + public final CustomAH customAH; + + private int totalPages = 0; + private int lastApiUpdate; + private LinkedList needUpdate = new LinkedList<>(); + + private TreeMap auctionMap = new TreeMap<>(); + public HashMap> internalnameToAucIdMap = new HashMap<>(); + private HashSet playerBids = new HashSet<>(); + private HashSet playerBidsNotified = new HashSet<>(); + private HashSet playerBidsFinishedNotified = new HashSet<>(); + + private HashMap> internalnameToLowestBIN = new HashMap<>(); + + private JsonArray playerInformation = null; + + public TreeMap>> extrasToAucIdMap = new TreeMap<>(); + + private long lastPageUpdate = 0; + private long lastProfileUpdate = 0; + private long lastCustomAHSearch = 0; + private long lastCleanup = 0; + + public int activeAuctions = 0; + public int uniqueItems = 0; + public int totalTags = 0; + public int internalnameTaggedAuctions = 0; + public int taggedAuctions = 0; + public int processMillis = 0; + + private boolean doFullUpdate = false; + + public APIManager(NEUManager manager) { + this.manager = manager; + customAH = new CustomAH(manager); + } + + public JsonObject getPlayerInformation() { + if(playerInformation == null) return null; + for(int i=0; i getAuctionItems() { + return auctionMap; + } + + public HashSet getPlayerBids() { + return playerBids; + } + + public HashSet getAuctionsForInternalname(String internalname) { + return internalnameToAucIdMap.computeIfAbsent(internalname, k -> new HashSet<>()); + } + + public class Auction { + public String auctioneerUuid; + public long end; + public int starting_bid; + public int highest_bid_amount; + public int bid_count; + public boolean bin; + public String category; + public String rarity; + public NBTTagCompound item_tag; + private ItemStack stack; + + public long lastUpdate = 0; + + public int enchLevel = 0; //0 = clean, 1 = ench, 2 = ench/hpb + + public Auction(String auctioneerUuid, long end, int starting_bid, int highest_bid_amount, int bid_count, + boolean bin, String category, String rarity, NBTTagCompound item_tag) { + this.auctioneerUuid = auctioneerUuid; + this.end = end; + this.starting_bid = starting_bid; + this.highest_bid_amount = highest_bid_amount; + this.bid_count = bid_count; + this.bin = bin; + this.category = category; + this.rarity = rarity; + this.item_tag = item_tag; + } + + public ItemStack getStack() { + if(stack != null) { + return stack; + } else { + JsonObject item = manager.getJsonFromNBT(item_tag); + ItemStack stack = manager.jsonToStack(item, false); + this.stack = stack; + return stack; + } + } + } + + public void tick() { + customAH.tick(); + if(System.currentTimeMillis() - lastPageUpdate > 5*1000) { + lastPageUpdate = System.currentTimeMillis(); + updatePageTick(); + ahNotification(); + } + if(System.currentTimeMillis() - lastProfileUpdate > 10*1000) { + lastProfileUpdate = System.currentTimeMillis(); + updateProfiles(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); + } + if(System.currentTimeMillis() - lastCleanup > 120*1000) { + lastCleanup = System.currentTimeMillis(); + cleanup(); + } + if(System.currentTimeMillis() - lastCustomAHSearch > 60*1000) { + lastCustomAHSearch = System.currentTimeMillis(); + if(Minecraft.getMinecraft().currentScreen instanceof CustomAHGui || customAH.isRenderOverAuctionView()) { + customAH.updateSearch(); + calculateStats(); + } + } + } + + public void updateProfiles(String uuid) { + HashMap args = new HashMap<>(); + args.put("uuid", ""+uuid); + manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/profiles", + args, jsonObject -> { + if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + playerInformation = jsonObject.get("profiles").getAsJsonArray(); + if(playerInformation == null) return; + String backup = null; + long backupLastSave = 0; + for(int i=0; i backupLastSave) { + backupLastSave = last_save; + backup = cute_name; + } + } + } + + manager.setCurrentProfileBackup(backup); + } + } + ); + } + + private String niceAucId(String aucId) { + if(aucId.length()!=32) return aucId; + + StringBuilder niceAucId = new StringBuilder(); + niceAucId.append(aucId, 0, 8); + niceAucId.append("-"); + niceAucId.append(aucId, 8, 12); + niceAucId.append("-"); + niceAucId.append(aucId, 12, 16); + niceAucId.append("-"); + niceAucId.append(aucId, 16, 20); + niceAucId.append("-"); + niceAucId.append(aucId, 20, 32); + return niceAucId.toString(); + } + + public int getLowestBin(String internalname) { + TreeMap lowestBIN = internalnameToLowestBIN.get(internalname); + if(lowestBIN == null || lowestBIN.isEmpty()) return -1; + return lowestBIN.firstKey(); + } + + private void ahNotification() { + playerBidsNotified.retainAll(playerBids); + playerBidsFinishedNotified.retainAll(playerBids); + if(manager.config.ahNotification.value <= 0) { + return; + } + for(String aucid : playerBids) { + Auction auc = auctionMap.get(aucid); + if(!playerBidsNotified.contains(aucid)) { + if(auc != null && auc.end - System.currentTimeMillis() < 1000*60*manager.config.ahNotification.value) { + ChatComponentText message = new ChatComponentText( + EnumChatFormatting.YELLOW+"The " + auc.getStack().getDisplayName() + EnumChatFormatting.YELLOW + " you have bid on is ending soon! Click here to view."); + ChatStyle clickEvent = new ChatStyle().setChatClickEvent( + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/viewauction " + niceAucId(aucid))); + clickEvent.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.YELLOW+"View auction"))); + message.setChatStyle(clickEvent); + Minecraft.getMinecraft().thePlayer.addChatMessage(message); + + playerBidsNotified.add(aucid); + } + } + if(!playerBidsFinishedNotified.contains(aucid)) { + if(auc != null && auc.end < System.currentTimeMillis()) { + ChatComponentText message = new ChatComponentText( + EnumChatFormatting.YELLOW+"The " + auc.getStack().getDisplayName() + EnumChatFormatting.YELLOW + " you have bid on (might) have ended! Click here to view."); + ChatStyle clickEvent = new ChatStyle().setChatClickEvent( + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/viewauction " + niceAucId(aucid))); + clickEvent.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.YELLOW+"View auction"))); + message.setChatStyle(clickEvent); + Minecraft.getMinecraft().thePlayer.addChatMessage(message); + + playerBidsFinishedNotified.add(aucid); + } + } + } + } + + private void cleanup() { + try { + long currTime = System.currentTimeMillis(); + Set toRemove = new HashSet<>(); + for(Map.Entry entry : auctionMap.entrySet()) { + long timeToEnd = entry.getValue().end - currTime; + if(timeToEnd < -60) { + toRemove.add(entry.getKey()); + } else if(currTime - entry.getValue().lastUpdate > 5*60*1000) { + toRemove.add(entry.getKey()); + } + } + toRemove.removeAll(playerBids); + for(String aucid : toRemove) { + auctionMap.remove(aucid); + } + for(HashMap> extrasMap : extrasToAucIdMap.values()) { + for(HashSet aucids : extrasMap.values()) { + for(String aucid : toRemove) { + aucids.remove(aucid); + } + } + } + for(HashSet aucids : internalnameToAucIdMap.values()) { + aucids.removeAll(toRemove); + } + for(TreeMap lowestBINs : internalnameToLowestBIN.values()) { + lowestBINs.values().removeAll(toRemove); + } + } catch(ConcurrentModificationException e) { + cleanup(); + } + } + + private void updatePageTick() { + if(totalPages == 0) { + getPageFromAPI(0); + } else if(doFullUpdate) { + doFullUpdate = false; + for(int i=0; i= totalPages && !needUpdate.isEmpty()) { + pageToUpdate = needUpdate.pop(); + } + + getPageFromAPI(pageToUpdate); + } + } + + public void calculateStats() { + try { + uniqueItems = internalnameToAucIdMap.size(); + Set aucs = new HashSet<>(); + for(HashSet aucids : internalnameToAucIdMap.values()) { + aucs.addAll(aucids); + } + internalnameTaggedAuctions = aucs.size(); + totalTags = extrasToAucIdMap.size(); + aucs = new HashSet<>(); + for(HashMap> extrasMap : extrasToAucIdMap.values()) { + for(HashSet aucids : extrasMap.values()) { + aucs.addAll(aucids); + } + } + taggedAuctions = aucs.size(); + } catch(Exception e) {} + } + + String[] rarityArr = new String[] { + "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", + }; + + public int checkItemType(String lore, boolean contains, String... typeMatches) { + String[] split = lore.split("\n"); + for(int i=split.length-1; i>=0; i--) { + String line = split[i]; + for(String rarity : rarityArr) { + for(int j=0; j args = new HashMap<>(); + args.put("page", ""+page); + manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", + args, jsonObject -> { + if (jsonObject.get("success").getAsBoolean()) { + totalPages = jsonObject.get("totalPages").getAsInt(); + activeAuctions = jsonObject.get("totalAuctions").getAsInt(); + + int lastUpdated = jsonObject.get("lastUpdated").getAsInt(); + + if(lastApiUpdate != lastUpdated) { + if(manager.config.quickAHUpdate.value && + (Minecraft.getMinecraft().currentScreen instanceof CustomAHGui || customAH.isRenderOverAuctionView())) { + doFullUpdate = true; + } + resetNeedUpdate(); + } + + lastApiUpdate = lastUpdated; + + String[] lvl4Maxes = {"Experience", "Life Steal", "Scavenger", "Looting"}; + + String[] categoryItemType = new String[]{"sword","fishingrod","pickaxe","axe", + "shovel","petitem","travelscroll","reforgestone","bow"}; + String playerUUID = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replaceAll("-",""); + + long startProcess = System.currentTimeMillis(); + JsonArray auctions = jsonObject.get("auctions").getAsJsonArray(); + for (int i = 0; i < auctions.size(); i++) { + JsonObject auction = auctions.get(i).getAsJsonObject(); + + String auctionUuid = auction.get("uuid").getAsString(); + String auctioneerUuid = auction.get("auctioneer").getAsString(); + long end = auction.get("end").getAsLong(); + int starting_bid = auction.get("starting_bid").getAsInt(); + int highest_bid_amount = auction.get("highest_bid_amount").getAsInt(); + int bid_count = auction.get("bids").getAsJsonArray().size(); + boolean bin = false; + if(auction.has("bin")) { + bin = auction.get("bin").getAsBoolean(); + } + String sbCategory = auction.get("category").getAsString(); + String extras = auction.get("extra").getAsString(); + String item_name = auction.get("item_name").getAsString(); + String item_lore = Utils.fixBrokenAPIColour(auction.get("item_lore").getAsString()); + String item_bytes = auction.get("item_bytes").getAsString(); + String rarity = auction.get("tier").getAsString(); + JsonArray bids = auction.get("bids").getAsJsonArray(); + + for(String lvl4Max : lvl4Maxes) { + item_lore = item_lore.replaceAll("\\u00A79("+lvl4Max+" IV)", EnumChatFormatting.DARK_PURPLE+"$1"); + } + item_lore = item_lore.replaceAll("\\u00A79([A-Za-z ]+ VI)", EnumChatFormatting.DARK_PURPLE+"$1"); + item_lore = item_lore.replaceAll("\\u00A79([A-Za-z ]+ VII)", EnumChatFormatting.RED+"$1"); + + try { + NBTTagCompound item_tag; + try { + item_tag = CompressedStreamTools.readCompressed( + new ByteArrayInputStream(Base64.getDecoder().decode(item_bytes))); + } catch(IOException e) { continue; } + + NBTTagCompound tag = item_tag.getTagList("i", 10).getCompoundTagAt(0).getCompoundTag("tag"); + String internalname = manager.getInternalnameFromNBT(tag); + String displayNormal = ""; + if(manager.getItemInformation().containsKey(internalname)) { + displayNormal = Utils.cleanColour(manager.getItemInformation().get(internalname).get("displayname").getAsString()); + } + + String[] lore = new String[0]; + NBTTagCompound display = tag.getCompoundTag("display"); + if(display.hasKey("Lore", 9)) { + NBTTagList loreList = new NBTTagList(); + for(String line : item_lore.split("\n")) { + loreList.appendTag(new NBTTagString(line)); + } + display.setTag("Lore", loreList); + } + tag.setTag("display", display); + item_tag.getTagList("i", 10).getCompoundTagAt(0).setTag("tag", tag); + + int index=0; + for(String str : extras.split(" ")) { + str = Utils.cleanColour(str).toLowerCase(); + if(str.length() > 0) { + HashMap> extrasMap = extrasToAucIdMap.computeIfAbsent(str, k -> new HashMap<>()); + HashSet aucids = extrasMap.computeIfAbsent(index, k -> new HashSet<>()); + aucids.add(auctionUuid); + } + index++; + } + + if(bin) { + TreeMap lowestBINs = internalnameToLowestBIN.computeIfAbsent(internalname, k -> new TreeMap<>()); + int count = item_tag.getInteger("Count"); + lowestBINs.put(starting_bid/(count>0?count:1), auctionUuid); + if(lowestBINs.size() > 5) { + lowestBINs.keySet().remove(lowestBINs.lastKey()); + } + } + + for(int j=0; j= 0) { + HashMap> extrasMap = extrasToAucIdMap.computeIfAbsent("dungeon", k -> new HashMap<>()); + HashSet aucids = extrasMap.computeIfAbsent(0, k -> new HashSet<>()); + aucids.add(auctionUuid); + } + + //Categories + String category = sbCategory; + int itemType = checkItemType(item_lore, false,"SWORD", "FISHING ROD", "PICKAXE", + "AXE", "SHOVEL", "PET ITEM", "TRAVEL SCROLL", "REFORGE STONE", "BOW"); + if(itemType >= 0 && itemType < categoryItemType.length) { + category = categoryItemType[itemType]; + } + if(extras.startsWith("Enchanted Book")) category = "ebook"; + if(extras.endsWith("Potion")) category = "potion"; + if(extras.contains("Rune")) category = "rune"; + if(item_lore.split("\n")[0].endsWith("Furniture")) category = "furniture"; + if(item_lore.split("\n")[0].endsWith("Pet") || + item_lore.split("\n")[0].endsWith("Mount")) category = "pet"; + + Auction auction1 = new Auction(auctioneerUuid, end, starting_bid, highest_bid_amount, + bid_count, bin, category, rarity, item_tag); + + if(tag.hasKey("ench")) { + auction1.enchLevel = 1; + if(tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + int hotpotatocount = ea.getInteger("hot_potato_count"); + if(hotpotatocount == 10) { + auction1.enchLevel = 2; + } + } + } + + auction1.lastUpdate = System.currentTimeMillis(); + + auctionMap.put(auctionUuid, auction1); + internalnameToAucIdMap.computeIfAbsent(internalname, k -> new HashSet<>()).add(auctionUuid); + } catch(Exception e) {e.printStackTrace();} + } + processMillis = (int)(System.currentTimeMillis() - startProcess); + } + } + ); + } + + private void resetNeedUpdate() { + for(Integer page=0; page pages = new HashMap<>(); + + HashMap args = new HashMap<>(); + args.put("page", "0"); + AtomicInteger totalPages = new AtomicInteger(1); + AtomicInteger currentPages = new AtomicInteger(0); + manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", + args, jsonObject -> { + if (jsonObject.get("success").getAsBoolean()) { + pages.put(0, jsonObject); + totalPages.set(jsonObject.get("totalPages").getAsInt()); + currentPages.incrementAndGet(); + + for (int i = 1; i < totalPages.get(); i++) { + int j = i; + HashMap args2 = new HashMap<>(); + args2.put("page", "" + i); + manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", + args2, jsonObject2 -> { + if (jsonObject2.get("success").getAsBoolean()) { + pages.put(j, jsonObject2); + currentPages.incrementAndGet(); + } else { + currentPages.incrementAndGet(); + } + } + ); + } + } + } + ); + + long startTime = System.currentTimeMillis(); + + int currentAuctionUpdateId = auctionUpdateId.incrementAndGet(); + + auctionUpdateSES.schedule(new Runnable() { + public void run() { + if(auctionUpdateId.get() != currentAuctionUpdateId) return; + System.out.println(currentPages.get() + "/" + totalPages.get()); + if (System.currentTimeMillis() - startTime > 20000) return; + + if (currentPages.get() == totalPages.get()) { + TreeMap auctionItemsTemp = new TreeMap<>(); + + for (int pageNum : pages.keySet()) { + System.out.println(pageNum + "/" + pages.size()); + JsonObject page = pages.get(pageNum); + JsonArray auctions = page.get("auctions").getAsJsonArray(); + for (int i = 0; i < auctions.size(); i++) { + JsonObject auction = auctions.get(i).getAsJsonObject(); + + String auctionUuid = auction.get("uuid").getAsString(); + String auctioneerUuid = auction.get("auctioneer").getAsString(); + long end = auction.get("end").getAsLong(); + int starting_bid = auction.get("starting_bid").getAsInt(); + int highest_bid_amount = auction.get("highest_bid_amount").getAsInt(); + int bid_count = auction.get("bids").getAsJsonArray().size(); + boolean bin = false; + if(auction.has("bin")) { + bin = auction.get("bin").getAsBoolean(); + } + String category = auction.get("category").getAsString(); + String extras = auction.get("item_lore").getAsString().replaceAll("\n"," ") + " " + + auction.get("extra").getAsString(); + String item_bytes = auction.get("item_bytes").getAsString(); + + auctionItemsTemp.put(auctionUuid, new Auction(auctioneerUuid, end, starting_bid, highest_bid_amount, + bid_count, bin, category, extras, item_bytes)); + } + } + auctionItems = auctionItemsTemp; + customAH.updateSearch(); + return; + } + + auctionUpdateSES.schedule(this, 1000L, TimeUnit.MILLISECONDS); + } + }, 3000L, TimeUnit.MILLISECONDS); + }*/ + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/AuctionManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/AuctionManager.java deleted file mode 100644 index 3f87f774..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/AuctionManager.java +++ /dev/null @@ -1,437 +0,0 @@ -package io.github.moulberry.notenoughupdates.auction; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.util.EnumChatFormatting; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public class AuctionManager { - - private NEUManager manager; - public final CustomAH customAH; - - private int totalPages = 0; - private int lastApiUpdate; - private LinkedList needUpdate = new LinkedList<>(); - - private TreeMap auctionMap = new TreeMap<>(); - public HashMap> internalnameToAucIdMap = new HashMap<>(); - private HashSet playerBids = new HashSet<>(); - - public TreeMap> extrasToAucIdMap = new TreeMap<>(); - - private long lastPageUpdate = 0; - private long lastCustomAHSearch = 0; - private long lastCleanup = 0; - - public int activeAuctions = 0; - public int uniqueItems = 0; - public int totalTags = 0; - public int internalnameTaggedAuctions = 0; - public int taggedAuctions = 0; - public int processMillis = 0; - - public AuctionManager(NEUManager manager) { - this.manager = manager; - customAH = new CustomAH(manager); - } - - public TreeMap getAuctionItems() { - return auctionMap; - } - - public HashSet getPlayerBids() { - return playerBids; - } - - public HashSet getAuctionsForInternalname(String internalname) { - return internalnameToAucIdMap.computeIfAbsent(internalname, k -> new HashSet<>()); - } - - public class Auction { - public String auctioneerUuid; - public long end; - public int starting_bid; - public int highest_bid_amount; - public int bid_count; - public boolean bin; - public String category; - public String rarity; - public NBTTagCompound item_tag; - private ItemStack stack; - - public long lastUpdate = 0; - - public int enchLevel = 0; //0 = clean, 1 = ench, 2 = ench/hpb - - public Auction(String auctioneerUuid, long end, int starting_bid, int highest_bid_amount, int bid_count, - boolean bin, String category, String rarity, NBTTagCompound item_tag) { - this.auctioneerUuid = auctioneerUuid; - this.end = end; - this.starting_bid = starting_bid; - this.highest_bid_amount = highest_bid_amount; - this.bid_count = bid_count; - this.bin = bin; - this.category = category; - this.rarity = rarity; - this.item_tag = item_tag; - } - - public ItemStack getStack() { - if(stack != null) { - return stack; - } else { - JsonObject item = manager.getJsonFromNBT(item_tag); - ItemStack stack = manager.jsonToStack(item, false); - this.stack = stack; - return stack; - } - } - } - - public void tick() { - customAH.tick(); - if(System.currentTimeMillis() - lastPageUpdate > 5*1000) { - lastPageUpdate = System.currentTimeMillis(); - updatePageTick(); - } - if(System.currentTimeMillis() - lastCleanup > 120*1000) { - lastCleanup = System.currentTimeMillis(); - cleanup(); - } - if(System.currentTimeMillis() - lastCustomAHSearch > 60*1000) { - lastCustomAHSearch = System.currentTimeMillis(); - if(Minecraft.getMinecraft().currentScreen instanceof CustomAHGui || customAH.isRenderOverAuctionView()) { - customAH.updateSearch(); - calculateStats(); - } - } - } - - private void cleanup() { - try { - long currTime = System.currentTimeMillis(); - Set toRemove = new HashSet<>(); - for(Map.Entry entry : auctionMap.entrySet()) { - long timeToEnd = entry.getValue().end - currTime; - if(timeToEnd < -60) { - toRemove.add(entry.getKey()); - } else if(currTime - entry.getValue().lastUpdate > 5*60*1000) { - toRemove.add(entry.getKey()); - } - } - toRemove.removeAll(playerBids); - for(String aucid : toRemove) { - auctionMap.remove(aucid); - } - for(HashSet aucids : extrasToAucIdMap.values()) { - for(String aucid : toRemove) { - aucids.remove(aucid); - } - } - for(HashSet aucids : internalnameToAucIdMap.values()) { - aucids.removeAll(toRemove); - } - playerBids.removeAll(toRemove); - } catch(ConcurrentModificationException e) { - cleanup(); - } - } - - private void updatePageTick() { - if(totalPages == 0) { - getPageFromAPI(0); - } else { - if(needUpdate.isEmpty()) resetNeedUpdate(); - - int pageToUpdate = needUpdate.pop(); - while (pageToUpdate >= totalPages && !needUpdate.isEmpty()) { - pageToUpdate = needUpdate.pop(); - } - - getPageFromAPI(pageToUpdate); - } - } - - public void calculateStats() { - try { - uniqueItems = internalnameToAucIdMap.size(); - Set aucs = new HashSet<>(); - for(HashSet aucids : internalnameToAucIdMap.values()) { - aucs.addAll(aucids); - } - internalnameTaggedAuctions = aucs.size(); - totalTags = extrasToAucIdMap.size(); - aucs = new HashSet<>(); - for(HashSet aucids : extrasToAucIdMap.values()) { - aucs.addAll(aucids); - } - taggedAuctions = aucs.size(); - } catch(Exception e) {} - } - - String[] rarityArr = new String[] { - "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", - }; - - public int checkItemType(String lore, String... typeMatches) { - String[] split = lore.split("\n"); - for(int i=split.length-1; i>=0; i--) { - String line = split[i]; - for(String rarity : rarityArr) { - for(int j=0; j args = new HashMap<>(); - args.put("page", ""+page); - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", - args, jsonObject -> { - if (jsonObject.get("success").getAsBoolean()) { - totalPages = jsonObject.get("totalPages").getAsInt(); - activeAuctions = jsonObject.get("totalAuctions").getAsInt(); - - int lastUpdated = jsonObject.get("lastUpdated").getAsInt(); - - if(lastApiUpdate != lastUpdated) { - resetNeedUpdate(); - } - - lastApiUpdate = lastUpdated; - - String[] lvl4Maxes = {"Experience", "Life Steal", "Scavenger", "Looting"}; - - String[] categoryItemType = new String[]{"sword","fishingrod","pickaxe","axe", - "shovel","petitem","travelscroll","reforgestone","bow"}; - String playerUUID = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replaceAll("-",""); - - long startProcess = System.currentTimeMillis(); - JsonArray auctions = jsonObject.get("auctions").getAsJsonArray(); - for (int i = 0; i < auctions.size(); i++) { - JsonObject auction = auctions.get(i).getAsJsonObject(); - - String auctionUuid = auction.get("uuid").getAsString(); - String auctioneerUuid = auction.get("auctioneer").getAsString(); - long end = auction.get("end").getAsLong(); - int starting_bid = auction.get("starting_bid").getAsInt(); - int highest_bid_amount = auction.get("highest_bid_amount").getAsInt(); - int bid_count = auction.get("bids").getAsJsonArray().size(); - boolean bin = false; - if(auction.has("bin")) { - bin = auction.get("bin").getAsBoolean(); - } - String sbCategory = auction.get("category").getAsString(); - String extras = auction.get("extra").getAsString(); - String item_name = auction.get("item_name").getAsString(); - String item_lore = Utils.fixBrokenAPIColour(auction.get("item_lore").getAsString()); - String item_bytes = auction.get("item_bytes").getAsString(); - String rarity = auction.get("tier").getAsString(); - JsonArray bids = auction.get("bids").getAsJsonArray(); - - - for(String lvl4Max : lvl4Maxes) { - item_lore = item_lore.replaceAll("\\u00A79("+lvl4Max+" IV)", EnumChatFormatting.DARK_PURPLE+"$1"); - } - item_lore = item_lore.replaceAll("\\u00A79([A-Za-z ]+ VI)", EnumChatFormatting.DARK_PURPLE+"$1"); - item_lore = item_lore.replaceAll("\\u00A79([A-Za-z ]+ VII)", EnumChatFormatting.RED+"$1"); - - try { - NBTTagCompound item_tag; - try { - item_tag = CompressedStreamTools.readCompressed( - new ByteArrayInputStream(Base64.getDecoder().decode(item_bytes))); - } catch(IOException e) { continue; } - - NBTTagCompound tag = item_tag.getTagList("i", 10).getCompoundTagAt(0).getCompoundTag("tag"); - String internalname = manager.getInternalnameFromNBT(tag); - String displayNormal = ""; - if(manager.getItemInformation().containsKey(internalname)) { - displayNormal = Utils.cleanColour(manager.getItemInformation().get(internalname).get("displayname").getAsString()); - } - - String[] lore = new String[0]; - NBTTagCompound display = tag.getCompoundTag("display"); - if(display.hasKey("Lore", 9)) { - NBTTagList loreList = new NBTTagList(); - for(String line : item_lore.split("\n")) { - loreList.appendTag(new NBTTagString(line)); - } - display.setTag("Lore", loreList); - } - tag.setTag("display", display); - item_tag.getTagList("i", 10).getCompoundTagAt(0).setTag("tag", tag); - - for(String str : extras.replaceAll(displayNormal, "").split(" ")) { - str = Utils.cleanColour(str).toLowerCase(); - if(str.length() > 0) { - HashSet aucids = extrasToAucIdMap.computeIfAbsent(str, k -> new HashSet<>()); - aucids.add(auctionUuid); - } - } - - for(int j=0; j= 0 && itemType < categoryItemType.length) { - category = categoryItemType[itemType]; - } - if(extras.startsWith("Enchanted Book")) category = "ebook"; - if(extras.endsWith("Potion")) category = "potion"; - if(extras.contains("Rune")) category = "rune"; - if(item_lore.split("\n")[0].endsWith("Furniture")) category = "furniture"; - if(item_lore.split("\n")[0].endsWith("Pet") || - item_lore.split("\n")[0].endsWith("Mount")) category = "pet"; - - Auction auction1 = new Auction(auctioneerUuid, end, starting_bid, highest_bid_amount, - bid_count, bin, category, rarity, item_tag); - - if(tag.hasKey("ench")) { - auction1.enchLevel = 1; - if(tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - int hotpotatocount = ea.getInteger("hot_potato_count"); - if(hotpotatocount == 10) { - auction1.enchLevel = 2; - } - } - } - - auction1.lastUpdate = System.currentTimeMillis(); - - auctionMap.put(auctionUuid, auction1); - internalnameToAucIdMap.computeIfAbsent(internalname, k -> new HashSet<>()).add(auctionUuid); - } catch(Exception e) {e.printStackTrace();} - } - processMillis = (int)(System.currentTimeMillis() - startProcess); - } - } - ); - } - - private void resetNeedUpdate() { - for(Integer page=0; page pages = new HashMap<>(); - - HashMap args = new HashMap<>(); - args.put("page", "0"); - AtomicInteger totalPages = new AtomicInteger(1); - AtomicInteger currentPages = new AtomicInteger(0); - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", - args, jsonObject -> { - if (jsonObject.get("success").getAsBoolean()) { - pages.put(0, jsonObject); - totalPages.set(jsonObject.get("totalPages").getAsInt()); - currentPages.incrementAndGet(); - - for (int i = 1; i < totalPages.get(); i++) { - int j = i; - HashMap args2 = new HashMap<>(); - args2.put("page", "" + i); - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", - args2, jsonObject2 -> { - if (jsonObject2.get("success").getAsBoolean()) { - pages.put(j, jsonObject2); - currentPages.incrementAndGet(); - } else { - currentPages.incrementAndGet(); - } - } - ); - } - } - } - ); - - long startTime = System.currentTimeMillis(); - - int currentAuctionUpdateId = auctionUpdateId.incrementAndGet(); - - auctionUpdateSES.schedule(new Runnable() { - public void run() { - if(auctionUpdateId.get() != currentAuctionUpdateId) return; - System.out.println(currentPages.get() + "/" + totalPages.get()); - if (System.currentTimeMillis() - startTime > 20000) return; - - if (currentPages.get() == totalPages.get()) { - TreeMap auctionItemsTemp = new TreeMap<>(); - - for (int pageNum : pages.keySet()) { - System.out.println(pageNum + "/" + pages.size()); - JsonObject page = pages.get(pageNum); - JsonArray auctions = page.get("auctions").getAsJsonArray(); - for (int i = 0; i < auctions.size(); i++) { - JsonObject auction = auctions.get(i).getAsJsonObject(); - - String auctionUuid = auction.get("uuid").getAsString(); - String auctioneerUuid = auction.get("auctioneer").getAsString(); - long end = auction.get("end").getAsLong(); - int starting_bid = auction.get("starting_bid").getAsInt(); - int highest_bid_amount = auction.get("highest_bid_amount").getAsInt(); - int bid_count = auction.get("bids").getAsJsonArray().size(); - boolean bin = false; - if(auction.has("bin")) { - bin = auction.get("bin").getAsBoolean(); - } - String category = auction.get("category").getAsString(); - String extras = auction.get("item_lore").getAsString().replaceAll("\n"," ") + " " + - auction.get("extra").getAsString(); - String item_bytes = auction.get("item_bytes").getAsString(); - - auctionItemsTemp.put(auctionUuid, new Auction(auctioneerUuid, end, starting_bid, highest_bid_amount, - bid_count, bin, category, extras, item_bytes)); - } - } - auctionItems = auctionItemsTemp; - customAH.updateSearch(); - return; - } - - auctionUpdateSES.schedule(this, 1000L, TimeUnit.MILLISECONDS); - } - }, 3000L, TimeUnit.MILLISECONDS); - }*/ - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java index dd02c887..17ce216e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java @@ -1,8 +1,6 @@ package io.github.moulberry.notenoughupdates.auction; import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.util.TexLoc; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -283,7 +281,7 @@ public class CustomAH extends Gui { } public List getTooltipForAucId(String aucId) { - AuctionManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucId); + APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucId); List tooltip = new ArrayList<>(); @@ -473,7 +471,7 @@ public class CustomAH extends Gui { long auctionViewEndsIn = prettyTimeToMillis(endsInStr); if(auctionViewEndsIn > 0) { if(System.currentTimeMillis() - currAucIdSetTimer > 1000) { - AuctionManager.Auction auc = manager.auctionManager.getAuctionItems().get(currentAucId); + APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(currentAucId); if(auc != null) { auc.end = auctionViewEndsIn + lastGuiScreenSwitch; } @@ -943,7 +941,7 @@ public class CustomAH extends Gui { return mainCategory.subcategories[clickedSubCategory]; } - private boolean doesAucMatch(AuctionManager.Auction auc) { + private boolean doesAucMatch(APIManager.Auction auc) { if(auc == null) return false; Category currentCategory = getCurrentCategory(); @@ -988,28 +986,48 @@ public class CustomAH extends Gui { Set itemMatches = manager.search(query); for(String internalname : itemMatches) { for(String aucid : manager.auctionManager.getAuctionsForInternalname(internalname)) { - AuctionManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); + APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); if(doesAucMatch(auc)) { - matches.add(aucid); + //matches.add(aucid); } else { dontMatch.add(aucid); } } } - if(!query.contains(" ")) { - for(HashSet aucids : manager.subMapWithKeysThatAreSuffixes(query, + HashMap> extrasMatches = new HashMap<>(); + HashMap> extrasMatchesCurrent = new HashMap<>(); + boolean first = true; + for(String subQuery : query.split(" ")) { + for(HashMap> extrasMap : manager.subMapWithKeysThatAreSuffixes(subQuery.toLowerCase(), manager.auctionManager.extrasToAucIdMap).values()) { - for(String aucid : aucids) { - AuctionManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); - if(!dontMatch.contains(aucid) && doesAucMatch(auc)) { - matches.add(aucid); - } else { - dontMatch.add(aucid); + for(int index : extrasMap.keySet()) { + for(String aucid : extrasMap.get(index)) { + APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); + if(!dontMatch.contains(aucid) && doesAucMatch(auc)) { + if(first) { + List indexList = extrasMatchesCurrent.computeIfAbsent(aucid, k -> new ArrayList<>()); + indexList.add(index); + } else { + List indexList = extrasMatches.computeIfAbsent(aucid, k -> new ArrayList<>()); + if(indexList.contains(index-1)) { + List indexListCurrent = extrasMatchesCurrent.computeIfAbsent(aucid, k -> new ArrayList<>()); + indexListCurrent.add(index); + } + } + } else { + dontMatch.add(aucid); + } } } + } + + extrasMatches = (HashMap>) extrasMatchesCurrent.clone(); + extrasMatchesCurrent.clear(); + first = false; } + matches.addAll(extrasMatches.keySet()); return matches; } @@ -1036,13 +1054,13 @@ public class CustomAH extends Gui { auctionIds.clear(); if(filterMyAuctions) { for(String aucid : manager.auctionManager.getPlayerBids()) { - AuctionManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); + APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); if(doesAucMatch(auc)) { auctionIds.add(aucid); } } } else if(searchField.getText().length() == 0) { - for(Map.Entry entry : manager.auctionManager.getAuctionItems().entrySet()) { + for(Map.Entry entry : manager.auctionManager.getAuctionItems().entrySet()) { if(doesAucMatch(entry.getValue())) { auctionIds.add(entry.getKey()); } @@ -1053,7 +1071,7 @@ public class CustomAH extends Gui { HashSet allMatch = new HashSet<>(); if(query.contains("!")) { //only used for inverted queries, so dont need to populate unless ! in query - for(Map.Entry entry : manager.auctionManager.getAuctionItems().entrySet()) { + for(Map.Entry entry : manager.auctionManager.getAuctionItems().entrySet()) { if(doesAucMatch(entry.getValue())) { allMatch.add(entry.getKey()); } else { @@ -1124,8 +1142,8 @@ public class CustomAH extends Gui { sortedAuctionIds.clear(); sortedAuctionIds.addAll(auctionIds); sortedAuctionIds.sort((o1, o2) -> { - AuctionManager.Auction auc1 = manager.auctionManager.getAuctionItems().get(o1); - AuctionManager.Auction auc2 = manager.auctionManager.getAuctionItems().get(o2); + APIManager.Auction auc1 = manager.auctionManager.getAuctionItems().get(o1); + APIManager.Auction auc2 = manager.auctionManager.getAuctionItems().get(o2); if(auc1 == null) return 1; if(auc2 == null) return -1; @@ -1311,8 +1329,10 @@ public class CustomAH extends Gui { break; case 8: if(rightClicked) { - StringSelection selection = new StringSelection(niceAucId(currentAucId)); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); + if(currentAucId != null) { + StringSelection selection = new StringSelection(niceAucId(currentAucId)); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); + } } else { manager.auctionManager.calculateStats(); } @@ -1424,7 +1444,7 @@ public class CustomAH extends Gui { aucid = sortedAuctionIds.get(id); } catch (IndexOutOfBoundsException e) { break out; } - AuctionManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); + APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucid); if(auc != null) { if(mouseX > itemX && mouseX < itemX+16) { if(mouseY > itemY && mouseY < itemY+16) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java index 9afbd17f..331ba8b1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java @@ -1,10 +1,13 @@ package io.github.moulberry.notenoughupdates.cosmetics; +import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -25,9 +28,13 @@ public class CapeManager { public void setCape(String player, String capename) { if(capename == null) { + NotEnoughUpdates.INSTANCE.manager.config.selectedCape.value = ""; capeMap.remove(player); return; } + if(player.equalsIgnoreCase(Minecraft.getMinecraft().thePlayer.getName())) { + NotEnoughUpdates.INSTANCE.manager.config.selectedCape.value = capename; + } if(capeMap.containsKey(player)) { Pair capePair = capeMap.get(player); capePair.setValue(capename); @@ -56,6 +63,14 @@ public class CapeManager { @SubscribeEvent public void onRenderPlayer(RenderPlayerEvent.Post e) { + if(e.partialRenderTick == 1.0F) return; //rendering in inventory + if(e.entityPlayer == Minecraft.getMinecraft().thePlayer) { + if(NotEnoughUpdates.INSTANCE.manager.config.selectedCape.value != null && + !NotEnoughUpdates.INSTANCE.manager.config.selectedCape.value.isEmpty()) { + setCape(Minecraft.getMinecraft().thePlayer.getName(), + NotEnoughUpdates.INSTANCE.manager.config.selectedCape.value); + } + } if(capeMap.containsKey(e.entityPlayer.getName())) { capeMap.get(e.entityPlayer.getName()).getLeft().onRenderPlayer(e); } @@ -87,15 +102,20 @@ public class CapeManager { return capes; } + private String[] contributors = new String[]{"thatgravyboat", "twasnt", "traxyrr", "some1sm", "meguminqt", "marethyu_77"}; + public boolean getPermissionForCape(String player, String capename) { if(capename == null) { return false; } else if(player.equalsIgnoreCase("Moulberry")) { return true; //Oh yeah gimme gimme - } else if(capename.equals("nullzee")) { - return player.equalsIgnoreCase("Nullzee"); - } else if(capename.equals("gravy")) { - return player.equalsIgnoreCase("ThatGravyBoat"); + } else { + switch(capename) { + case "nullzee": return player.equalsIgnoreCase("Nullzee"); + case "gravy": return player.equalsIgnoreCase("ThatGravyBoat"); + case "contrib": return ArrayUtils.contains(contributors, player.toLowerCase()); + case "fade": return true; + } } return false; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java index 8ca3a538..08d91057 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java @@ -244,7 +244,7 @@ public class NEUCape { shaderManager.loadShader(shaderName); loadShaderUniforms(shaderManager); - if(!Keyboard.isKeyDown(Keyboard.KEY_K)) renderCape(player, e.partialRenderTick); + renderCape(player, e.partialRenderTick); GL11.glTranslatef((float)viewerX, (float)viewerY, (float)viewerZ); @@ -569,7 +569,7 @@ public class NEUCape { newPosition.y = node.lastPosition.y + (node.position.y - node.lastPosition.y) * partialRenderTick; newPosition.z = node.lastPosition.z + (node.position.z - node.lastPosition.z) * partialRenderTick; - if(node.oldRenderPosition[node.oldRenderPosition.length-1] == null || Keyboard.isKeyDown(Keyboard.KEY_B)) { + if(node.oldRenderPosition[node.oldRenderPosition.length-1] == null) { node.renderPosition = newPosition; } else { Vector3f accum = new Vector3f(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java index 38edc0f9..5f9e6af1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java @@ -40,6 +40,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { private int previousX = 0; private int previousFilter = 0; + private long lastUpdate = 0; + private static final int FILTER_ALL = 0; private static final int FILTER_WEAPON = 1; private static final int FILTER_ARMOR = 2; @@ -58,6 +60,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { private Framebuffer itemFramebufferGrayscale = null; private Shader grayscaleShader = null; + private int updateCounter = 0; + public CollectionLogInfoPane(NEUOverlay overlay, NEUManager manager) { super(overlay, manager); refreshItems(); @@ -75,6 +79,7 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { items.clear(); for(String internalname : manager.getItemInformation().keySet()) { if(!manager.isVanillaItem(internalname) && !internalname.matches(mobRegex)) { + JsonObject item = manager.getItemInformation().get(internalname); JsonArray lore = manager.getItemInformation().get(internalname).get("lore").getAsJsonArray(); switch(filterMode) { case FILTER_WEAPON: @@ -87,19 +92,19 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { if(overlay.checkItemType(lore, "ACCESSORY") < 0) continue; break; case FILTER_PET: - if(!internalname.matches(petRegex)) continue; + if(!internalname.matches(petRegex) || !item.get("displayname").getAsString().contains("[")) continue; break; case FILTER_TOOL: if(overlay.checkItemType(lore, "AXE", "PICKAXE", "FISHING ROD", "SHOVEL", "HOE") < 0) continue; break; case FILTER_SLAYER_ZOMBIE: - if(!loreContains(lore, "\u00A7c\u2620 \u00A75Requires Zombie")) continue; + if(!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("ZOMBIE")) continue; break; case FILTER_SLAYER_WOLF: - if(!loreContains(lore, "\u00A7c\u2620 \u00A75Requires Wolf")) continue; + if(!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("WOLF")) continue; break; case FILTER_SLAYER_SPIDER: - if(!loreContains(lore, "\u00A7c\u2620 \u00A75Requires Spider")) continue; + if(!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("SPIDER")) continue; break; } items.add(internalname); @@ -113,8 +118,11 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { private Comparator getItemComparator() { return (o1, o2) -> { - float cost1 = manager.getCraftCost(o1).craftCost; - float cost2 = manager.getCraftCost(o2).craftCost; + float cost1 = manager.auctionManager.getLowestBin(o1); + float cost2 = manager.auctionManager.getLowestBin(o2); + + if(cost1 == -1) cost1 = manager.getCraftCost(o1).craftCost; + if(cost2 == -1) cost2 = manager.getCraftCost(o2).craftCost; if(cost1 < cost2) return 1; if(cost1 > cost2) return -1; @@ -160,8 +168,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { int own = 0; for(String item : items) { if(getAcquiredItems() != null && - getAcquiredItems().containsKey(manager.currentProfile) && - getAcquiredItems().get(manager.currentProfile).contains(item)) { + getAcquiredItems().containsKey(manager.getCurrentProfile()) && + getAcquiredItems().get(manager.getCurrentProfile()).contains(item)) { own++; } @@ -248,8 +256,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { public int getCurrentAcquiredCount() { if(getAcquiredItems() == null) return 0; - if(!getAcquiredItems().containsKey(manager.currentProfile)) return 0; - return getAcquiredItems().get(manager.currentProfile).size(); + if(!getAcquiredItems().containsKey(manager.getCurrentProfile())) return 0; + return getAcquiredItems().get(manager.getCurrentProfile()).size(); } private void renderCollectionLog(Color fg, int width, int height, int left, int right, int top, int bottom) { @@ -272,7 +280,9 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { scaledresolution.getScaleFactor()); if(!manager.config.cacheRenderedItempane.value || previousAcquiredCount != getCurrentAcquiredCount() || - previousScroll != scrollHeight.getValue() || previousX != left || previousFilter != filterMode) { + previousScroll != scrollHeight.getValue() || previousX != left || previousFilter != filterMode || + System.currentTimeMillis() - lastUpdate > 5000) { + lastUpdate = System.currentTimeMillis(); renderItemsToImage(itemFramebuffer, fg, left+5, right, top+1, bottom); renderItemBGToImage(itemBGFramebuffer, fg, left+5, right, top+1, bottom); } @@ -316,35 +326,37 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { iterateItemSlots(new ItemSlotConsumer() { @Override public void consume(int x, int y, int id) { - String internalname = items[id]; - if(id == 0) isTop.set(true); + if(id < items.length) { + String internalname = items[id]; + if(id == 0) isTop.set(true); - int leftI = x-1; - int rightI = x+17; - int topI = y-1; - int bottomI = y+17; + int leftI = x-1; + int rightI = x+17; + int topI = y-1; + int bottomI = y+17; - lowestY.set(Math.max(bottomI, lowestY.get())); + lowestY.set(Math.max(bottomI, lowestY.get())); - if(mouseX > leftI && mouseX < rightI) { - if(mouseY > topI && mouseY < bottomI) { - tooltipToDisplay.set(manager.getItemInformation().get(internalname)); + if(mouseX > leftI && mouseX < rightI) { + if(mouseY > topI && mouseY < bottomI) { + tooltipToDisplay.set(manager.getItemInformation().get(internalname)); + } } - } - if(getAcquiredItems() != null && - getAcquiredItems().containsKey(manager.currentProfile) && - getAcquiredItems().get(manager.currentProfile).contains(internalname)) { - return; - } + if(getAcquiredItems() != null && + getAcquiredItems().containsKey(manager.getCurrentProfile()) && + getAcquiredItems().get(manager.getCurrentProfile()).contains(internalname)) { + return; + } - topI = Math.max(topI, top); - bottomI = Math.min(bottomI, bottom); + topI = Math.max(topI, top); + bottomI = Math.min(bottomI, bottom); - Utils.drawTexturedRect(leftI, topI, rightI-leftI, bottomI-topI, - leftI/(float)width, rightI/(float)width, - (height-topI)/(float)height, (height-bottomI)/(float)height); + Utils.drawTexturedRect(leftI, topI, rightI-leftI, bottomI-topI, + leftI/(float)width, rightI/(float)width, + (height-topI)/(float)height, (height-bottomI)/(float)height); + } } }, left+5, right, top+1, bottom); @@ -410,24 +422,26 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { String[] items = getItemList(); iterateItemSlots(new ItemSlotConsumer() { public void consume(int x, int y, int id) { - String internalname = items[id]; + if(id < items.length) { + String internalname = items[id]; - Color color = fgCustomOpacity; - if(getAcquiredItems() != null && - getAcquiredItems().containsKey(manager.currentProfile) && - getAcquiredItems().get(manager.currentProfile).contains(internalname)) { - color = fgGold; - } + Color color = fgCustomOpacity; + if(getAcquiredItems() != null && + getAcquiredItems().containsKey(manager.getCurrentProfile()) && + getAcquiredItems().get(manager.getCurrentProfile()).contains(internalname)) { + color = fgGold; + } - Minecraft.getMinecraft().getTextureManager().bindTexture(item_mask); - if(manager.config.itemStyle.value) { - GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, - color.getBlue() / 255f, color.getAlpha() / 255f); - Utils.drawTexturedRect(x - 1, y - 1, overlay.ITEM_SIZE + 2, overlay.ITEM_SIZE + 2, GL11.GL_NEAREST); - } else { - drawRect(x-1, y-1, x+overlay.ITEM_SIZE+1, y+overlay.ITEM_SIZE+1, color.getRGB()); + Minecraft.getMinecraft().getTextureManager().bindTexture(item_mask); + if(manager.config.itemStyle.value) { + GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, + color.getBlue() / 255f, color.getAlpha() / 255f); + Utils.drawTexturedRect(x - 1, y - 1, overlay.ITEM_SIZE + 2, overlay.ITEM_SIZE + 2, GL11.GL_NEAREST); + } else { + drawRect(x-1, y-1, x+overlay.ITEM_SIZE+1, y+overlay.ITEM_SIZE+1, color.getRGB()); + } + GlStateManager.bindTexture(0); } - GlStateManager.bindTexture(0); } }, left, right, top, bottom); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CosmeticsInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CosmeticsInfoPane.java index e972e2c8..707968e3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CosmeticsInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CosmeticsInfoPane.java @@ -68,13 +68,9 @@ public class CosmeticsInfoPane extends InfoPane { public void mouseInput(int width, int height, int mouseX, int mouseY, boolean mouseDown) { if(mouseDown && selectedCape != null) { if(selectedCape.equals(CapeManager.getInstance().getCape(Minecraft.getMinecraft().thePlayer.getName()))) { - for(EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - CapeManager.getInstance().setCape(player.getName(), null); - } + CapeManager.getInstance().setCape(Minecraft.getMinecraft().thePlayer.getName(), null); } else { - for(EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - CapeManager.getInstance().setCape(player.getName(), selectedCape); - } + CapeManager.getInstance().setCape(Minecraft.getMinecraft().thePlayer.getName(), selectedCape); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java deleted file mode 100644 index 5cc7211e..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java +++ /dev/null @@ -1,341 +0,0 @@ -package io.github.moulberry.notenoughupdates.infopanes; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.NEUOverlay; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.ScaledResolution; -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 java.awt.*; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.*; -import java.util.List; - -public class QOLInfoPane extends ScrollableInfoPane { - - /** - * Not currently used in BETA-1.6 - */ - - private LinkedHashMap accessoryMap = new LinkedHashMap<>(); - private LinkedHashMap allTalismans = new LinkedHashMap<>(); - private List recommended = new ArrayList<>(); - private int maxAccessories = 39; //TODO: Get from API - - private Integer[] talismanRarityValue = new Integer[]{1, 2, 4, 7, 10}; - - public QOLInfoPane(NEUOverlay overlay, NEUManager manager) { - super(overlay, manager); - - Comparator rarityComparator = new Comparator() { - @Override - public int compare(JsonObject o1, JsonObject o2) { - int rarity1 = overlay.getRarity(o1.get("lore").getAsJsonArray()); - int rarity2 = overlay.getRarity(o2.get("lore").getAsJsonArray()); - - int rarityDiff = rarity2 - rarity1; - if(rarityDiff != 0) { - return rarityDiff; - } - - return o2.get("internalname").getAsString().compareTo(o1.get("internalname").getAsString()); - } - }; - - TreeSet all = new TreeSet<>(rarityComparator); - LinkedHashMap highestRarity = new LinkedHashMap<>(); - LinkedHashMap lowerRarity = new LinkedHashMap<>(); - - for(Map.Entry entry : manager.getItemInformation().entrySet()) { - if(overlay.checkItemType(entry.getValue().get("lore").getAsJsonArray(), "ACCESSORY") >= 0) { - all.add(entry.getValue()); - } - } - outer: - for(JsonObject o : all) { - String internalname = o.get("internalname").getAsString(); - String name = getTalismanName(internalname); - int power = getTalismanPower(internalname); - for(JsonObject o2 : all) { - if(o != o2) { - String internalname2 = o2.get("internalname").getAsString(); - String name2 = getTalismanName(internalname2); - if(name2.equals(name)) { - int power2 = getTalismanPower(internalname2); - if(power2 > power) { - lowerRarity.put(internalname, o); - continue outer; - } - } - } - } - highestRarity.put(internalname, o); - } - for(Map.Entry entry : highestRarity.entrySet()) { - allTalismans.put(entry.getKey(), entry.getValue()); - } - for(Map.Entry entry : lowerRarity.entrySet()) { - allTalismans.put(entry.getKey(), entry.getValue()); - } - - HashMap args = new HashMap<>(); - String uuid = Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString(); - args.put("uuid", uuid); - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/profiles", - args, jsonObject -> { - if(jsonObject.get("success").getAsBoolean()) { - JsonObject currProfile = null; - for(JsonElement e : jsonObject.get("profiles").getAsJsonArray()) { - JsonObject profile = e.getAsJsonObject(); - String profileId = profile.get("profile_id").getAsString(); - String cuteName = profile.get("cute_name").getAsString(); - - if(manager.currentProfile.equals(cuteName)) { - JsonObject members = profile.get("members").getAsJsonObject(); - JsonObject profile_member = members.get(uuid.replaceAll("-","")).getAsJsonObject(); - currProfile = profile_member; - } - } - if(currProfile.has("talisman_bag")) { - String b64 = currProfile.get("talisman_bag").getAsJsonObject().get("data").getAsString(); - try { - NBTTagCompound tag = CompressedStreamTools.readCompressed(new ByteArrayInputStream(Base64.getDecoder().decode(b64))); - NBTTagList list = tag.getTagList("i", 10); - for(int i=0; i= maxAccessories) { - lowestRarity = 999; - for(Map.Entry entry : accessoryMap.entrySet()) { - JsonObject json = manager.getJsonForItem(entry.getValue()); - int rarity = overlay.getRarity(json.get("lore").getAsJsonArray()); - if(rarity < lowestRarity) { - lowestRarity = rarity; - } - } - } - System.out.println("lowestrarity:"+lowestRarity); - - TreeMap valueMap = new TreeMap<>(); - outer: - for(Map.Entry entry : allTalismans.entrySet()) { - int rarity = overlay.getRarity(entry.getValue().get("lore").getAsJsonArray()); - System.out.println(entry.getKey() + ":" + rarity); - if(rarity > lowestRarity) { - System.out.println("found greater:"+entry.getKey()); - float rarityVal = (float)talismanRarityValue[rarity]; - System.out.println("rarity val:"+rarityVal); - float price = manager.getCraftCost(entry.getKey()).craftCost; - - System.out.println("cc:"+price); - if(price < 0) { - System.out.println("invalid price:"+entry.getKey()); - continue; - } - - String internalname = entry.getValue().get("internalname").getAsString(); - String name = getTalismanName(internalname); - int power = getTalismanPower(internalname); - for(Map.Entry entry2 : accessoryMap.entrySet()) { - try { - JsonObject json = manager.getJsonForItem(entry2.getValue()); - String internalname2 = json.get("internalname").getAsString(); - - if(internalname.equals(internalname2)) { - //continue outer; - } - - String name2 = getTalismanName(internalname2); - } catch(Exception e) { - e.printStackTrace(); - System.out.println(":( -> " + entry2.getKey()); - } - - - /*if(name2.equals(name)) { - int power2 = getTalismanPower(internalname2); - if(power2 > power) { - continue outer; - } - }*/ - } - - valueMap.put(-rarityVal/price, entry.getValue()); - } - } - System.out.println("valuemap size:"+valueMap.size()); - int i=0; - for(Map.Entry entry : valueMap.entrySet()) { - recommended.add(entry.getValue()); - if(++i >= 500) { - break; - } - } - System.out.println("recommended size:"+recommended.size()); - } - //jsonObject.get("profiles") - } - }); - } - - - String[] talismanPowers = new String[]{"RING","ARTIFACT"}; - public int getTalismanPower(String internalname) { - for(int i=0; i entry : accessoryMap.entrySet()) { - if(mouseX > x && mouseX < x+16) { - if(mouseY > y && mouseY < y+16) { - display = entry.getValue(); - } - } - - drawRect(x, y, x+16, y+16, fg.getRGB()); - Utils.drawItemStack(entry.getValue(), x, y); - x += 20; - if(x + 20 + (leftSide+overlay.getBoxPadding()+5) > paneWidth) { - x=leftSide+overlay.getBoxPadding()+5; - y+=20; - } - } - - y+=20; - - y += renderParagraph(width, height, y, "Missing Accessories"); - - y+=10; - - x=leftSide+overlay.getBoxPadding()+5; - for(Map.Entry entry : allTalismans.entrySet()) { - if(accessoryMap.containsKey(entry.getKey())) { - continue; - } - if(mouseX > x && mouseX < x+16) { - if(mouseY > y && mouseY < y+16) { - display = manager.jsonToStack(entry.getValue()); - } - } - - drawRect(x, y, x+16, y+16, fg.getRGB()); - Utils.drawItemStack(manager.jsonToStack(entry.getValue()), x, y); - x += 20; - if(x + 20 + (leftSide+overlay.getBoxPadding()+5) > paneWidth) { - x=leftSide+overlay.getBoxPadding()+5; - y+=20; - } - } - - y+=20; - y += renderParagraph(width, height, y, "Recommended Accessory Upgrades"); - - x=leftSide+overlay.getBoxPadding()+5; - for(JsonObject json : recommended) { - if(mouseX > x && mouseX < x+16) { - if(mouseY > y && mouseY < y+16) { - display = manager.jsonToStack(json); - } - } - - drawRect(x, y, x+16, y+16, fg.getRGB()); - Utils.drawItemStack(manager.jsonToStack(json), x, y); - x += 20; - if(x + 20 + (leftSide+overlay.getBoxPadding()+5) > paneWidth) { - x=leftSide+overlay.getBoxPadding()+5; - y+=20; - } - } - - //L:9/cost, E=6/cost, R=3/cost, C=1/cost - - - if(display != null) { - List list = display.getTooltip(Minecraft.getMinecraft().thePlayer, - Minecraft.getMinecraft().gameSettings.advancedItemTooltips); - - for (int i = 0; i < list.size(); ++i){ - if (i == 0){ - list.set(i, display.getRarity().rarityColor + list.get(i)); - } else { - list.set(i, EnumChatFormatting.GRAY + list.get(i)); - } - } - - Utils.drawHoveringText(list, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); - } - } - - public boolean keyboardInput() { - return false; - } - - - private int renderParagraph(int width, int height, int startY, String text) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - - int paneWidth = (int)(width/3*overlay.getWidthMult()); - int rightSide = (int)(width*overlay.getInfoPaneOffsetFactor()); - int leftSide = rightSide - paneWidth; - - int yOff = 0; - for(String line : text.split("\n")) { - yOff += Utils.renderStringTrimWidth(line, fr, false,leftSide+overlay.getBoxPadding() + 5, - startY + yOff, - width*1/3-overlay.getBoxPadding()*2-10, Color.WHITE.getRGB(), -1); - yOff += 16; - } - - return yOff; - } - - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java index 147c006c..2bba6426 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java @@ -58,13 +58,37 @@ public class SettingsInfoPane extends InfoPane { AtomicInteger tfTopX = new AtomicInteger(); AtomicInteger tfTopY = new AtomicInteger(); iterateSettingTile(new SettingsTileConsumer() { - public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option) { + public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option, Options.Button button) { float mult = tileWidth/90f; drawRect(x, y, x+tileWidth, y+tileHeight, fg.getRGB()); if(manager.config.hideApiKey.value && option==manager.config.apiKey) return; + if(option == null) { + Utils.renderStringTrimWidth(button.displayName, fr, true, x+(int)(8*mult), y+(int)(8*mult), + tileWidth-(int)(16*mult), new Color(100,255,150).getRGB(), 3, + 2f/scaledresolution.getScaleFactor()); + + GlStateManager.color(1f, 1f, 1f, 1f); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); + Utils.drawTexturedRect(x + tileWidth/2f - (int) (32 * mult), y + tileHeight - (int) (20 * mult), (int) (48 * mult), (int) (16 * mult)); + + Minecraft.getMinecraft().getTextureManager().bindTexture(help); + Utils.drawTexturedRect(x + tileWidth/2f + (int) (19 * mult), y + tileHeight - (int) (19 * mult), (int) (14 * mult), (int) (14 * mult)); + GlStateManager.bindTexture(0); + + if (mouseX > x + tileWidth / 2 + (int) (19 * mult) && mouseX < x + tileWidth / 2 + (int) (19 * mult) + (int) (14 * mult)) { + if (mouseY > y + tileHeight - (int) (19 * mult) && mouseY < y + tileHeight - (int) (19 * mult) + (int) (14 * mult)) { + List textLines = new ArrayList<>(); + textLines.add(button.displayName); + textLines.add(EnumChatFormatting.GRAY + button.desc); + textToDisplay.set(textLines); + } + } + return; + } + Utils.renderStringTrimWidth(option.displayName, fr, true, x+(int)(8*mult), y+(int)(8*mult), tileWidth-(int)(16*mult), new Color(100,255,150).getRGB(), 3, 2f/scaledresolution.getScaleFactor()); @@ -166,9 +190,18 @@ public class SettingsInfoPane extends InfoPane { public void mouseInput(int width, int height, int mouseX, int mouseY, boolean mouseDown) { iterateSettingTile(new SettingsTileConsumer() { @Override - public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option) { + public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option, Options.Button button) { float mult = tileWidth/90f; - if(option.value instanceof Boolean) { + if(option == null) { + if(Mouse.getEventButtonState()) { + if(mouseX > x+tileWidth/2-(int)(32*mult) && mouseX < x+tileWidth/2-(int)(32*mult)+(int)(48*mult)) { + if(mouseY > y+tileHeight-(int)(20*mult) && mouseY < y+tileHeight-(int)(20*mult)+(int)(16*mult)) { + button.click.run(); + return; + } + } + } + } else if(option.value instanceof Boolean) { if(Mouse.getEventButtonState()) { if(mouseX > x+tileWidth/2-(int)(32*mult) && mouseX < x+tileWidth/2-(int)(32*mult)+(int)(48*mult)) { if(mouseY > y+tileHeight-(int)(20*mult) && mouseY < y+tileHeight-(int)(20*mult)+(int)(16*mult)) { @@ -293,7 +326,9 @@ public class SettingsInfoPane extends InfoPane { AtomicBoolean ret = new AtomicBoolean(false); iterateSettingTile(new SettingsTileConsumer() { @Override - public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option) { + public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option, Options.Button button) { + if(option == null) return; + if(!textConfigMap.containsKey(option)) { textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), 0)); } @@ -312,7 +347,7 @@ public class SettingsInfoPane extends InfoPane { } private abstract static class SettingsTileConsumer { - public abstract void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option); + public abstract void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option, Options.Button button); } public void iterateSettingTile(SettingsTileConsumer settingsTileConsumer) { @@ -340,7 +375,7 @@ public class SettingsInfoPane extends InfoPane { int currPage=0; int x=0; int y=tilePadding+overlay.getBoxPadding()+overlay.getSearchBarYSize(); - for(int i=0; i childrenPosition = new HashMap<>(); + + public MBGuiGroup() { + } + + public abstract Collection getChildren(); + + public Map getChildrenPosition() { + return Collections.unmodifiableMap(childrenPosition); + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + + @Override + public void mouseClick(float x, float y, int mouseX, int mouseY) { + for(MBGuiElement child : getChildren()) { + Vector2f childPos = childrenPosition.get(child); + if(mouseX > x+childPos.x && mouseX < x+childPos.x+child.getWidth()) { + if(mouseY > y+childPos.y && mouseY < y+childPos.y+child.getHeight()) { + child.mouseClick(x+childPos.x, y+childPos.y, mouseX, mouseY); + } + } + } + } + + @Override + public void mouseClickOutside() { + for(MBGuiElement child : getChildren()) { + child.mouseClickOutside(); + } + } + + @Override + public void render(float x, float y) { + for(MBGuiElement child : getChildren()) { + Vector2f childPos = childrenPosition.get(child); + child.render(x+childPos.x, y+childPos.y); + } + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java new file mode 100644 index 00000000..91cca2d7 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java @@ -0,0 +1,42 @@ +package io.github.moulberry.notenoughupdates.mbgui; + +import org.lwjgl.util.vector.Vector2f; + +import java.util.*; + +public class MBGuiGroupFloating extends MBGuiGroup { + + private LinkedHashMap children; + + public MBGuiGroupFloating(int width, int height, LinkedHashMap children) { + this.width = width; + this.height = height; + this.children = children; + recalculate(); + } + + public Map getChildrenMap() { + return Collections.unmodifiableMap(children); + } + + @Override + public void recalculate() { + for(MBGuiElement child : children.keySet()) { + child.recalculate(); + } + + for(Map.Entry entry : children.entrySet()) { + MBGuiElement child = entry.getKey(); + MBAnchorPoint anchorPoint = entry.getValue(); + float x = anchorPoint.anchorPoint.x * width - anchorPoint.anchorPoint.x * child.getWidth() + anchorPoint.offset.x; + float y = anchorPoint.anchorPoint.y * height - anchorPoint.anchorPoint.y * child.getHeight() + anchorPoint.offset.y; + childrenPosition.put(child, new Vector2f(x, y)); + } + } + + @Override + public Collection getChildren() { + return children.keySet(); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupHorz.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupHorz.java new file mode 100644 index 00000000..cf477eac --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupHorz.java @@ -0,0 +1,47 @@ +package io.github.moulberry.notenoughupdates.mbgui; + +import org.lwjgl.util.vector.Vector2f; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +public abstract class MBGuiGroupHorz extends MBGuiGroup { + + private List children; + + public MBGuiGroupHorz(List children) { + this.children = children; + recalculate(); + } + + public abstract int getPadding(); + + public Collection getChildren() { + return children; + } + + public void recalculate() { + for(MBGuiElement child : children) { + child.recalculate(); + } + + width = 0; + for(int i=0; i height) { + height = childHeight; + } + } + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java index 047ca5af..1c8a6e07 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java @@ -1,8 +1,17 @@ package io.github.moulberry.notenoughupdates.options; import com.google.gson.*; +import io.github.moulberry.notenoughupdates.NEUOverlayPlacements; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.mbgui.MBAnchorPoint; import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.util.Util; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.client.ForgeHooksClient; +import org.lwjgl.util.vector.Vector2f; +import java.awt.*; import java.io.*; import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; @@ -38,6 +47,11 @@ public class Options { "Quick Commands", false, "Shows QuickCommands™ above search bar."); + public Option showUpdateMsg = new Option( + true, + "Show Update Notifs", + false, + "Shows update messages if NEU is out-of-date."); public Option tooltipBorderColours = new Option( true, "Coloured Tooltip Borders", @@ -63,6 +77,11 @@ public class Options { "Hide Apikey Setting", false, "Hides the Apikey setting (please try not to leak Apikey if you're recording)"); + public Option quickAHUpdate = new Option( + false, + "NeuAH Quick Update", + false, + "Will instantly update the whole AH when an api update is detected (aka as fast as possible). Warning: Uses lots of data."); public Option bgBlurFactor = new Option( 5.0, "Background Blur", @@ -78,6 +97,16 @@ public class Options { "Automatically Update Items", false, "If true, updated items will automatically download from the remote repository when you start the game. \nHIGHLY RECOMMENDED."); + public Option quickcommandMousePress = new Option( + false, + "QuickCommand on Mouse Press", + false, + "If true, quickcommands will trigger on mouse down instead of mouse up."); + public Option disableItemTabOpen = new Option( + false, + "No Tab Open", + false, + "If True, moving your mouse to the item tab on the right side won't open the itempane."); public Option keepopen = new Option( false, "Keep Itempane Open", @@ -113,6 +142,16 @@ public class Options { "Pane Padding", false, "Changes the padding of the panes. Value between 0-20.", 0, 20); + public Option ahNotification = new Option( + 2.0, + "AH Notification (Mins, 0 = off)", + false, + "Minutes before AH ends to notify. 0-10.", 0, 10); + public Option tooltipBorderOpacity = new Option( + 200.0, + "Coloured Tooltip Border Opacity", + false, + "Coloured tooltips only apply to tooltips in my GUIs. Value between 0-255.", 0, 255); /** * OPTIONS THAT DON'T SHOW IN GUI @@ -122,6 +161,11 @@ public class Options { "Show Dev Options", true, "Dev Feature. Please don't use."); + public Option selectedCape = new Option( + "", + "Selected Cape", + true, + "Selected Cape"); public Option compareMode = new Option( 0.0, "Compare Mode", @@ -152,6 +196,16 @@ public class Options { "Quick Commands", false, "Quick Commands"); + public Option overlaySearchBar = new Option( + "", + "OverlaySearchBar", + false, + "OverlaySearchBar"); + public Option overlayQuickCommand = new Option( + "", + "OverlaySearchBar", + false, + "OverlaySearchBar"); private ArrayList createDefaultQuickCommands() { ArrayList arr = new ArrayList<>(); @@ -160,34 +214,74 @@ public class Options { arr.add("/craft:Crafting Table:CRAFTING_TABLE"); arr.add("/enderchest:Ender Chest:ENDER_CHEST"); arr.add("/wardrobe:Wardrobe:LEATHER_CHESTPLATE"); + arr.add("/pets:Pets:BONE"); arr.add("neucl:Collection Log:MAP"); arr.add("neuah:NEU Auction House:GOLD_BLOCK"); return arr; } + public class Button { + public String displayName; + public String desc; + public Runnable click; + + public Button(String displayName, String desc, Runnable click) { + this.displayName = displayName; + this.desc = desc; + this.click = click; + } + } + + private transient List