From 79894d22b49f943bcbedb22b9d515eb3db622886 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sun, 30 Aug 2020 02:51:50 +1000 Subject: 1.2.4 --- .../notenoughupdates/CustomItemEffects.java | 3 +- .../notenoughupdates/NEUEventListener.java | 6 +- .../moulberry/notenoughupdates/NEUManager.java | 2 - .../notenoughupdates/NotEnoughUpdates.java | 13 +- .../moulberry/notenoughupdates/SBAIntegration.java | 16 +- .../moulberry/notenoughupdates/TradeWindow.java | 638 ++++++++++++++++++++- .../infopanes/SettingsInfoPane.java | 2 +- .../notenoughupdates/options/Options.java | 20 +- 8 files changed, 653 insertions(+), 47 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java index fe3c7542..9d3c1c2f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java @@ -93,7 +93,8 @@ public class CustomItemEffects { @SubscribeEvent public void onPlayerInteract(PlayerInteractEvent event) { - if(NotEnoughUpdates.INSTANCE.manager.config.smoothAoteMillis.value <= 0) return; + if(NotEnoughUpdates.INSTANCE.manager.config.smoothAoteMillis.value <= 0 + || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) return; if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 84094642..fb6348ee 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -777,11 +777,11 @@ public class NEUEventListener { event.setCanceled(true); } } else { - if(TradeWindow.keyboardInput()) { + TradeWindow.keyboardInput(); + if(Keyboard.getEventKey() != Keyboard.KEY_ESCAPE) { event.setCanceled(true); Minecraft.getMinecraft().dispatchKeypresses(); - } else if(neu.overlay.keyboardInput(focusInv)) { - event.setCanceled(true); + neu.overlay.keyboardInput(focusInv); } } return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index a7303ca4..d5dd1184 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -812,8 +812,6 @@ public class NEUManager { String[] info = new String[0]; String clickcommand = ""; - - JsonObject item = new JsonObject(); item.addProperty("internalname", internalname); item.addProperty("itemid", itemid); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 597beca2..ab0de3cb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -220,16 +220,17 @@ public class NotEnoughUpdates { ScheduledExecutorService peekCommandExecutorService = null; SimpleCommand peekCommand = new SimpleCommand("peek", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { + String name; if(args.length == 0) { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED+"[PEEK] Usage: /peek (username)")); - return; + name = Minecraft.getMinecraft().thePlayer.getName(); + } else { + name = args[0]; } int id = new Random().nextInt(Integer.MAX_VALUE/2)+Integer.MAX_VALUE/2; Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( EnumChatFormatting.YELLOW+"[PEEK] Getting player information..."), id); - profileViewer.getProfileByName(args[0], profile -> { + profileViewer.getProfileByName(name, profile -> { if (profile == null) { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( EnumChatFormatting.RED+"[PEEK] Unknown player or api is down."), id); @@ -264,14 +265,14 @@ public class NotEnoughUpdates { if(profileInfo != null) { float overallScore = 0; - boolean isMe = args[0].equalsIgnoreCase("moulberry"); + boolean isMe = name.equalsIgnoreCase("moulberry"); PlayerStats.Stats stats = profile.getStats(null); JsonObject skill = profile.getSkillInfo(null); Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText(EnumChatFormatting.GREEN+" "+ EnumChatFormatting.STRIKETHROUGH+"-=-" +EnumChatFormatting.RESET+EnumChatFormatting.GREEN+" "+ - Utils.getElementAsString(profile.getHypixelProfile().get("displayname"), args[0]) + "'s Info " + + Utils.getElementAsString(profile.getHypixelProfile().get("displayname"), name) + "'s Info " + EnumChatFormatting.STRIKETHROUGH+"-=-"), id); if(skill == null) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java b/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java index 502792df..2a19b16e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java @@ -182,13 +182,17 @@ public class SBAIntegration { int width = scaledResolution.getScaledWidth(); int height = scaledResolution.getScaledHeight(); - GuiContainer container = new GuiContainer(null) { - protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { - } - }; - container.setWorldAndResolution(Minecraft.getMinecraft(), width, height); + if(Minecraft.getMinecraft().currentScreen instanceof GuiContainer) { + guiContainerHook_drawBackpacks.invoke(null, Minecraft.getMinecraft().currentScreen, mouseX, mouseY, fontRendererObj); + } else { + GuiContainer container = new GuiContainer(null) { + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + } + }; + container.setWorldAndResolution(Minecraft.getMinecraft(), width, height); - guiContainerHook_drawBackpacks.invoke(null, container, mouseX, mouseY, fontRendererObj); + guiContainerHook_drawBackpacks.invoke(null, container, mouseX, mouseY, fontRendererObj); + } } catch(Exception e) { return false; } return true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java b/src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java index b95acc09..a046f939 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java @@ -1,5 +1,6 @@ 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; @@ -13,16 +14,25 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; +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.awt.*; +import java.io.ByteArrayInputStream; +import java.text.NumberFormat; +import java.util.*; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class TradeWindow { @@ -33,8 +43,21 @@ public class TradeWindow { private static int guiLeft; private static int guiTop; + private static long lastTradeMillis = -1; + + private static final long CHANGE_EXCLAM_MILLIS = 5000; + + private static Integer[] ourTradeIndexes = new Integer[16]; + private static Integer[] theirTradeIndexes = new Integer[16]; + private static String[] theirTradeOld = new String[16]; + private static Long[] theirTradeChangesMillis = new Long[16]; + + private static ItemStack lastBackpack; + private static int lastBackpackX; + private static int lastBackpackY; + public static boolean tradeWindowActive() { - if(Keyboard.isKeyDown(Keyboard.KEY_J)) return false; + if(!NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value) return false; GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; if(guiScreen instanceof GuiChest) { @@ -45,11 +68,86 @@ public class TradeWindow { return true; } } + + lastTradeMillis = -1; + ourTradeIndexes = new Integer[16]; + theirTradeIndexes = new Integer[16]; + theirTradeOld = new String[16]; + theirTradeChangesMillis = new Long[16]; + return false; } private static TexLoc tl = new TexLoc(0, 0, Keyboard.KEY_M); + private static void drawStringShadow(String str, float x, float y, int len) { + for(int xOff=-2; xOff<=2; xOff++) { + for(int yOff=-2; yOff<=2; yOff++) { + if(Math.abs(xOff) != Math.abs(yOff)) { + Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(str), + Minecraft.getMinecraft().fontRendererObj, + x+xOff/2f, y+yOff/2f, false, len, + new Color(20, 20, 20, 100/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); + } + } + } + + Utils.drawStringCenteredScaledMaxWidth(str, + Minecraft.getMinecraft().fontRendererObj, + x, y, false, len, + new Color(64, 64, 64, 255).getRGB()); + } + + private static int getBackpackValue(ItemStack stack) { + int price = 0; + + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + byte[] bytes = null; + for (String key : ea.getKeySet()) { + if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { + bytes = ea.getByteArray(key); + break; + } + } + if(bytes != null) { + try { + NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); + NBTTagList items = contents_nbt.getTagList("i", 10); + for(int k=0; k 0) { + NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag"); + String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(nbt); + if(internalname2 != null) { + JsonObject info2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname2); + + int pricePer2 = -1; + if(info2 != null && info2.has("price") && info2.has("count")) { + int auctionPricePer2 = (int)(info2.get("price").getAsFloat() / info2.get("count").getAsFloat()); + + pricePer2 = auctionPricePer2; + } else { + JsonObject bazaarInfo2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname2); + if(bazaarInfo2 != null && bazaarInfo2.has("avg_buy")) { + pricePer2 = (int)bazaarInfo2.get("avg_buy").getAsFloat(); + } + } + if(pricePer2 > 0) { + int count2 = items.getCompoundTagAt(k).getByte("Count"); + System.out.println("adding" + pricePer2*count2); + price += pricePer2 * count2; + } + } + } + } + } catch(Exception e) { } + } + } + return price; + } + public static void render(int mouseX, int mouseY) { if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; @@ -63,15 +161,162 @@ public class TradeWindow { guiTop = (scaledResolution.getScaledHeight()-ySize)/2; List tooltipToDisplay = null; + ItemStack stackToRender = null; + int tooltipLen = -1; tl.handleKeyboardInput(); + //Set index mappings + //Our slots + TreeMap> ourTradeMap = new TreeMap<>(); + for(int i=0; i<16; i++) { + ourTradeIndexes[i] = -1; + + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname == null) { + List list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + list.add(containerIndex); + } else { + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + int price = -1; + if(info != null && info.has("price") && info.has("count")) { + int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); + + price = auctionPricePer * stack.stackSize; + } else { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { + price = (int)bazaarInfo.get("avg_buy").getAsFloat() * stack.stackSize; + } + } + + price += getBackpackValue(stack); + + List list = ourTradeMap.computeIfAbsent(price, k -> new ArrayList<>()); + list.add(containerIndex); + } + } + long currentTime = System.currentTimeMillis(); + List theirTradeCurrent = new ArrayList<>(); + TreeMap> theirTradeMap = new TreeMap<>(); + for(int i=0; i<16; i++) { + theirTradeIndexes[i] = -1; + if(theirTradeChangesMillis[i] == null || currentTime - theirTradeChangesMillis[i] > CHANGE_EXCLAM_MILLIS) { + theirTradeChangesMillis[i] = -1L; + } + + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x+5; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + NBTTagCompound tag = stack.getTagCompound(); + String uuid = null; + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + if (ea.hasKey("uuid", 8)) { + uuid = ea.getString("uuid"); + } else { + uuid = stack.getDisplayName(); + } + } else { + uuid = stack.getDisplayName(); + } + if(uuid != null) theirTradeCurrent.add(uuid); + + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname == null) { + List list = theirTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + list.add(containerIndex); + } else { + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + int price = -1; + if(info != null && info.has("price") && info.has("count")) { + int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); + + price = auctionPricePer * stack.stackSize; + } else { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { + price = (int)bazaarInfo.get("avg_buy").getAsFloat() * stack.stackSize; + } + } + + price += getBackpackValue(stack); + + List list = theirTradeMap.computeIfAbsent(price, k -> new ArrayList<>()); + list.add(containerIndex); + } + } + int ourTradeIndex = 0; + for(Map.Entry> entry : ourTradeMap.descendingMap().entrySet()) { + for(Integer index : entry.getValue()) { + ourTradeIndexes[ourTradeIndex++] = index; + } + } + + //Their slots + int maxMissing = 16-theirTradeCurrent.size(); + int j=0; + for(int i=0; i<16; i++) { + while(j <= 15 && (j-i= 0) j++; + j = Math.min(15, j); + + String oldUUID = theirTradeOld[i]; + if(oldUUID != null && !theirTradeCurrent.contains(oldUUID)) { + theirTradeChangesMillis[j] = System.currentTimeMillis(); + } + j++; + } + + for(int i=0; i<16; i++) { + theirTradeOld[i] = null; + } + int theirTradeIndex = 0; + j=0; + for(Map.Entry> entry : theirTradeMap.descendingMap().entrySet()) { + for(Integer index : entry.getValue()) { + while(j <= 15 && (j-theirTradeIndex= 0) j++; + j = Math.min(15, j); + + theirTradeIndexes[j] = index; + + ItemStack stack = chest.inventorySlots.getInventory().get(index); + if(stack == null) continue; + + NBTTagCompound tag = stack.getTagCompound(); + String uuid = null; + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + if (ea.hasKey("uuid", 8)) { + uuid = ea.getString("uuid"); + } else { + uuid = stack.getDisplayName(); + } + } else { + uuid = stack.getDisplayName(); + } + if(uuid != null) theirTradeCurrent.add(uuid); + theirTradeOld[theirTradeIndex] = uuid; + + j++; + theirTradeIndex++; + } + } + + GlStateManager.color(1, 1, 1, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(location); Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, 176/256f, 0, 204/256f, GL11.GL_NEAREST); - - Utils.drawTexturedRect(guiLeft+42, guiTop+92, 40, 14, - 0, 40/256f, ySize/256f, (ySize+14)/256f, GL11.GL_NEAREST); - Utils.drawStringCentered("Confirm", Minecraft.getMinecraft().fontRendererObj, guiLeft+64, guiTop+96, - false, 4210752); Utils.drawStringF(new ChatComponentTranslation("container.inventory").getUnformattedText(), Minecraft.getMinecraft().fontRendererObj, guiLeft+8, guiTop+111, false, 4210752); @@ -79,7 +324,8 @@ public class TradeWindow { guiTop+5, false, 4210752); String[] split = containerName.split(" "); if(split.length >= 1) { - Utils.drawStringF(split[split.length-1], Minecraft.getMinecraft().fontRendererObj, guiLeft+109, + Utils.drawStringF(split[split.length-1], Minecraft.getMinecraft().fontRendererObj, + guiLeft+167-Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length-1]), guiTop+5, false, 4210752); } @@ -93,7 +339,7 @@ public class TradeWindow { if(mouseX > guiLeft+x-1 && mouseX < guiLeft+x+18) { if(mouseY > guiTop+y-1 && mouseY < guiTop+y+18) { - if(stack != null) tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, true); + if(stack != null) stackToRender = stack; GlStateManager.disableLighting(); GlStateManager.disableDepth(); @@ -112,15 +358,18 @@ public class TradeWindow { for(int i=0; i<16; i++) { int x = i % 4; int y = i / 4; - int containerIndex = y*9+x; - ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + int containerIndex = ourTradeIndexes[i]; - Utils.drawItemStack(stack, guiLeft+10+x*18, guiTop+15+y*18); + ItemStack stack = null; + if(containerIndex >= 0) { + stack = chest.inventorySlots.getInventory().get(containerIndex); + Utils.drawItemStack(stack, guiLeft+10+x*18, guiTop+15+y*18); + } if(mouseX > guiLeft+10+x*18-1 && mouseX < guiLeft+10+x*18+18) { if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { - if(stack != null) tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, true); + if(stack != null) stackToRender = stack; GlStateManager.disableLighting(); GlStateManager.disableDepth(); @@ -139,32 +388,115 @@ public class TradeWindow { Utils.drawItemStack(bidStack, guiLeft+10, guiTop+90); if(mouseX > guiLeft+10-1 && mouseX < guiLeft+10+18) { if(mouseY > guiTop+90-1 && mouseY < guiTop+90+18) { - tooltipToDisplay = bidStack.getTooltip(Minecraft.getMinecraft().thePlayer, true); + tooltipToDisplay = bidStack.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); } } } ItemStack confirmStack = chest.inventorySlots.getInventory().get(39); if(confirmStack != null) { - if(mouseX > guiLeft+42 && mouseX < guiLeft+42+40) { - if (mouseY > guiTop+92 && mouseY < guiTop+92+14) { - tooltipToDisplay = confirmStack.getTooltip(Minecraft.getMinecraft().thePlayer, true); + String confirmDisplay = confirmStack.getDisplayName(); + if(!confirmDisplay.equals(EnumChatFormatting.GREEN+"Trading!")) { + if(mouseX > guiLeft+81-51 && mouseX < guiLeft+81) { + if (mouseY > guiTop+91 && mouseY < guiTop+91+14) { + tooltipToDisplay = confirmStack.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + } + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+81-51, guiTop+91, 51, 14, + 0, 51/256f, ySize/256f, (ySize+14)/256f, GL11.GL_NEAREST); + + Pattern pattern = Pattern.compile(EnumChatFormatting.GRAY+"\\("+EnumChatFormatting.YELLOW+"([0-9]+)"+EnumChatFormatting.GRAY+"\\)"); + Matcher matcher = pattern.matcher(confirmDisplay); + + if(!confirmDisplay.equals(EnumChatFormatting.YELLOW+"Warning!") && + !confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal!")) { + lastTradeMillis = -1; + } + + if(matcher.find()) { + String numS = matcher.group(1); + int num = Integer.parseInt(numS); + + Utils.drawStringCentered(EnumChatFormatting.DARK_RED + "Check " + EnumChatFormatting.BOLD + (char) (9311 + num), Minecraft.getMinecraft().fontRendererObj, guiLeft + 56, guiTop + 99, + false, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.AQUA+"Gift!")) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accept", Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.GREEN+"Deal accepted!")) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accepted", Minecraft.getMinecraft().fontRendererObj, + guiLeft+56, guiTop+99, true, 4210752); + } else if(lastTradeMillis > 0) { + long delta = System.currentTimeMillis() - lastTradeMillis; + if(delta > 2000) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accept", Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } else { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Trade "+EnumChatFormatting.BOLD+(char)(9312+(2000-delta)/1000), + Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } + } else { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Trade "+EnumChatFormatting.BOLD+(char)(9314), Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } + } + } + + ItemStack theirConfirmStack = chest.inventorySlots.getInventory().get(41); + if(theirConfirmStack != null) { + String confirmDisplay = theirConfirmStack.getDisplayName(); + if(mouseX > guiLeft+95 && mouseX < guiLeft+95+51) { + if (mouseY > guiTop+91 && mouseY < guiTop+91+14) { + tooltipToDisplay = theirConfirmStack.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); } } + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+95, guiTop+91, 51, 14, + 0, 51/256f, ySize/256f, (ySize+14)/256f, GL11.GL_NEAREST); + + if(confirmDisplay.equals(EnumChatFormatting.YELLOW+"Pending their confirm")) { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Pending", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, + true, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal timer...")) { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Pending", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, + true, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.GREEN+"Other player confirmed!")) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accepted", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, + true, 4210752); + } } for(int i=0; i<16; i++) { int x = i % 4; int y = i / 4; - int containerIndex = y*9+x+5; - ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + int containerIndex = theirTradeIndexes[i]; - Utils.drawItemStack(stack, guiLeft+96+x*18, guiTop+15+y*18); + ItemStack stack = null; + if(containerIndex >= 0) { + stack = chest.inventorySlots.getInventory().get(containerIndex); + Utils.drawItemStack(stack, guiLeft+96+x*18, guiTop+15+y*18); + } + + if(currentTime % 400 > 200 && theirTradeChangesMillis[i] != null && theirTradeChangesMillis[i] > 0) { + GlStateManager.translate(0, 0, 200); + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+96+x*18, guiTop+15+y*18, 16, 16, + 51/256f, 67/256f, 204/256f, 220/256f, GL11.GL_NEAREST); + GlStateManager.translate(0, 0, -200); + } if(mouseX > guiLeft+96+x*18-1 && mouseX < guiLeft+96+x*18+18) { if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { - if(stack != null) tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, true); + if(stack != null) stackToRender = stack; GlStateManager.disableLighting(); GlStateManager.disableDepth(); @@ -178,9 +510,231 @@ public class TradeWindow { } } + if(NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value) { + int ourTopItemsCount = 0; + TreeMap> ourTopItems = new TreeMap<>(); + int ourPrice = 0; + for(int i=0; i<16; i++) { + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname != null) { + if(NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(internalname)) continue; + + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + int pricePer = -1; + if(info != null && info.has("price") && info.has("count")) { + int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); + + pricePer = auctionPricePer * stack.stackSize; + } else { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { + pricePer = (int)bazaarInfo.get("avg_buy").getAsFloat(); + } + } + if(pricePer > 0) { + int price = pricePer * stack.stackSize; + + price += getBackpackValue(stack); + + Set items = ourTopItems.computeIfAbsent(price, k->new HashSet<>()); + items.add(containerIndex); + + ourTopItemsCount++; + ourPrice += price; + } + } + } + int theirTopItemsCount = 0; + TreeMap> theirTopItems = new TreeMap<>(); + int theirPrice = 0; + for(int i=0; i<16; i++) { + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x+5; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname != null) { + if(NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(internalname)) continue; + + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + int pricePer = -1; + if(info != null && info.has("price") && info.has("count")) { + int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); + + pricePer = auctionPricePer; + } else { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { + pricePer = (int)bazaarInfo.get("avg_buy").getAsFloat(); + } + } + if(pricePer > 0) { + int price = pricePer * stack.stackSize; + + price += getBackpackValue(stack); + + Set items = theirTopItems.computeIfAbsent(price, k->new HashSet<>()); + items.add(containerIndex); + + theirTopItemsCount++; + theirPrice += price; + } + } + } + + NumberFormat format = NumberFormat.getInstance(Locale.US); + + GlStateManager.disableLighting(); + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft-80-3, guiTop, 80, 106, + 176/256f, 1, 0, 106/256f, GL11.GL_NEAREST); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+"Total Value", + guiLeft-40-3, guiTop+11, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(ourPrice), + guiLeft-40-3, guiTop+21, 72); + + int ourTopIndex = Math.max(0, 3-ourTopItemsCount); + out: + for(Map.Entry> entry : ourTopItems.descendingMap().entrySet()) { + for(int ourTopItem : entry.getValue()) { + ItemStack stack = chest.inventorySlots.getInventory().get(ourTopItem); + if(stack == null) continue; + + if(NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value) { + Utils.drawItemStack(stack, guiLeft-75-3, guiTop+49+18*ourTopIndex); + GlStateManager.disableLighting(); + GlStateManager.disableBlend(); + GlStateManager.color(1, 1, 1, 1); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft-29-3, guiTop+57+18*ourTopIndex, 52); + GlStateManager.enableBlend(); + } else { + drawStringShadow(stack.getDisplayName(), + guiLeft-40-3, guiTop+46+20*ourTopIndex, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft-40-3, guiTop+56+20*ourTopIndex, 72); + } + + if(++ourTopIndex >= 3) break out; + } + } + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop, 80, 106, + 176/256f, 1, 0, 106/256f, GL11.GL_NEAREST); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+"Total Value", + guiLeft+xSize+3+40, guiTop+11, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(theirPrice), + guiLeft+xSize+3+40, guiTop+21, 72); + + int theirTopIndex = Math.max(0, 3-theirTopItemsCount); + out: + for(Map.Entry> entry : theirTopItems.descendingMap().entrySet()) { + for(int theirTopItem : entry.getValue()) { + ItemStack stack = chest.inventorySlots.getInventory().get(theirTopItem); + if(stack == null) continue; + + if(NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value) { + Utils.drawItemStack(stack, guiLeft+xSize+3+5, guiTop+49+18*theirTopIndex); + GlStateManager.disableLighting(); + GlStateManager.disableBlend(); + GlStateManager.color(1, 1, 1, 1); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft+xSize+3+51, guiTop+57+18*theirTopIndex, 52); + GlStateManager.enableBlend(); + } else { + drawStringShadow(stack.getDisplayName(), + guiLeft+xSize+3+40, guiTop+46+20*theirTopIndex, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft+xSize+3+40, guiTop+56+20*theirTopIndex, 72); + } + + if(++theirTopIndex >= 3) break out; + } + } + } + + + boolean button1 = NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value; + boolean button2 = NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value; + boolean button3 = NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value; + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-19, 17, 17, + (button3?17:0)/256f, (button3?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-38, 17, 17, + (button2?17:0)/256f, (button2?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-57, 17, 17, + (button1?17:0)/256f, (button1?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); + + if(mouseX >= guiLeft+xSize+3 && mouseX <= guiLeft+xSize+3+17) { + if(mouseY >= guiTop+ySize-19 && mouseY <= guiTop+ySize-19+17) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.GOLD+NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.displayName); + tooltipToDisplay.add(EnumChatFormatting.GRAY+NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.desc); + tooltipLen = 200; + } else if(mouseY >= guiTop+ySize-38 && mouseY <= guiTop+ySize-38+17) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.GOLD+NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.displayName); + tooltipToDisplay.add(EnumChatFormatting.GRAY+NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.desc); + tooltipLen = 200; + } else if(mouseY >= guiTop+ySize-57 && mouseY <= guiTop+ySize-57+17) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.GOLD+NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.displayName); + tooltipToDisplay.add(EnumChatFormatting.GRAY+NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.desc); + tooltipLen = 200; + } + } + + if(stackToRender == null && !SBAIntegration.isFreezeBackpack()) lastBackpack = null; + if(SBAIntegration.isFreezeBackpack()) { + if(lastBackpack != null) { + SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); + GlStateManager.translate(0, 0, 100); + SBAIntegration.renderActiveBackpack(mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj); + GlStateManager.translate(0, 0, -100); + } + } else { + if(stackToRender != null) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stackToRender); + boolean renderedBackpack; + if(internalname != null && (internalname.endsWith("BACKPACK") || internalname.equals("NEW_YEAR_CAKE_BAG"))) { + lastBackpack = stackToRender; + lastBackpackX = mouseX; + lastBackpackY = mouseY; + renderedBackpack = SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); + if(renderedBackpack) { + GlStateManager.translate(0, 0, 100); + renderedBackpack = SBAIntegration.renderActiveBackpack(mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj); + GlStateManager.translate(0, 0, -100); + } + } else { + renderedBackpack = false; + } + if(!renderedBackpack) { + lastBackpack = null; + tooltipToDisplay = stackToRender.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + } + } + } + if(tooltipToDisplay != null) { Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), - -1, Minecraft.getMinecraft().fontRendererObj); + tooltipLen, Minecraft.getMinecraft().fontRendererObj); } } @@ -224,7 +778,9 @@ public class TradeWindow { for(int i=0; i<16; i++) { int x = i % 4; int y = i / 4; - int containerIndex = y*9+x; + + int containerIndex = ourTradeIndexes[i]; + if(containerIndex < 0) continue; if(mouseX > guiLeft+10+x*18-1 && mouseX < guiLeft+10+x*18+18) { if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { @@ -245,11 +801,39 @@ public class TradeWindow { } } - if(mouseX > guiLeft+42 && mouseX < guiLeft+42+40) { - if (mouseY > guiTop+92 && mouseY < guiTop+92+14) { - Minecraft.getMinecraft().playerController.windowClick( - chest.inventorySlots.windowId, - 39, 2, 3, Minecraft.getMinecraft().thePlayer); + ItemStack confirmStack = chest.inventorySlots.getInventory().get(39); + if(confirmStack != null) { + String confirmDisplay = confirmStack.getDisplayName(); + if(!confirmDisplay.equals(EnumChatFormatting.GREEN+"Trading!")) { + if(mouseX > guiLeft+42 && mouseX < guiLeft+42+40) { + if (mouseY > guiTop+92 && mouseY < guiTop+92+14) { + if((confirmDisplay.equals(EnumChatFormatting.YELLOW+"Warning!") || + confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal!")) && lastTradeMillis < 0) { + lastTradeMillis = System.currentTimeMillis(); + } else if(lastTradeMillis < 0 || System.currentTimeMillis() - lastTradeMillis > 2000) { + Minecraft.getMinecraft().playerController.windowClick( + chest.inventorySlots.windowId, + 39, 2, 3, Minecraft.getMinecraft().thePlayer); + return; + } + } + } + + } + } + + if(mouseX >= guiLeft+xSize+3 && mouseX <= guiLeft+xSize+3+17) { + if(mouseY >= guiTop+ySize-19 && mouseY <= guiTop+ySize-19+17) { + NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value = + !NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value; + return; + } else if(mouseY >= guiTop+ySize-38 && mouseY <= guiTop+ySize-38+17) { + NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value = + !NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value; + return; + } else if(mouseY >= guiTop+ySize-57 && mouseY <= guiTop+ySize-57+17) { + NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value = + !NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value; return; } } 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 2bba6426..8b35f5cb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java @@ -330,7 +330,7 @@ public class SettingsInfoPane extends InfoPane { if(option == null) return; if(!textConfigMap.containsKey(option)) { - textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), 0)); + return; } GuiElementTextField tf = textConfigMap.get(option); 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 53c6e00b..9dc0e714 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java @@ -47,7 +47,7 @@ public class Options { true, "Quick Commands", false, - "Shows QuickCommands™ above search bar."); + "Shows QuickCommands\u2122 above search bar."); public Option showUpdateMsg = new Option( true, "Show Update Notifs", @@ -138,6 +138,11 @@ public class Options { "Price Info in Auction Lore", false, "If true, will show price information about an item inside the auction house item tooltip."); + public Option useCustomTrade = new Option( + true, + "Custom Trade", + false, + "If true, uses the custom trade window for skyblock trades."); public Option paneWidthMult = new Option( 1.0, "Pane Width", @@ -192,6 +197,16 @@ public class Options { "loadedModBefore", true, "loadedModBefore"); + public Option customTradePrices = new Option( + true, + "Trade Item Values", + true, + "If true, shows a window with the total item value of either side"); + public Option customTradePriceStyle = new Option( + true, + "Trade Prices Style", + true, + "Changes the style of the top item prices"); public Option selectedCape = new Option( "", "Selected Cape", @@ -328,6 +343,9 @@ public class Options { tryAddOption(disableItemTabOpen, options); tryAddOption(dungeonProfitLore, options); tryAddOption(auctionPriceInfo, options); + tryAddOption(useCustomTrade, options); + tryAddOption(customTradePrices, options); + tryAddOption(customTradePriceStyle, options); //Sliders tryAddOption(smoothAoteMillis, options); tryAddOption(bgBlurFactor, options); -- cgit