diff options
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java | 107 |
1 files changed, 72 insertions, 35 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java index 1ba155d5..16b5015b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java @@ -1,9 +1,30 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + package io.github.moulberry.notenoughupdates.miscgui; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; @@ -26,8 +47,14 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.ByteArrayInputStream; import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; -import java.util.*; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -95,28 +122,34 @@ public class TradeWindow { ); } - private static int getPrice(String internalname) { - int pricePer = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); + private static long getPrice(String internalName) { + long pricePer = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalName); if (pricePer == -1) { - JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalName); if (bazaarInfo != null && bazaarInfo.has("avg_buy")) { - pricePer = (int) bazaarInfo.get("avg_buy").getAsFloat(); + pricePer = (long) bazaarInfo.get("avg_buy").getAsDouble(); } } if (pricePer == -1) { - JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); - if (info != null && !NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(internalname) && + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalName); + if (info != null && !NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(internalName) && info.has("price") && info.has("count")) { - int auctionPricePer = (int) (info.get("price").getAsFloat() / info.get("count").getAsFloat()); + long auctionPricePer = (long) (info.get("price").getAsDouble() / info.get("count").getAsDouble()); pricePer = auctionPricePer; } } + if (pricePer == -1) { + APIManager.CraftInfo craftCost = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(internalName); + if (craftCost != null) { + pricePer = (int) craftCost.craftCost; + } + } return pricePer; } - private static int processTopItems( - ItemStack stack, Map<Integer, Set<String>> topItems, + private static long processTopItems( + ItemStack stack, Map<Long, Set<String>> topItems, Map<String, ItemStack> topItemsStack, Map<String, Integer> topItemsCount ) { String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); @@ -155,9 +188,9 @@ public class TradeWindow { topItemsStack.putIfAbsent("TRADE_COINS", stack); - int existingPrice = coins; - Set<Integer> toRemove = new HashSet<>(); - for (Map.Entry<Integer, Set<String>> entry : topItems.entrySet()) { + long existingPrice = coins; + Set<Long> toRemove = new HashSet<>(); + for (Map.Entry<Long, Set<String>> entry : topItems.entrySet()) { if (entry.getValue().contains("TRADE_COINS")) { entry.getValue().remove("TRADE_COINS"); existingPrice += entry.getKey(); @@ -175,12 +208,12 @@ public class TradeWindow { } } } else { - int pricePer = getPrice(internalname); + long pricePer = getPrice(internalname); if (pricePer > 0) { topItemsStack.putIfAbsent(internalname, stack); - int price = pricePer * stack.stackSize; - int priceInclBackpack = price; + long price = pricePer * stack.stackSize; + long priceInclBackpack = price; NBTTagCompound tag = stack.getTagCompound(); if (tag != null && tag.hasKey("ExtraAttributes", 10)) { @@ -221,9 +254,9 @@ public class TradeWindow { } } - int existingPrice = price; - Set<Integer> toRemove = new HashSet<>(); - for (Map.Entry<Integer, Set<String>> entry : topItems.entrySet()) { + long existingPrice = price; + Set<Long> toRemove = new HashSet<>(); + for (Map.Entry<Long, Set<String>> entry : topItems.entrySet()) { if (entry.getValue().contains(internalname)) { entry.getValue().remove(internalname); existingPrice += entry.getKey(); @@ -267,7 +300,7 @@ public class TradeWindow { NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag"); String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(nbt); if (internalname2 != null) { - int pricePer2 = getPrice(internalname2); + long pricePer2 = getPrice(internalname2); if (pricePer2 > 0) { int count2 = items.getCompoundTagAt(k).getByte("Count"); price += pricePer2 * count2; @@ -300,7 +333,7 @@ public class TradeWindow { //Set index mappings //Our slots - TreeMap<Integer, List<Integer>> ourTradeMap = new TreeMap<>(); + TreeMap<Long, List<Integer>> ourTradeMap = new TreeMap<>(); for (int i = 0; i < 16; i++) { ourTradeIndexes[i] = -1; @@ -345,19 +378,19 @@ public class TradeWindow { try { int coins = (int) (Float.parseFloat(sb.toString()) * mult); - List<Integer> list = ourTradeMap.computeIfAbsent(coins, k -> new ArrayList<>()); + List<Integer> list = ourTradeMap.computeIfAbsent((long) coins, k -> new ArrayList<>()); list.add(containerIndex); } catch (Exception ignored) { - List<Integer> list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + List<Integer> list = ourTradeMap.computeIfAbsent(-1L, k -> new ArrayList<>()); list.add(containerIndex); } } else { - List<Integer> list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + List<Integer> list = ourTradeMap.computeIfAbsent(-1L, k -> new ArrayList<>()); list.add(containerIndex); } } else { - int price = getPrice(internalname); + long price = getPrice(internalname); if (price == -1) price = 0; price += getBackpackValue(stack); @@ -468,7 +501,7 @@ public class TradeWindow { } } int ourTradeIndex = 0; - for (Map.Entry<Integer, List<Integer>> entry : ourTradeMap.descendingMap().entrySet()) { + for (Map.Entry<Long, List<Integer>> entry : ourTradeMap.descendingMap().entrySet()) { for (Integer index : entry.getValue()) { ourTradeIndexes[ourTradeIndex++] = index; } @@ -553,8 +586,12 @@ public class TradeWindow { int y = 104 + 18 * (index / 9); if (index < 9) y = 180; - chest.drawSlot(new Slot(Minecraft.getMinecraft().thePlayer.inventory, index, guiLeft + x, guiTop + y)); - //Utils.drawItemStack(stack, guiLeft+x, guiTop+y); + ((AccessorGuiContainer) chest).doDrawSlot(new Slot( + Minecraft.getMinecraft().thePlayer.inventory, + index, + guiLeft + x, + guiTop + y + )); int col = 0x80ffffff; if (SlotLocking.getInstance().isSlotIndexLocked(index)) { @@ -796,10 +833,10 @@ public class TradeWindow { } if (NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePrices) { - TreeMap<Integer, Set<String>> ourTopItems = new TreeMap<>(); + TreeMap<Long, Set<String>> ourTopItems = new TreeMap<>(); TreeMap<String, ItemStack> ourTopItemsStack = new TreeMap<>(); TreeMap<String, Integer> ourTopItemsCount = new TreeMap<>(); - int ourPrice = 0; + double ourPrice = 0; for (int i = 0; i < 16; i++) { int x = i % 4; int y = i / 4; @@ -810,10 +847,10 @@ public class TradeWindow { ourPrice += processTopItems(stack, ourTopItems, ourTopItemsStack, ourTopItemsCount); } - TreeMap<Integer, Set<String>> theirTopItems = new TreeMap<>(); + TreeMap<Long, Set<String>> theirTopItems = new TreeMap<>(); TreeMap<String, ItemStack> theirTopItemsStack = new TreeMap<>(); TreeMap<String, Integer> theirTopItemsCount = new TreeMap<>(); - int theirPrice = 0; + double theirPrice = 0; for (int i = 0; i < 16; i++) { int x = i % 4; int y = i / 4; @@ -842,7 +879,7 @@ public class TradeWindow { int ourTopIndex = Math.max(0, 3 - ourTopItemsStack.size()); out: - for (Map.Entry<Integer, Set<String>> entry : ourTopItems.descendingMap().entrySet()) { + for (Map.Entry<Long, Set<String>> entry : ourTopItems.descendingMap().entrySet()) { for (String ourTopItemInternal : entry.getValue()) { ItemStack stack = ourTopItemsStack.get(ourTopItemInternal); if (stack == null) continue; @@ -905,7 +942,7 @@ public class TradeWindow { int theirTopIndex = Math.max(0, 3 - theirTopItemsStack.size()); out: - for (Map.Entry<Integer, Set<String>> entry : theirTopItems.descendingMap().entrySet()) { + for (Map.Entry<Long, Set<String>> entry : theirTopItems.descendingMap().entrySet()) { for (String theirTopItemInternal : entry.getValue()) { ItemStack stack = theirTopItemsStack.get(theirTopItemInternal); if (stack == null) continue; @@ -1041,7 +1078,7 @@ public class TradeWindow { !SlotLocking.getInstance().isSlotLocked(slot)) { Minecraft.getMinecraft().playerController.windowClick( chest.inventorySlots.windowId, - slot.slotNumber, 2, 3, Minecraft.getMinecraft().thePlayer + slot.slotNumber, 0, 0, Minecraft.getMinecraft().thePlayer ); } return; |
