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') 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; +