From 009ed0ef14d3a5fd75be17ed2c90688202e69c85 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 5 Jul 2020 07:17:21 +1000 Subject: 1.9 --- .../moulberry/notenoughupdates/CustomAH.java | 607 ++++++++++++++++----- .../moulberry/notenoughupdates/CustomAHGui.java | 16 + .../moulberry/notenoughupdates/GuiItemRecipe.java | 1 + .../moulberry/notenoughupdates/GuiItemUsages.java | 1 + .../moulberry/notenoughupdates/GuiTextures.java | 6 +- .../moulberry/notenoughupdates/NEUManager.java | 317 ++++++++--- .../moulberry/notenoughupdates/NEUOverlay.java | 61 ++- .../notenoughupdates/NotEnoughUpdates.java | 98 +++- .../moulberry/notenoughupdates/StreamerMode.java | 2 +- .../github/moulberry/notenoughupdates/Utils.java | 422 -------------- .../infopanes/CollectionLogInfoPane.java | 23 +- .../notenoughupdates/infopanes/DevInfoPane.java | 12 - .../infopanes/FlipperInfoPane.java | 7 +- .../notenoughupdates/infopanes/HTMLInfoPane.java | 23 +- .../notenoughupdates/infopanes/QOLInfoPane.java | 10 +- .../infopanes/SettingsInfoPane.java | 3 +- .../notenoughupdates/infopanes/TextInfoPane.java | 2 +- .../itemeditor/GuiElementTextField.java | 5 +- .../notenoughupdates/itemeditor/NEUItemEditor.java | 2 +- .../mixins/MixinInventoryEffectRenderer.java | 5 - .../notenoughupdates/mixins/MixinItemStack.java | 2 +- .../notenoughupdates/options/Options.java | 17 +- .../notenoughupdates/util/HypixelApi.java | 4 +- .../moulberry/notenoughupdates/util/Utils.java | 435 +++++++++++++++ .../assets/notenoughupdates/ah_item_holder.png | Bin 642 -> 0 bytes .../assets/notenoughupdates/ah_item_tab.png | Bin 627 -> 0 bytes .../assets/notenoughupdates/auction_price.png | Bin 0 -> 4457 bytes .../assets/notenoughupdates/auction_view.png | Bin 0 -> 5031 bytes .../notenoughupdates/auction_view_buttons.png | Bin 0 -> 1286 bytes .../assets/notenoughupdates/item_edit.png | Bin 11387 -> 0 bytes 30 files changed, 1337 insertions(+), 744 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/CustomAHGui.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/Utils.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java delete mode 100644 src/main/resources/assets/notenoughupdates/ah_item_holder.png delete mode 100644 src/main/resources/assets/notenoughupdates/ah_item_tab.png create mode 100644 src/main/resources/assets/notenoughupdates/auction_price.png create mode 100644 src/main/resources/assets/notenoughupdates/auction_view.png create mode 100644 src/main/resources/assets/notenoughupdates/auction_view_buttons.png delete mode 100644 src/main/resources/assets/notenoughupdates/item_edit.png diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomAH.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomAH.java index d74d0e5c..f0e3437f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/CustomAH.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/CustomAH.java @@ -1,48 +1,55 @@ package io.github.moulberry.notenoughupdates; -import com.google.gson.JsonArray; -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.FontRenderer; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.gui.inventory.GuiEditSign; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.item.Item; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Base64; -import java.util.HashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; +import java.awt.*; +import java.text.NumberFormat; +import java.util.*; +import java.util.List; import static io.github.moulberry.notenoughupdates.GuiTextures.*; -public class CustomAH extends GuiScreen { +public class CustomAH extends Gui { - private static final ResourceLocation inventoryBackground = new ResourceLocation("textures/gui/container/inventory.png"); private static final ResourceLocation creativeTabSearch = new ResourceLocation("textures/gui/container/creative_inventory/tab_item_search.png"); private static final ResourceLocation creativeInventoryTabs = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png"); - private int yScrollInitial = 0; + private List auctionIds = new ArrayList<>(); + private boolean scrollClicked = false; + private int startingBid = 0; + + private GuiTextField searchField = null; + private GuiTextField priceField = null; + + private boolean renderOverAuctionView = false; + private long lastRenderDisable = 0; + + private int eventButton; + private long lastMouseEvent; private int splits = 2; private int ySplit = 35; private int ySplitSize = 18; - private int ySize = 136 + ySplitSize*splits; - private int xSize = 195; private float scrollAmount; @@ -50,136 +57,476 @@ public class CustomAH extends GuiScreen { private int guiTop = 0; private NEUManager manager; - private HashMap auctionItems = new HashMap<>(); - - private TexLoc tl = new TexLoc(0, 0, Keyboard.KEY_M); public CustomAH(NEUManager manager) { this.manager = manager; - updateAuctions(); - } - - private void updateAuctions() { - HashMap 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/profiles", - args, jsonObject -> { - if(jsonObject.get("success").getAsBoolean()) { - pages.put(0, jsonObject); - totalPages.set(jsonObject.get("totalPages").getAsInt()); - currentPages.incrementAndGet(); - - for(int i=1; i args2 = new HashMap<>(); - args2.put("page", ""+i); - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/profiles", - args2, jsonObject2 -> { - if (jsonObject2.get("success").getAsBoolean()) { - pages.put(j, jsonObject2); - currentPages.incrementAndGet(); - } - } - ); - } - } + } + + private void init() { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + this.searchField = new GuiTextField(0, fr, this.guiLeft + 82, this.guiTop + 6, + 89, fr.FONT_HEIGHT); + this.priceField = new GuiTextField(1, fr, this.guiLeft + 82, this.guiTop + 6, + 89, fr.FONT_HEIGHT); + + this.searchField.setMaxStringLength(15); + this.searchField.setEnableBackgroundDrawing(false); + this.searchField.setTextColor(16777215); + this.searchField.setVisible(true); + this.searchField.setCanLoseFocus(false); + this.searchField.setFocused(true); + this.searchField.setText(""); + + this.priceField.setMaxStringLength(10); + this.priceField.setEnableBackgroundDrawing(false); + this.priceField.setTextColor(16777215); + this.priceField.setVisible(true); + this.priceField.setCanLoseFocus(false); + this.priceField.setFocused(false); + this.priceField.setText(""); + } + + public boolean isRenderOverAuctionView() { + return renderOverAuctionView || (System.currentTimeMillis() - lastRenderDisable) < 500; + } + + public void setRenderOverAuctionView(boolean renderOverAuctionView) { + if(this.renderOverAuctionView && !renderOverAuctionView) lastRenderDisable = System.currentTimeMillis(); + this.renderOverAuctionView = renderOverAuctionView; + } + + private int getXSize() { + return 195; + } + + private int getYSize() { + return 136 + ySplitSize*splits; + } + + private TexLoc tl = new TexLoc(0, 0, Keyboard.KEY_M); + + public List getTooltipForAucId(String aucId) { + NEUManager.Auction auc = manager.getAuctionItems().get(aucId); + + List tooltip = new ArrayList<>(); + + for(String line : auc.getStack().getTooltip(Minecraft.getMinecraft().thePlayer, false)) { + tooltip.add(EnumChatFormatting.GRAY+line); + } + + long timeUntilEnd = auc.end - System.currentTimeMillis(); + + long seconds = timeUntilEnd / 1000 % 60; + long minutes = (timeUntilEnd / 1000 / 60) % 60; + long hours = (timeUntilEnd / 1000 / 60 / 60) % 24; + long days = (timeUntilEnd / 1000 / 60 / 60 / 24); + + String endsIn = EnumChatFormatting.YELLOW+""; + if(timeUntilEnd < 0) { + endsIn += "Ended!"; + } else if(minutes == 0 && hours == 0 && days == 0) { + endsIn += seconds + "s"; + } else if(hours==0 && days==0) { + endsIn += minutes + "m" + seconds + "s"; + } else if(days==0) { + if(hours <= 6) { + endsIn += hours + "h" + minutes + "m" + seconds + "s"; + } else { + endsIn += hours + "h"; } - ); - - ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();//1593549115 () 1593631661919 - long startTime = System.currentTimeMillis(); - ses.schedule(new Runnable() { - public void run() { - if(System.currentTimeMillis() - startTime > 20000) return; - - if(currentPages.get() == totalPages.get()) { - auctionItems.clear(); - for(int pageNum : pages.keySet()) { - JsonObject page = pages.get(pageNum); - JsonArray auctions = page.get("auctions").getAsJsonArray(); - for(int i=0; i 0) { + tooltip.add(EnumChatFormatting.GRAY+"Bids: "+EnumChatFormatting.GREEN+auc.bid_count+" bids"); + tooltip.add(""); + tooltip.add(EnumChatFormatting.GRAY+"Top bid: "+ + EnumChatFormatting.GOLD+format.format(auc.highest_bid_amount)); + tooltip.add(EnumChatFormatting.GRAY+"Bidder: [CLICK TO SEE]"); + } else { + tooltip.add(EnumChatFormatting.GRAY+"Starting bid: "+ + EnumChatFormatting.GOLD+format.format(auc.starting_bid)); } - }, 5000L, TimeUnit.MILLISECONDS); + } + + tooltip.add(""); + tooltip.add(EnumChatFormatting.GRAY+"Ends in: "+endsIn); + tooltip.add(""); + tooltip.add(EnumChatFormatting.YELLOW+"Click to inspect!"); + + return tooltip; + } + public boolean isEditingPrice() { + return Minecraft.getMinecraft().currentScreen instanceof GuiEditSign; } - public void drawScreen(int mouseX, int mouseY, float partialTicks) { + public void drawScreen(int mouseX, int mouseY) { + Mouse.setGrabbed(false); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + if(searchField == null || priceField == null) init(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); tl.handleKeyboardInput(); - guiLeft = (this.width - xSize)/2; - guiTop = (this.height - ySize)/2; + guiLeft = (width - getXSize())/2; + guiTop = (height - getYSize())/2; + this.searchField.xPosition = guiLeft + 82; + this.searchField.yPosition = guiTop + 6; + + this.searchField.setFocused(true); + this.priceField.setFocused(false); + + if(!isEditingPrice()) priceField.setText("IAUSHDIUAH"); + + List tooltipToRender = null; + if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest auctionView = (GuiChest) Minecraft.getMinecraft().currentScreen; + + int auctionViewLeft = guiLeft+getXSize()+4; + + Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view); + this.drawTexturedModalRect(auctionViewLeft, guiTop, 0, 0, 78, 172); + + try { + ItemStack itemStack = auctionView.inventorySlots.getSlot(13).getStack(); + Utils.drawItemStack(itemStack, auctionViewLeft+31, guiTop+35); + + ItemStack bidStack = auctionView.inventorySlots.getSlot(29).getStack(); + Utils.drawItemStack(bidStack, auctionViewLeft+31, guiTop+100); + + ItemStack historyStack = auctionView.inventorySlots.getSlot(33).getStack(); + + ItemStack changeBidStack = auctionView.inventorySlots.getSlot(31).getStack(); - this.mc.getTextureManager().bindTexture(creativeTabSearch); - this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySplit); + if(changeBidStack != null && changeBidStack.getTagCompound().hasKey("AttributeModifiers")) { + Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view_buttons); + boolean hover = mouseX > auctionViewLeft+31 && mouseX guiTop+126 && mouseY < guiTop+126+16; + this.drawTexturedModalRect(auctionViewLeft+31, guiTop+126, hover?16:0, 0, 16, 16); + } else { + changeBidStack = null; + } + + if(mouseX > auctionViewLeft+31 && mouseX guiTop+35 && mouseY < guiTop+35+16) { + if(itemStack != null) tooltipToRender = itemStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } else if(mouseY > guiTop+100 && mouseY < guiTop+100+16) { + if(bidStack != null) tooltipToRender = bidStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } else if(mouseY > guiTop+61 && mouseY < guiTop+61+16) { + if(historyStack != null) tooltipToRender = historyStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } else if(mouseY > guiTop+126 && mouseY < guiTop+126+16) { + if(changeBidStack != null) tooltipToRender = changeBidStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + } catch(NullPointerException e) { //i cant be bothered + } + } else if(isEditingPrice()) { + int auctionViewLeft = guiLeft+getXSize()+4; + + if(priceField.getText().equals("IAUSHDIUAH")) priceField.setText(""+startingBid); + + searchField.setFocused(false); + priceField.setFocused(true); + priceField.xPosition = auctionViewLeft+18; + priceField.yPosition = guiTop+18; + + Minecraft.getMinecraft().getTextureManager().bindTexture(auction_price); + this.drawTexturedModalRect(auctionViewLeft, guiTop, 0, 0, 96, 99); + priceField.drawTextBox(); + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view_buttons); + this.drawTexturedModalRect(auctionViewLeft+16, guiTop+32, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16+34, guiTop+32, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16, guiTop+50, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16+34, guiTop+50, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16, guiTop+68, 0, 32, 64, 16); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + Utils.drawStringCentered("x2", fr, auctionViewLeft+16+15, guiTop+32+8, false, + Color.BLACK.getRGB()); + Utils.drawStringCentered("+50%", fr, auctionViewLeft+16+34+15, guiTop+32+8, false, + Color.BLACK.getRGB()); + Utils.drawStringCentered("+25%", fr, auctionViewLeft+16+15, guiTop+50+8, false, + Color.BLACK.getRGB()); + Utils.drawStringCentered("+10%", fr, auctionViewLeft+16+34+15, guiTop+50+8, false, + Color.BLACK.getRGB()); + Utils.drawStringCentered("Set Amount", fr, auctionViewLeft+16+32, guiTop+68+8, false, + Color.BLACK.getRGB()); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + + GuiEditSign editSign = (GuiEditSign) Minecraft.getMinecraft().currentScreen; + TileEntitySign tes = (TileEntitySign)Utils.getField(GuiEditSign.class, editSign, + "tileSign", "field_146848_f"); + tes.lineBeingEdited = 0; + tes.signText[0] = new ChatComponentText(priceField.getText()); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(creativeTabSearch); + this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, getXSize(), ySplit); int y = guiTop+ySplit; for(int i=0; i itemX && mouseX < itemX+16) { + if(mouseY > itemY && mouseY < itemY+16) { + tooltipToRender = getTooltipForAucId(aucid); + } + } + } catch(Exception e) { + break out; + } + } + } + + searchField.drawTextBox(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + + if(auctionIds.size() == 0 && searchField.getText().length() == 0) { + drawRect(guiLeft+8, guiTop+17, guiLeft+170, guiTop+107+18*splits, + new Color(100, 100, 100, 100).getRGB()); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int strWidth = fr.getStringWidth("Loading items..."); + fr.drawString("Loading items...", guiLeft+(8+170-strWidth)/2, guiTop+(17+107+18*splits)/2, Color.BLACK.getRGB()); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(creativeInventoryTabs); this.drawTexturedModalRect(guiLeft+175, guiTop+18+(int)((95+ySplitSize*2)*scrollAmount), 256-(scrollClicked?12:24), 0, 12, 15); + + if(tooltipToRender != null) { + Utils.drawHoveringText(tooltipToRender, mouseX, mouseY, width, + height, -1, Minecraft.getMinecraft().fontRendererObj); + } + } + + public void handleMouseInput() { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + int mouseX = Mouse.getEventX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getEventY() * height / Minecraft.getMinecraft().displayHeight - 1; + int mouseButton = Mouse.getEventButton(); + + if (Mouse.getEventButtonState()) { + this.eventButton = mouseButton; + this.lastMouseEvent = Minecraft.getSystemTime(); + mouseClicked(mouseX, mouseY, this.eventButton); + } else if (mouseButton != -1) { + this.eventButton = -1; + mouseReleased(mouseX, mouseY, mouseButton); + } else if (this.eventButton != -1 && this.lastMouseEvent > 0L) { + long l = Minecraft.getSystemTime() - this.lastMouseEvent; + mouseClickMove(mouseX, mouseY, this.eventButton, l); + } + + int dWheel = Mouse.getDWheel(); + + scrollAmount = scrollAmount - dWheel/((float)auctionIds.size()-(5+splits)); + scrollAmount = Math.max(0, Math.min(1, scrollAmount)); + } + + 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 void updateSearch() { + scrollAmount = 0; + auctionIds.clear(); + try { + for(Map.Entry entry : manager.getAuctionItems().entrySet()) { + if(searchField.getText().length() == 0 || + Utils.cleanColour(entry.getValue().extras).toLowerCase().contains(searchField.getText().toLowerCase())) { + auctionIds.add(entry.getKey()); + } + } + } catch(ConcurrentModificationException e) { + updateSearch(); + } + } + + public boolean keyboardInput() { + if(isEditingPrice() && Keyboard.getEventKey() == Keyboard.KEY_RETURN) { + Minecraft.getMinecraft().displayGuiScreen(null); + } else if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { + return false; + } + keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + return true; + } + + public void keyTyped(char typedChar, int keyCode) { + if(searchField == null || priceField == null) init(); + + if(!isEditingPrice()) { + if(this.searchField.textboxKeyTyped(typedChar, keyCode)) { + this.updateSearch(); + } + } else { + priceField.textboxKeyTyped(typedChar, keyCode); + } + } + + private void increasePriceByFactor(float factor) { + String price = priceField.getText().trim(); + StringBuilder priceNumbers = new StringBuilder(); + for(int i=0; i= 48 && (int)c <= 57) { + priceNumbers.append(c); + } else { + break; + } + } + int priceI = 0; + if(priceNumbers.length() > 0) { + priceI = Integer.parseInt(priceNumbers.toString()); + } + String end = price.substring(priceNumbers.length()); + priceField.setText((int)(priceI*factor) + end); } - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { + searchField.mouseClicked(mouseX, mouseY, mouseButton); + + int totalItems = auctionIds.size(); + int itemsScroll = (int)Math.floor((totalItems*scrollAmount)/9f)*9; + + int maxItemScroll = Math.max(0, totalItems - (5+splits)*9); + itemsScroll = Math.min(itemsScroll, maxItemScroll); + + if(mouseButton == 0 && Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest auctionView = (GuiChest) Minecraft.getMinecraft().currentScreen; + + if(mouseX > guiLeft+getXSize()+4+31 && mouseX < guiLeft+getXSize()+4+31+16) { + if(mouseY > guiTop+100 && mouseY < guiTop+100+16) { + Minecraft.getMinecraft().playerController.windowClick(auctionView.inventorySlots.windowId, + 29, 2, 3, Minecraft.getMinecraft().thePlayer); + } else if(mouseY > guiTop+126 && mouseY < guiTop+126+16) { + Minecraft.getMinecraft().playerController.windowClick(auctionView.inventorySlots.windowId, + 31, 0, 4, Minecraft.getMinecraft().thePlayer); + } + } + } + if(mouseButton == 0 && isEditingPrice()) { + int auctionViewLeft = guiLeft+getXSize()+4; + System.out.println("1"); + + if(mouseX > auctionViewLeft+16 && mouseX < auctionViewLeft+16+64) { + System.out.println("2"); + if(mouseY > guiTop+32 && mouseY < guiTop+32+16) { + System.out.println("3"); + if(mouseX < auctionViewLeft+16+32) { + //top left + increasePriceByFactor(2); + } else { + //top right + increasePriceByFactor(1.5f); + } + } else if(mouseY > guiTop+50 && mouseY < guiTop+50+16) { + if(mouseX < auctionViewLeft+16+32) { + //mid left + increasePriceByFactor(1.25f); + } else { + //mid right + increasePriceByFactor(1.1f); + } + } else if(mouseY > guiTop+68 && mouseY < guiTop+68+16) { + //bottom + Minecraft.getMinecraft().displayGuiScreen(null); + } + } + + this.drawTexturedModalRect(auctionViewLeft+16, guiTop+32, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16+34, guiTop+32, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16, guiTop+50, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16+34, guiTop+50, 0, 16, 30, 16); + this.drawTexturedModalRect(auctionViewLeft+16, guiTop+68, 0, 32, 64, 16); + } + + out: + for(int i=0; i<5+splits; i++) { + int itemY = guiTop + i*18 + 18; + for(int j=0; j<9; j++) { + int itemX = guiLeft + j*18 + 9; + int id = itemsScroll + i*9 + j; + if(auctionIds.size() <= id) break out; + + String aucid; + try { + aucid = auctionIds.get(id); + } catch (IndexOutOfBoundsException e) { break out; } + + NEUManager.Auction auc = manager.getAuctionItems().get(aucid); + long timeUntilEnd = auc.end - System.currentTimeMillis(); + + if(timeUntilEnd > 0) { + if(mouseX > itemX && mouseX < itemX+16) { + if(mouseY > itemY && mouseY < itemY+16) { + startingBid = Math.max(auc.starting_bid, auc.highest_bid_amount); + NotEnoughUpdates.INSTANCE.sendChatMessage("/viewauction "+niceAucId(aucid)); + } + } + } + + + } + } + int y = guiTop+18+(int)((95+ySplitSize*2)*scrollAmount); if(mouseX > guiLeft+175 && mouseX < guiLeft+175+12) { if(mouseY > y && mouseY < y+15) { @@ -190,18 +537,16 @@ public class CustomAH extends GuiScreen { scrollClicked = false; } - @Override protected void mouseReleased(int mouseX, int mouseY, int state) { scrollClicked = false; } - @Override protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { if(scrollClicked) { int yMin = guiTop+18 + 8; int yMax = guiTop+18+(95+ySplitSize*2) + 8; - scrollAmount = (mouseY-yMin)/(float)yMax; + scrollAmount = (mouseY-yMin)/(float)(yMax-yMin); scrollAmount = Math.max(0, Math.min(1, scrollAmount)); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomAHGui.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomAHGui.java new file mode 100644 index 00000000..af7486a0 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/CustomAHGui.java @@ -0,0 +1,16 @@ +package io.github.moulberry.notenoughupdates; + +import net.minecraft.client.gui.GuiScreen; +import org.lwjgl.input.Mouse; + +public class CustomAHGui extends GuiScreen { + + public CustomAHGui() { + this.allowUserInput = true; + } + + public boolean doesGuiPauseGame() { + return false; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java index 6916372b..0cdef647 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java @@ -1,6 +1,7 @@ package io.github.moulberry.notenoughupdates; import com.google.gson.JsonObject; +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; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java index 49a1be51..06fc3d71 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java @@ -2,6 +2,7 @@ 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; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java index 965a7e48..ec44474e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java @@ -11,7 +11,6 @@ public class GuiTextures { //public static final ResourceLocation next = new ResourceLocation("notenoughupdates:next.png"); public static final ResourceLocation rightarrow_overlay = new ResourceLocation("notenoughupdates:rightarrow_overlay.png"); public static final ResourceLocation rightarrow = new ResourceLocation("notenoughupdates:rightarrow.png"); - public static final ResourceLocation item_edit = new ResourceLocation("notenoughupdates:item_edit.png"); public static final ResourceLocation close = new ResourceLocation("notenoughupdates:close.png"); public static final ResourceLocation settings = new ResourceLocation("notenoughupdates:settings.png"); @@ -24,8 +23,9 @@ public class GuiTextures { public static final ResourceLocation item_mask = new ResourceLocation("notenoughupdates:item_mask.png"); - public static final ResourceLocation ah_item_holder = new ResourceLocation("notenoughupdates:ah_item_holder.png"); - public static final ResourceLocation ah_item_tab = new ResourceLocation("notenoughupdates:ah_item_tab.png"); + public static final ResourceLocation auction_view = new ResourceLocation("notenoughupdates:auction_view.png"); + public static final ResourceLocation auction_price = new ResourceLocation("notenoughupdates:auction_price.png"); + public static final ResourceLocation auction_view_buttons = new ResourceLocation("notenoughupdates:auction_view_buttons.png"); public static final ResourceLocation logo = new ResourceLocation("notenoughupdates:logo.png"); public static final ResourceLocation logo_fg = new ResourceLocation("notenoughupdates:logo_fg.png"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index e2c8d928..502cebe9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -1,10 +1,8 @@ package io.github.moulberry.notenoughupdates; -import com.google.common.io.CharSource; import com.google.gson.*; import io.github.moulberry.notenoughupdates.options.Options; import io.github.moulberry.notenoughupdates.util.HypixelApi; -import javafx.scene.control.Alert; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import net.minecraft.init.Items; @@ -12,21 +10,19 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; import net.minecraft.network.play.client.C0DPacketCloseWindow; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.ReaderInputStream; -import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; import javax.swing.*; import java.io.*; -import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.text.NumberFormat; 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; @@ -54,7 +50,7 @@ public class NEUManager { public String viewItemAttemptID = null; public long viewItemAttemptTime = 0; - public String currentProfile = "Papaya"; + public String currentProfile = ""; public final HypixelApi hypixelApi = new HypixelApi(); private ResourceLocation wkZip = new ResourceLocation("notenoughupdates:wkhtmltox.zip"); @@ -64,6 +60,11 @@ public class NEUManager { private JsonObject auctionPricesJson = null; private long auctionLastUpdate = 0; + private TreeMap auctionItems = new TreeMap<>(); + public CustomAH customAH = new CustomAH(this); + + private HashMap uuidToName = new HashMap<>(); + private HashMap craftCost = new HashMap<>(); private HashMap> usagesMap = new HashMap<>(); @@ -105,73 +106,47 @@ public class NEUManager { } catch (IOException e) { } } + } - //Unused code, used to automatically grab items from auctions. Leaving here in case I need it. - /*try { - for(int j=0; j<=89; j++) { - JsonObject auctions0 = getJsonFromFile(new File(configLocation, "auctions/auctions"+j+".json")); - - JsonArray arr = auctions0.getAsJsonArray("auctions"); - for(int i=0; i tag.toString().length()) { - writeItemJson(internalname, itemid, displayname, lore, info, clickcommand, damage, tag); - } - } + 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 extras; + public String item_bytes; + private ItemStack stack; + + public Auction(String auctioneerUuid, long end, int starting_bid, int highest_bid_amount, int bid_count, + boolean bin, String category, String extras, String item_bytes) { + 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.extras = extras; + this.item_bytes = item_bytes; + } - } catch(Exception e) { - } - } + public ItemStack getStack() { + if(stack != null) { + return stack; + } else { + JsonObject item = getJsonFromItemBytes(item_bytes); + ItemStack stack = jsonToStack(item, false); + this.stack = stack; + return stack; } - } catch(Exception e) { - e.printStackTrace(); } + } - throw new RuntimeException();*/ + public TreeMap getAuctionItems() { + return auctionItems; } public class CraftInfo { @@ -497,11 +472,104 @@ public class NEUManager { dialog.dispose(); } + Set currentlyInstalledItems = new HashSet<>(); for(File f : itemsLocation.listFiles()) { - loadItem(f.getName().substring(0, f.getName().length()-5)); + currentlyInstalledItems.add(f.getName().substring(0, f.getName().length()-5)); + } + + Set removedItems = neuio.getRemovedItems(currentlyInstalledItems); + for(File f : itemsLocation.listFiles()) { + String internalname = f.getName().substring(0, f.getName().length()-5); + if(!removedItems.contains(internalname)) { + loadItem(internalname); + } } } + ScheduledExecutorService auctionUpdateSES = Executors.newSingleThreadScheduledExecutor(); + private AtomicInteger auctionUpdateId = new AtomicInteger(0); + public void updateAuctions() { + HashMap pages = new HashMap<>(); + + HashMap args = new HashMap<>(); + args.put("page", "0"); + AtomicInteger totalPages = new AtomicInteger(1); + AtomicInteger currentPages = new AtomicInteger(0); + hypixelApi.getHypixelApiAsync(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); + hypixelApi.getHypixelApiAsync(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); + } + /** * Loads the item in to the itemMap and also stores various words associated with this item * in to titleWordMap and loreWordMap. These maps are used in the searching algorithm. @@ -688,6 +756,38 @@ public class NEUManager { } } + /*public TreeMap searchForStacks(String query, Set stacks, boolean multi) { + if(multi) { + Set result = new HashSet<>(); + + StringBuilder query2 = new StringBuilder(); + char lastOp = '|'; + for(char c : query.toCharArray()) { + if(c == '|' || c == '&') { + if(lastOp == '|') { + result.addAll(doesStackMatchSearch(stack, query2.toString())); + } else if(lastOp == '&') { + result.retainAll(search(query2.toString())); + } + + query2 = new StringBuilder(); + lastOp = c; + } else { + query2.append(c); + } + } + if(lastOp == '|') { + result.addAll(search(query2.toString())); + } else if(lastOp == '&') { + result.retainAll(search(query2.toString())); + } + + return result; + } else { + return search(query); + } + }*/ + /** * Returns the name of items which match a certain search query. */ @@ -792,6 +892,70 @@ public class NEUManager { return inputWithoutLastChar+incrementedLastChar; } + public JsonObject getJsonFromItemBytes(String item_bytes) { + try { + NBTTagCompound tag = CompressedStreamTools.readCompressed(new ByteArrayInputStream(Base64.getDecoder().decode(item_bytes))); + tag = tag.getTagList("i", 10).getCompoundTagAt(0); + int id = tag.getShort("id"); + int damage = tag.getShort("Damage"); + tag = tag.getCompoundTag("tag"); + + String internalname = ""; + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + if(ea.hasKey("id", 8)) { + internalname = ea.getString("id"); + } + } + + String[] lore = new String[0]; + NBTTagCompound display = tag.getCompoundTag("display"); + + if(display.hasKey("Lore", 9)) { + NBTTagList list = display.getTagList("Lore", 8); + lore = new String[list.tagCount()]; + for(int k=0; k 0) { + JsonArray jsonLore = new JsonArray(); + for (String line : lore) { + jsonLore.add(new JsonPrimitive(line)); + } + item.add("lore", jsonLore); + } + + item.addProperty("damage", damage); + item.addProperty("nbttag", tag.toString()); + + return item; + } catch(IOException e) { + return null; + } + } + private String clean(String str) { return str.replaceAll("(\u00a7.)|[^0-9a-zA-Z ]", "").toLowerCase().trim(); } @@ -1215,9 +1379,14 @@ public class NEUManager { } public ItemStack jsonToStack(JsonObject json) { - if(itemstackCache.containsKey(json.get("internalname").getAsString())) { + return jsonToStack(json, true); + } + + public ItemStack jsonToStack(JsonObject json, boolean useCache) { + if(useCache && itemstackCache.containsKey(json.get("internalname").getAsString())) { return itemstackCache.get(json.get("internalname").getAsString()).copy(); } + ItemStack stack = new ItemStack(Item.itemRegistry.getObject( new ResourceLocation(json.get("itemid").getAsString()))); @@ -1256,7 +1425,7 @@ public class NEUManager { } } - itemstackCache.put(json.get("internalname").getAsString(), stack); + if(useCache) itemstackCache.put(json.get("internalname").getAsString(), stack); return stack; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index d96be893..97964042 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -6,6 +6,7 @@ import io.github.moulberry.notenoughupdates.infopanes.*; import io.github.moulberry.notenoughupdates.itemeditor.NEUItemEditor; import io.github.moulberry.notenoughupdates.util.LerpingFloat; import io.github.moulberry.notenoughupdates.util.LerpingInteger; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; import net.minecraft.client.gui.inventory.GuiContainer; @@ -151,16 +152,17 @@ public class NEUOverlay extends Gui { for (int i = 0; i < lore.size(); i++) loreA[i] = lore.get(i).getAsString(); String loreS = StringUtils.join(loreA, "\n"); + String internalname = item.get("internalname").getAsString(); String name = item.get("displayname").getAsString(); switch(item.get("infoType").getAsString()) { case "WIKI_URL": displayInformationPane(HTMLInfoPane.createFromWikiUrl(this, manager, name, loreS)); return; case "WIKI": - displayInformationPane(HTMLInfoPane.createFromWiki(this, manager, name, loreS)); + displayInformationPane(HTMLInfoPane.createFromWiki(this, manager, name, internalname, loreS)); return; case "HTML": - displayInformationPane(new HTMLInfoPane(this, manager, name, loreS)); + displayInformationPane(new HTMLInfoPane(this, manager, name, internalname, loreS)); return; } displayInformationPane(new TextInfoPane(this, manager, name, loreS)); @@ -964,6 +966,10 @@ public class NEUOverlay extends Gui { return Math.min(255, Math.max(0, col)); } + public boolean isUsingMobsFilter() { + return getSortMode() == SORT_MODE_MOB; + } + public float yaw = 0; public float pitch = 20; @@ -1394,23 +1400,6 @@ public class NEUOverlay extends Gui { GlStateManager.disableLighting(); } - /** - * Item info (left) gui element rendering - */ - - rightSide = (int)(width*getInfoPaneOffsetFactor()); - leftSide = rightSide - paneWidth; - - if(activeInfoPane != null) { - activeInfoPane.tick(); - activeInfoPane.render(width, height, bg, fg, scaledresolution, mouseX, mouseY); - - GlStateManager.color(1f, 1f, 1f, 1f); - Minecraft.getMinecraft().getTextureManager().bindTexture(close); - Utils.drawTexturedRect(rightSide-getBoxPadding()-8, getBoxPadding()-8, 16, 16); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - } - /** * Search bar */ @@ -1438,10 +1427,10 @@ public class NEUOverlay extends Gui { int y = topTextBox - bigItemSize - bigItemPadding - paddingUnscaled*2; for(String quickCommand : quickCommands) { - if(!quickCommand.contains(":")) { + if(quickCommand.split(":").length!=3) { continue; } - String display = quickCommand.split(":")[1]; + String display = quickCommand.split(":")[2]; ItemStack render = null; float extraScale = 1; if(display.length() > 20) { //Custom head @@ -1483,6 +1472,13 @@ public class NEUOverlay extends Gui { 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); @@ -1559,6 +1555,23 @@ public class NEUOverlay extends Gui { topTextBox+(getSearchBarYSize()-8)/2, Color.BLACK.getRGB()); } + /** + * Item info (left) gui element rendering + */ + + rightSide = (int)(width*getInfoPaneOffsetFactor()); + leftSide = rightSide - paneWidth; + + if(activeInfoPane != null) { + activeInfoPane.tick(); + activeInfoPane.render(width, height, bg, fg, scaledresolution, mouseX, mouseY); + + GlStateManager.color(1f, 1f, 1f, 1f); + Minecraft.getMinecraft().getTextureManager().bindTexture(close); + Utils.drawTexturedRect(rightSide-getBoxPadding()-8, getBoxPadding()-8, 16, 16); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + //Render tooltip JsonObject json = tooltipToDisplay.get(); if(json != null) { @@ -1624,6 +1637,12 @@ public class NEUOverlay extends Gui { if(textToDisplay != null) { Utils.drawHoveringText(textToDisplay, mouseX, mouseY, width, height, -1, fr); } + + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.enableAlpha(); + GlStateManager.alphaFunc(516, 0.1F); + GlStateManager.disableLighting(); } /** diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index ab903227..6d8e91e7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -8,12 +8,11 @@ import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication; import io.github.moulberry.notenoughupdates.commands.SimpleCommand; import io.github.moulberry.notenoughupdates.infopanes.CollectionLogInfoPane; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.client.gui.inventory.*; import net.minecraft.client.settings.KeyBinding; import net.minecraft.command.ICommandSender; import net.minecraft.init.Blocks; @@ -28,11 +27,11 @@ import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Session; -import net.minecraft.util.StatCollector; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -43,6 +42,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import javax.swing.*; @@ -97,7 +97,7 @@ public class NotEnoughUpdates { if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { guiDelaySES.schedule(()->{ Minecraft.getMinecraft().displayGuiScreen(new GuiInventory(Minecraft.getMinecraft().thePlayer)); - }, 10L, TimeUnit.MILLISECONDS); + }, 20L, TimeUnit.MILLISECONDS); } manager.updatePrices(); overlay.displayInformationPane(new CollectionLogInfoPane(overlay, manager)); @@ -108,8 +108,10 @@ public class NotEnoughUpdates { public void processCommand(ICommandSender sender, String[] args) { if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { guiDelaySES.schedule(()->{ - Minecraft.getMinecraft().displayGuiScreen(new CustomAH(manager)); - }, 10L, TimeUnit.MILLISECONDS); + Minecraft.getMinecraft().displayGuiScreen(new CustomAHGui()); + Mouse.setGrabbed(false); + }, 20L, TimeUnit.MILLISECONDS); + manager.updateAuctions(); } } }); @@ -216,23 +218,26 @@ public class NotEnoughUpdates { for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { processUniqueStack(stack, newItem); } - boolean usableContainer = true; - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.openContainer.getInventory()) { - if(stack == null) { - continue; - } - if(stack.hasTagCompound()) { - NBTTagCompound tag = stack.getTagCompound(); - if(tag.hasKey("ExtraAttributes", 10)) { + if(Minecraft.getMinecraft().currentScreen instanceof GuiContainer && + !(Minecraft.getMinecraft().currentScreen instanceof GuiCrafting)) { + boolean usableContainer = true; + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.openContainer.getInventory()) { + if(stack == null) { continue; } + if(stack.hasTagCompound()) { + NBTTagCompound tag = stack.getTagCompound(); + if(tag.hasKey("ExtraAttributes", 10)) { + continue; + } + } + usableContainer = false; + break; } - usableContainer = false; - break; - } - if(usableContainer) { - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.openContainer.getInventory()) { - processUniqueStack(stack, newItem); + if(usableContainer) { + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.openContainer.getInventory()) { + processUniqueStack(stack, newItem); + } } } newItemAddMap.keySet().retainAll(newItem); @@ -259,6 +264,14 @@ public class NotEnoughUpdates { } } + @SubscribeEvent + public void onRenderGameOverlay(RenderGameOverlayEvent event) { + if(event.type.equals(RenderGameOverlayEvent.ElementType.BOSSHEALTH) && + Minecraft.getMinecraft().currentScreen instanceof GuiContainer && overlay.isUsingMobsFilter()) { + event.setCanceled(true); + } + } + /** * When opening a GuiContainer, will reset the overlay and load the config. * When closing a GuiContainer, will save the config. @@ -267,6 +280,23 @@ public class NotEnoughUpdates { AtomicBoolean missingRecipe = new AtomicBoolean(false); @SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { + if(event.gui == null && manager.customAH.isRenderOverAuctionView() && + !(Minecraft.getMinecraft().currentScreen instanceof CustomAHGui)) { + //todo + } + + if(!(event.gui instanceof GuiChest || event.gui instanceof GuiEditSign)) { + manager.customAH.setRenderOverAuctionView(false); + } else if(event.gui instanceof GuiChest && (manager.customAH.isRenderOverAuctionView() || + Minecraft.getMinecraft().currentScreen instanceof CustomAHGui)){ + GuiChest chest = (GuiChest) event.gui; + ContainerChest container = (ContainerChest) chest.inventorySlots; + String containerName = container.getLowerChestInventory().getDisplayName().getUnformattedText(); + + manager.customAH.setRenderOverAuctionView(containerName.trim().equals("Auction View") || + containerName.trim().equals("BIN Auction View")); + } + //OPEN if(Minecraft.getMinecraft().currentScreen == null && event.gui instanceof GuiContainer) { @@ -465,13 +495,21 @@ public class NotEnoughUpdates { } } + @SubscribeEvent + public void onGuiScreenDrawPre(GuiScreenEvent.DrawScreenEvent.Pre event) { + if(event.gui instanceof CustomAHGui || manager.customAH.isRenderOverAuctionView()) { + event.setCanceled(true); + manager.customAH.drawScreen(event.mouseX, event.mouseY); + } + } + /** * Will draw the NEUOverlay over the inventory if focusInv == false. (z-translation of 300 is so that NEUOverlay * will draw over Items in the inventory (which render at a z value of about 250)) * @param event */ @SubscribeEvent - public void onGuiScreenDraw(GuiScreenEvent.DrawScreenEvent.Post event) { + public void onGuiScreenDrawPost(GuiScreenEvent.DrawScreenEvent.Post event) { if(event.gui instanceof GuiContainer && isOnSkyblock()) { if(!focusInv) { GL11.glTranslatef(0, 0, 300); @@ -489,6 +527,12 @@ public class NotEnoughUpdates { */ @SubscribeEvent public void onGuiScreenMouse(GuiScreenEvent.MouseInputEvent.Pre event) { + if(event.gui instanceof CustomAHGui || manager.customAH.isRenderOverAuctionView()) { + event.setCanceled(true); + manager.customAH.handleMouseInput(); + //overlay.mouseInput(); + return; + } if(event.gui instanceof GuiContainer && !(hoverInv && focusInv) && isOnSkyblock()) { if(overlay.mouseInput()) { event.setCanceled(true); @@ -505,6 +549,14 @@ public class NotEnoughUpdates { boolean started = false; @SubscribeEvent public void onGuiScreenKeyboard(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if(event.gui instanceof CustomAHGui || manager.customAH.isRenderOverAuctionView()) { + if(manager.customAH.keyboardInput()) { + event.setCanceled(true); + Minecraft.getMinecraft().dispatchKeypresses(); + } + return; + } + if(event.gui instanceof GuiContainer && isOnSkyblock()) { if(overlay.keyboardInput(focusInv)) { event.setCanceled(true); @@ -689,7 +741,7 @@ public class NotEnoughUpdates { } } if(!Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || !manager.config.dev.value) return; - if(event.toolTip.get(event.toolTip.size()-1).startsWith(EnumChatFormatting.DARK_GRAY + "NBT: ")) { + if(event.toolTip.size()>0&&event.toolTip.get(event.toolTip.size()-1).startsWith(EnumChatFormatting.DARK_GRAY + "NBT: ")) { event.toolTip.remove(event.toolTip.size()-1); StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java b/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java index c7d5e8ae..47f2da10 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java @@ -20,7 +20,7 @@ public class StreamerMode { long obfLobbyNum = (lobbyNum*9182739 + 11) % 500; char obfLobbyLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt((int)(obfLobbyNum%26)); - line = line.replaceAll("(mini|mega)([0-9]{1,3}[A-Z])", lobbyType+obfLobbyNum+obfLobbyLetter); + line = line.replaceAll("(mini|mega|m|M)([0-9]{1,3}[A-Z])", lobbyType+obfLobbyNum+obfLobbyLetter); } return line; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/Utils.java deleted file mode 100644 index f850b49d..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/Utils.java +++ /dev/null @@ -1,422 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import com.mojang.authlib.Agent; -import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; -import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication; -import io.github.moulberry.notenoughupdates.util.TexLoc; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Session; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import javax.swing.*; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.Proxy; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class Utils { - - private static boolean hasEffectOverride = false; - - public static ArrayList createList(T... values) { - ArrayList list = new ArrayList<>(); - for(T value : values)list.add(value); - return list; - } - - public static boolean getHasEffectOverride() { - return hasEffectOverride; - } - - public static void drawItemStackWithoutGlint(ItemStack stack, int x, int y) { - RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); - - RenderHelper.enableGUIStandardItemLighting(); - itemRender.zLevel = -145; //Negates the z-offset of the below method. - hasEffectOverride = true; - try { - itemRender.renderItemAndEffectIntoGUI(stack, x, y); - } catch(Exception e) {e.printStackTrace();} //Catch exceptions to ensure that hasEffectOverride is set back to false. - hasEffectOverride = false; - itemRender.zLevel = 0; - RenderHelper.disableStandardItemLighting(); - } - - public static void drawItemStack(ItemStack stack, int x, int y) { - RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); - - RenderHelper.enableGUIStandardItemLighting(); - itemRender.zLevel = -145; //Negates the z-offset of the below method. - itemRender.renderItemAndEffectIntoGUI(stack, x, y); - itemRender.zLevel = 0; - RenderHelper.disableStandardItemLighting(); - } - - public static Method getMethod(Class clazz, Class[] params, String... methodNames) { - for(String methodName : methodNames) { - try { - return clazz.getDeclaredMethod(methodName, params); - } catch(Exception e) {} - } - return null; - } - - public static Object getField(Class clazz, Object o, String... fieldNames) { - Field field = null; - for(String fieldName : fieldNames) { - try { - field = clazz.getDeclaredField(fieldName); - break; - } catch(Exception e) {} - } - if(field != null) { - field.setAccessible(true); - try { - return field.get(o); - } catch(IllegalAccessException e) { - } - } - return null; - } - - public static Slot getSlotUnderMouse(GuiContainer container) { - return (Slot) getField(GuiContainer.class, container, "theSlot", "field_147006_u"); - } - - public static void drawTexturedRect(float x, float y, float width, float height) { - drawTexturedRect(x, y, width, height, 0, 1, 0 , 1); - } - - public static void drawTexturedRect(float x, float y, float width, float height, int filter) { - drawTexturedRect(x, y, width, height, 0, 1, 0 , 1, filter); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { - drawTexturedRect(x, y, width, height, uMin, uMax, vMin , vMax, GL11.GL_LINEAR); - } - - public static String cleanColour(String in) { - return in.replaceAll("(?i)\\u00A7.", ""); - } - - public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { - GlStateManager.enableTexture2D(); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer - .pos(x, y+height, 0.0D) - .tex(uMin, vMax).endVertex(); - worldrenderer - .pos(x+width, y+height, 0.0D) - .tex(uMax, vMax).endVertex(); - worldrenderer - .pos(x+width, y, 0.0D) - .tex(uMax, vMin).endVertex(); - worldrenderer - .pos(x, y, 0.0D) - .tex(uMin, vMin).endVertex(); - tessellator.draw(); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); - - GlStateManager.disableBlend(); - } - - public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; - factor = Math.min(1, factor); - - drawStringScaled(str, fr, x, y, shadow, colour, factor); - } - - public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { - GlStateManager.scale(factor, factor, 1); - fr.drawString(str, x/factor, y/factor, colour, shadow); - GlStateManager.scale(1/factor, 1/factor, 1); - } - - public static void drawStringCenteredScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; - factor = Math.min(1, factor); - int newLen = Math.min(strLen, len); - - float fontHeight = 8*factor; - - drawStringScaled(str, fr, x-newLen/2, y-fontHeight/2, shadow, colour, factor); - } - - public static void drawStringCenteredScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; - float fontHeight = 8*factor; - - drawStringScaled(str, fr, x-len/2, y-fontHeight/2, shadow, colour, factor); - } - - public static void drawStringCenteredYScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { - int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; - float fontHeight = 8*factor; - - drawStringScaled(str, fr, x, y-fontHeight/2, shadow, colour, factor); - } - - public static int renderStringTrimWidth(String str, FontRenderer fr, boolean shadow, int x, int y, int len, int colour, int maxLines) { - return renderStringTrimWidth(str, fr, shadow, x, y, len, colour, maxLines, 1); - } - - public static int renderStringTrimWidth(String str, FontRenderer fr, boolean shadow, int x, int y, int len, int colour, int maxLines, float scale) { - len = (int)(len/scale); - - int yOff = 0; - String excess; - String trimmed = trimToWidth(str, len); - - String colourCodes = ""; - Pattern pattern = Pattern.compile("\\u00A7."); - Matcher matcher = pattern.matcher(trimmed); - while(matcher.find()) { - colourCodes += matcher.group(); - } - - boolean firstLine = true; - int trimmedCharacters = trimmed.length(); - int lines = 0; - while((lines++ textLines, final int mouseX, final int mouseY, final int screenWidth, final int screenHeight, final int maxTextWidth, FontRenderer font) { - if (!textLines.isEmpty()) - { - GlStateManager.disableRescaleNormal(); - RenderHelper.disableStandardItemLighting(); - GlStateManager.disableLighting(); - GlStateManager.disableDepth(); - int tooltipTextWidth = 0; - - for (String textLine : textLines) - { - int textLineWidth = font.getStringWidth(textLine); - - if (textLineWidth > tooltipTextWidth) - { - tooltipTextWidth = textLineWidth; - } - } - - boolean needsWrap = false; - - int titleLinesCount = 1; - int tooltipX = mouseX + 12; - if (tooltipX + tooltipTextWidth + 4 > screenWidth) - { - tooltipX = mouseX - 16 - tooltipTextWidth; - if (tooltipX < 4) // if the tooltip doesn't fit on the screen - { - if (mouseX > screenWidth / 2) - { - tooltipTextWidth = mouseX - 12 - 8; - } - else - { - tooltipTextWidth = screenWidth - 16 - mouseX; - } - needsWrap = true; - } - } - - if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) - { - tooltipTextWidth = maxTextWidth; - needsWrap = true; - } - - if (needsWrap) - { - int wrappedTooltipWidth = 0; - List wrappedTextLines = new ArrayList(); - for (int i = 0; i < textLines.size(); i++) - { - String textLine = textLines.get(i); - List wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); - if (i == 0) - { - titleLinesCount = wrappedLine.size(); - } - - for (String line : wrappedLine) - { - int lineWidth = font.getStringWidth(line); - if (lineWidth > wrappedTooltipWidth) - { - wrappedTooltipWidth = lineWidth; - } - wrappedTextLines.add(line); - } - } - tooltipTextWidth = wrappedTooltipWidth; - textLines = wrappedTextLines; - - if (mouseX > screenWidth / 2) - { - tooltipX = mouseX - 16 - tooltipTextWidth; - } - else - { - tooltipX = mouseX + 12; - } - } - - int tooltipY = mouseY - 12; - int tooltipHeight = 8; - - if (textLines.size() > 1) - { - tooltipHeight += (textLines.size() - 1) * 10; - if (textLines.size() > titleLinesCount) { - tooltipHeight += 2; // gap between title lines and next lines - } - } - - if (tooltipY + tooltipHeight + 6 > screenHeight) - { - tooltipY = screenHeight - tooltipHeight - 6; - } - - final int zLevel = 300; - final int backgroundColor = 0xF0100010; - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - final int borderColorStart = 0x505000FF; - final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); - drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); - drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); - - for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) - { - String line = textLines.get(lineNumber); - font.drawStringWithShadow(line, (float)tooltipX, (float)tooltipY, -1); - - if (lineNumber + 1 == titleLinesCount) - { - tooltipY += 2; - } - - tooltipY += 10; - } - - GlStateManager.enableLighting(); - GlStateManager.enableDepth(); - RenderHelper.enableStandardItemLighting(); - GlStateManager.enableRescaleNormal(); - } - GlStateManager.disableLighting(); - } - - public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) { - float startAlpha = (float)(startColor >> 24 & 255) / 255.0F; - float startRed = (float)(startColor >> 16 & 255) / 255.0F; - float startGreen = (float)(startColor >> 8 & 255) / 255.0F; - float startBlue = (float)(startColor & 255) / 255.0F; - float endAlpha = (float)(endColor >> 24 & 255) / 255.0F; - float endRed = (float)(endColor >> 16 & 255) / 255.0F; - float endGreen = (float)(endColor >> 8 & 255) / 255.0F; - float endBlue = (float)(endColor & 255) / 255.0F; - - GlStateManager.disableTexture2D(); - GlStateManager.enableBlend(); - GlStateManager.disableAlpha(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.shadeModel(7425); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); - worldrenderer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); - worldrenderer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); - worldrenderer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); - worldrenderer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); - tessellator.draw(); - - GlStateManager.shadeModel(7424); - GlStateManager.disableBlend(); - GlStateManager.enableAlpha(); - GlStateManager.enableTexture2D(); - } - -} 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 1c21e342..707e392b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java @@ -5,7 +5,7 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NEUResourceManager; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -14,12 +14,10 @@ import net.minecraft.client.shader.Shader; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Matrix4f; -import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import java.awt.*; -import java.text.NumberFormat; import java.util.*; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -37,6 +35,9 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { private int buttonHover = -1; + private int previousAcquiredCount = 0; + private int previousScroll = 0; + private static final int FILTER_ALL = 0; private static final int FILTER_WEAPON = 1; private static final int FILTER_ARMOR = 2; @@ -243,6 +244,12 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { return projMatrix; } + public int getCurrentAcquiredCount() { + if(getAcquiredItems() == null) return 0; + if(!getAcquiredItems().containsKey(manager.currentProfile)) return 0; + return getAcquiredItems().get(manager.currentProfile).size(); + } + private void renderCollectionLog(Color fg, int width, int height, int left, int right, int top, int bottom) { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -261,8 +268,14 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { scaledresolution.getScaleFactor()); itemFramebufferGrayscale = checkFramebufferSizes(itemFramebufferGrayscale, width, height, scaledresolution.getScaleFactor()); - renderItemsToImage(itemFramebuffer, fg, left+5, right, top+1, bottom); - renderItemBGToImage(itemBGFramebuffer, fg, left+5, right, top+1, bottom); + + if(!manager.config.cacheRenderedItempane.value || previousAcquiredCount != getCurrentAcquiredCount() || + previousScroll != scrollHeight.getValue()) { + renderItemsToImage(itemFramebuffer, fg, left+5, right, top+1, bottom); + renderItemBGToImage(itemBGFramebuffer, fg, left+5, right, top+1, bottom); + } + previousAcquiredCount = getCurrentAcquiredCount(); + previousScroll = scrollHeight.getValue(); Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); renderFromImage(itemBGFramebuffer, width, height, left, right, top, bottom); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java index 61344237..f28dae0b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java @@ -1,29 +1,17 @@ package io.github.moulberry.notenoughupdates.infopanes; -import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; -import io.github.moulberry.notenoughupdates.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; -import java.awt.*; -import java.io.*; -import java.nio.charset.StandardCharsets; import java.util.*; -import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; public class DevInfoPane extends TextInfoPane { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java index 152d0628..b5d20a97 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java @@ -2,22 +2,17 @@ package io.github.moulberry.notenoughupdates.infopanes; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; -import io.github.moulberry.notenoughupdates.Utils; -import io.github.moulberry.notenoughupdates.itemeditor.GuiElementButton; +import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; -import org.lwjgl.opengl.GL11; import static io.github.moulberry.notenoughupdates.GuiTextures.*; import static io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField.*; import java.awt.*; -import java.util.ArrayList; -import java.util.List; public class FlipperInfoPane extends InfoPane { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java index ddf8d962..3e9cdb3f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java @@ -11,7 +11,7 @@ import info.bliki.wiki.tags.IgnoreTag; import io.github.moulberry.notenoughupdates.AllowEmptyHTMLTag; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; @@ -26,7 +26,6 @@ import java.awt.image.BufferedImage; import java.io.*; import java.nio.charset.CharsetEncoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -87,10 +86,11 @@ public class HTMLInfoPane extends TextInfoPane { /** * Takes a wiki url, uses NEUManager#getWebFile to download the web file and passed that in to #createFromWiki */ - public static HTMLInfoPane createFromWikiUrl(NEUOverlay overlay, NEUManager manager, String name, String wikiUrl) { + public static HTMLInfoPane createFromWikiUrl(NEUOverlay overlay, NEUManager manager, String name, + String wikiUrl) { File f = manager.getWebFile(wikiUrl); if(f == null) { - return new HTMLInfoPane(overlay, manager, "error", "Failed to load wiki url: "+ wikiUrl); + return new HTMLInfoPane(overlay, manager, "error", "error","Failed to load wiki url: "+ wikiUrl); }; StringBuilder sb = new StringBuilder(); @@ -101,9 +101,9 @@ public class HTMLInfoPane extends TextInfoPane { sb.append(l).append("\n"); } } catch(IOException e) { - return new HTMLInfoPane(overlay, manager, "error", "Failed to load wiki url: "+ wikiUrl); + return new HTMLInfoPane(overlay, manager, "error", "error","Failed to load wiki url: "+ wikiUrl); } - return createFromWiki(overlay, manager, name, sb.toString()); + return createFromWiki(overlay, manager, name, f.getName(), sb.toString()); } /** @@ -112,7 +112,8 @@ public class HTMLInfoPane extends TextInfoPane { * a more permanent solution that can be abstracted to work with arbitrary wiki codes (eg. moulberry.github.io/ * files/neu_help.html). */ - public static HTMLInfoPane createFromWiki(NEUOverlay overlay, NEUManager manager, String name, String wiki) { + public static HTMLInfoPane createFromWiki(NEUOverlay overlay, NEUManager manager, String name, String filename, + String wiki) { String[] split = wiki.split(""); wiki = split[split.length - 1]; //Remove everything before infobox wiki = wiki.split("")[0]; //Remove navbox @@ -126,13 +127,13 @@ public class HTMLInfoPane extends TextInfoPane { try { html = wikiModel.render(wiki); } catch(IOException e) { - return new HTMLInfoPane(overlay, manager, "error", "Could not render wiki."); + return new HTMLInfoPane(overlay, manager, "error", "error", "Could not render wiki."); } try (PrintWriter out = new PrintWriter(new File(manager.configLocation, "debug/html.txt"))) { out.println(html); } catch (IOException e) { } - return new HTMLInfoPane(overlay, manager, name, html); + return new HTMLInfoPane(overlay, manager, name, filename, html); } /** @@ -140,14 +141,14 @@ public class HTMLInfoPane extends TextInfoPane { * generation is done asynchronously as sometimes it can take up to 10 seconds for more * complex webpages. */ - public HTMLInfoPane(NEUOverlay overlay, NEUManager manager, String name, String html) { + public HTMLInfoPane(NEUOverlay overlay, NEUManager manager, String name, String filename, String html) { super(overlay, manager, name, ""); this.title = name; File cssFile = new File(manager.configLocation, "wikia.css"); File wkHtmlToImage = new File(manager.configLocation, "wkhtmltox/bin/wkhtmltoimage"); File input = new File(manager.configLocation, "tmp/input.html"); - String outputFileName = name.replaceAll("(?i)\\u00A7.", "") + String outputFileName = filename.replaceAll("(?i)\\u00A7.", "") .replaceAll("[^a-zA-Z0-9_\\-]", "_"); File output = new File(manager.configLocation, "tmp/"+ outputFileName+".png"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java index e847a01c..5cc7211e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java @@ -4,29 +4,21 @@ 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.Utils; +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.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; import java.awt.*; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.*; import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; public class QOLInfoPane extends ScrollableInfoPane { 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 090410dd..147c006c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java @@ -2,7 +2,7 @@ package io.github.moulberry.notenoughupdates.infopanes; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import io.github.moulberry.notenoughupdates.options.Options; import net.minecraft.client.Minecraft; @@ -12,7 +12,6 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.EnumChatFormatting; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; import java.awt.*; import java.util.ArrayList; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java index 1072ca4f..72a9e42b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java @@ -2,7 +2,7 @@ package io.github.moulberry.notenoughupdates.infopanes; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java index 9bcc2891..3c939589 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java @@ -1,16 +1,13 @@ package io.github.moulberry.notenoughupdates.itemeditor; -import com.google.common.base.Predicate; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; import org.apache.commons.lang3.StringUtils; -import javax.annotation.Nullable; import java.awt.*; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java index 5591fcb9..1d67b8c4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java @@ -4,7 +4,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.util.LerpingInteger; import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; import net.minecraft.client.renderer.GlStateManager; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java index 524c9ffb..51c85b19 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java @@ -1,15 +1,10 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.Utils; import net.minecraft.client.renderer.InventoryEffectRenderer; -import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin({InventoryEffectRenderer.class}) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java index 4a713218..123c8cb9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java @@ -1,6 +1,6 @@ package io.github.moulberry.notenoughupdates.mixins; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; 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 fdda8c66..14cb2b26 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java @@ -1,13 +1,10 @@ package io.github.moulberry.notenoughupdates.options; -import com.google.common.collect.Lists; import com.google.gson.*; -import com.google.gson.annotations.Expose; -import io.github.moulberry.notenoughupdates.Utils; +import io.github.moulberry.notenoughupdates.util.Utils; import java.io.*; import java.lang.reflect.Field; -import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; @@ -153,12 +150,12 @@ public class Options { private ArrayList createDefaultQuickCommands() { ArrayList arr = new ArrayList<>(); - arr.add("/warp home:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0="); - arr.add("/warp hub:eyJ0aW1lc3RhbXAiOjE1NTkyMTU0MTY5MDksInByb2ZpbGVJZCI6IjQxZDNhYmMyZDc0OTQwMGM5MDkwZDU0MzRkMDM4MzFiIiwicHJvZmlsZU5hbWUiOiJNZWdha2xvb24iLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2Q3Y2M2Njg3NDIzZDA1NzBkNTU2YWM1M2UwNjc2Y2I1NjNiYmRkOTcxN2NkODI2OWJkZWJlZDZmNmQ0ZTdiZjgifX19"); - arr.add("/craft:CRAFTING_TABLE"); - arr.add("/enderchest:ENDER_CHEST"); - arr.add("/wardrobe:LEATHER_CHESTPLATE"); - arr.add("/collectionlog:MAP"); + arr.add("/warp home:Warp Home:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0="); + arr.add("/warp hub:Warp Hub:eyJ0aW1lc3RhbXAiOjE1NTkyMTU0MTY5MDksInByb2ZpbGVJZCI6IjQxZDNhYmMyZDc0OTQwMGM5MDkwZDU0MzRkMDM4MzFiIiwicHJvZmlsZU5hbWUiOiJNZWdha2xvb24iLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2Q3Y2M2Njg3NDIzZDA1NzBkNTU2YWM1M2UwNjc2Y2I1NjNiYmRkOTcxN2NkODI2OWJkZWJlZDZmNmQ0ZTdiZjgifX19"); + arr.add("/craft:Crafting Table:CRAFTING_TABLE"); + arr.add("/enderchest:Ender Chest:ENDER_CHEST"); + arr.add("/wardrobe:Wardrobe:LEATHER_CHESTPLATE"); + arr.add("neucl:Collection Log:MAP"); return arr; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java index 7e8e8a14..84d970d5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java @@ -23,10 +23,10 @@ public class HypixelApi { */ private Gson gson = new Gson(); - private ExecutorService es = Executors.newSingleThreadExecutor(); + private ExecutorService es = Executors.newCachedThreadPool(); public void getHypixelApiAsync(String apiKey, String method, HashMap args, Consumer consumer) { - getHypixelApiAsync(generateApiUrl(apiKey, method, args), consumer); + getHypixelApiAsync(generateApiUrl(apiKey.trim(), method, args), consumer); } public void getHypixelApiAsync(String urlS, Consumer consumer) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java new file mode 100644 index 00000000..0247c01e --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -0,0 +1,435 @@ +package io.github.moulberry.notenoughupdates.util; + +import com.mojang.authlib.Agent; +import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; +import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication; +import io.github.moulberry.notenoughupdates.util.TexLoc; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Session; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import javax.swing.*; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.Proxy; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Utils { + + private static boolean hasEffectOverride = false; + + public static ArrayList createList(T... values) { + ArrayList list = new ArrayList<>(); + for(T value : values)list.add(value); + return list; + } + + public static boolean getHasEffectOverride() { + return hasEffectOverride; + } + + public static void drawItemStackWithoutGlint(ItemStack stack, int x, int y) { + RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); + + RenderHelper.enableGUIStandardItemLighting(); + itemRender.zLevel = -145; //Negates the z-offset of the below method. + hasEffectOverride = true; + try { + itemRender.renderItemAndEffectIntoGUI(stack, x, y); + } catch(Exception e) {e.printStackTrace();} //Catch exceptions to ensure that hasEffectOverride is set back to false. + hasEffectOverride = false; + itemRender.zLevel = 0; + RenderHelper.disableStandardItemLighting(); + } + + public static void drawItemStack(ItemStack stack, int x, int y) { + if(stack == null)return; + + RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); + + RenderHelper.enableGUIStandardItemLighting(); + itemRender.zLevel = -145; //Negates the z-offset of the below method. + itemRender.renderItemAndEffectIntoGUI(stack, x, y); + itemRender.zLevel = 0; + RenderHelper.disableStandardItemLighting(); + } + + public static Method getMethod(Class clazz, Class[] params, String... methodNames) { + for(String methodName : methodNames) { + try { + return clazz.getDeclaredMethod(methodName, params); + } catch(Exception e) {} + } + return null; + } + + public static Object getField(Class clazz, Object o, String... fieldNames) { + Field field = null; + for(String fieldName : fieldNames) { + try { + field = clazz.getDeclaredField(fieldName); + break; + } catch(Exception e) {} + } + if(field != null) { + field.setAccessible(true); + try { + return field.get(o); + } catch(IllegalAccessException e) { + } + } + return null; + } + + public static Slot getSlotUnderMouse(GuiContainer container) { + return (Slot) getField(GuiContainer.class, container, "theSlot", "field_147006_u"); + } + + public static void drawTexturedRect(float x, float y, float width, float height) { + drawTexturedRect(x, y, width, height, 0, 1, 0 , 1); + } + + public static void drawTexturedRect(float x, float y, float width, float height, int filter) { + drawTexturedRect(x, y, width, height, 0, 1, 0 , 1, filter); + } + + public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { + drawTexturedRect(x, y, width, height, uMin, uMax, vMin , vMax, GL11.GL_LINEAR); + } + + public static String cleanColour(String in) { + return in.replaceAll("(?i)\\u00A7.", ""); + } + + public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { + GlStateManager.enableTexture2D(); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldrenderer + .pos(x, y+height, 0.0D) + .tex(uMin, vMax).endVertex(); + worldrenderer + .pos(x+width, y+height, 0.0D) + .tex(uMax, vMax).endVertex(); + worldrenderer + .pos(x+width, y, 0.0D) + .tex(uMax, vMin).endVertex(); + worldrenderer + .pos(x, y, 0.0D) + .tex(uMin, vMin).endVertex(); + tessellator.draw(); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GlStateManager.disableBlend(); + } + + public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { + int strLen = fr.getStringWidth(str); + float factor = len/(float)strLen; + factor = Math.min(1, factor); + + drawStringScaled(str, fr, x, y, shadow, colour, factor); + } + + public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { + int strLen = fr.getStringWidth(str); + + float x2 = x - strLen/2f; + float y2 = y - fr.FONT_HEIGHT/2f; + + GL11.glTranslatef(x2, y2, 0); + fr.drawString(str, 0, 0, colour, shadow); + GL11.glTranslatef(-x2, -y2, 0); + } + + public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { + GlStateManager.scale(factor, factor, 1); + fr.drawString(str, x/factor, y/factor, colour, shadow); + GlStateManager.scale(1/factor, 1/factor, 1); + } + + public static void drawStringCenteredScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { + int strLen = fr.getStringWidth(str); + float factor = len/(float)strLen; + factor = Math.min(1, factor); + int newLen = Math.min(strLen, len); + + float fontHeight = 8*factor; + + drawStringScaled(str, fr, x-newLen/2, y-fontHeight/2, shadow, colour, factor); + } + + public static void drawStringCenteredScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { + int strLen = fr.getStringWidth(str); + float factor = len/(float)strLen; + float fontHeight = 8*factor; + + drawStringScaled(str, fr, x-len/2, y-fontHeight/2, shadow, colour, factor); + } + + public static void drawStringCenteredYScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { + int strLen = fr.getStringWidth(str); + float factor = len/(float)strLen; + float fontHeight = 8*factor; + + drawStringScaled(str, fr, x, y-fontHeight/2, shadow, colour, factor); + } + + public static int renderStringTrimWidth(String str, FontRenderer fr, boolean shadow, int x, int y, int len, int colour, int maxLines) { + return renderStringTrimWidth(str, fr, shadow, x, y, len, colour, maxLines, 1); + } + + public static int renderStringTrimWidth(String str, FontRenderer fr, boolean shadow, int x, int y, int len, int colour, int maxLines, float scale) { + len = (int)(len/scale); + + int yOff = 0; + String excess; + String trimmed = trimToWidth(str, len); + + String colourCodes = ""; + Pattern pattern = Pattern.compile("\\u00A7."); + Matcher matcher = pattern.matcher(trimmed); + while(matcher.find()) { + colourCodes += matcher.group(); + } + + boolean firstLine = true; + int trimmedCharacters = trimmed.length(); + int lines = 0; + while((lines++ textLines, final int mouseX, final int mouseY, final int screenWidth, final int screenHeight, final int maxTextWidth, FontRenderer font) { + if (!textLines.isEmpty()) + { + GlStateManager.disableRescaleNormal(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + int tooltipTextWidth = 0; + + for (String textLine : textLines) + { + int textLineWidth = font.getStringWidth(textLine); + + if (textLineWidth > tooltipTextWidth) + { + tooltipTextWidth = textLineWidth; + } + } + + boolean needsWrap = false; + + int titleLinesCount = 1; + int tooltipX = mouseX + 12; + if (tooltipX + tooltipTextWidth + 4 > screenWidth) + { + tooltipX = mouseX - 16 - tooltipTextWidth; + if (tooltipX < 4) // if the tooltip doesn't fit on the screen + { + if (mouseX > screenWidth / 2) + { + tooltipTextWidth = mouseX - 12 - 8; + } + else + { + tooltipTextWidth = screenWidth - 16 - mouseX; + } + needsWrap = true; + } + } + + if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) + { + tooltipTextWidth = maxTextWidth; + needsWrap = true; + } + + if (needsWrap) + { + int wrappedTooltipWidth = 0; + List wrappedTextLines = new ArrayList(); + for (int i = 0; i < textLines.size(); i++) + { + String textLine = textLines.get(i); + List wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); + if (i == 0) + { + titleLinesCount = wrappedLine.size(); + } + + for (String line : wrappedLine) + { + int lineWidth = font.getStringWidth(line); + if (lineWidth > wrappedTooltipWidth) + { + wrappedTooltipWidth = lineWidth; + } + wrappedTextLines.add(line); + } + } + tooltipTextWidth = wrappedTooltipWidth; + textLines = wrappedTextLines; + + if (mouseX > screenWidth / 2) + { + tooltipX = mouseX - 16 - tooltipTextWidth; + } + else + { + tooltipX = mouseX + 12; + } + } + + int tooltipY = mouseY - 12; + int tooltipHeight = 8; + + if (textLines.size() > 1) + { + tooltipHeight += (textLines.size() - 1) * 10; + if (textLines.size() > titleLinesCount) { + tooltipHeight += 2; // gap between title lines and next lines + } + } + + if (tooltipY + tooltipHeight + 6 > screenHeight) + { + tooltipY = screenHeight - tooltipHeight - 6; + } + + final int zLevel = 300; + final int backgroundColor = 0xF0100010; + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + final int borderColorStart = 0x505000FF; + final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); + drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); + drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); + drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); + + for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) + { + String line = textLines.get(lineNumber); + font.drawStringWithShadow(line, (float)tooltipX, (float)tooltipY, -1); + + if (lineNumber + 1 == titleLinesCount) + { + tooltipY += 2; + } + + tooltipY += 10; + } + + GlStateManager.enableLighting(); + GlStateManager.enableDepth(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.enableRescaleNormal(); + } + GlStateManager.disableLighting(); + } + + public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) { + float startAlpha = (float)(startColor >> 24 & 255) / 255.0F; + float startRed = (float)(startColor >> 16 & 255) / 255.0F; + float startGreen = (float)(startColor >> 8 & 255) / 255.0F; + float startBlue = (float)(startColor & 255) / 255.0F; + float endAlpha = (float)(endColor >> 24 & 255) / 255.0F; + float endRed = (float)(endColor >> 16 & 255) / 255.0F; + float endGreen = (float)(endColor >> 8 & 255) / 255.0F; + float endBlue = (float)(endColor & 255) / 255.0F; + + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.shadeModel(7425); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + worldrenderer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + worldrenderer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); + worldrenderer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); + tessellator.draw(); + + GlStateManager.shadeModel(7424); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + } + +} diff --git a/src/main/resources/assets/notenoughupdates/ah_item_holder.png b/src/main/resources/assets/notenoughupdates/ah_item_holder.png deleted file mode 100644 index ed396f25..00000000 Binary files a/src/main/resources/assets/notenoughupdates/ah_item_holder.png and /dev/null differ diff --git a/src/main/resources/assets/notenoughupdates/ah_item_tab.png b/src/main/resources/assets/notenoughupdates/ah_item_tab.png deleted file mode 100644 index c307fa31..00000000 Binary files a/src/main/resources/assets/notenoughupdates/ah_item_tab.png and /dev/null differ diff --git a/src/main/resources/assets/notenoughupdates/auction_price.png b/src/main/resources/assets/notenoughupdates/auction_price.png new file mode 100644 index 00000000..fd211217 Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/auction_price.png differ diff --git a/src/main/resources/assets/notenoughupdates/auction_view.png b/src/main/resources/assets/notenoughupdates/auction_view.png new file mode 100644 index 00000000..1f70198c Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/auction_view.png differ diff --git a/src/main/resources/assets/notenoughupdates/auction_view_buttons.png b/src/main/resources/assets/notenoughupdates/auction_view_buttons.png new file mode 100644 index 00000000..a76c02fa Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/auction_view_buttons.png differ diff --git a/src/main/resources/assets/notenoughupdates/item_edit.png b/src/main/resources/assets/notenoughupdates/item_edit.png deleted file mode 100644 index 6ab71631..00000000 Binary files a/src/main/resources/assets/notenoughupdates/item_edit.png and /dev/null differ -- cgit