aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-16 15:50:41 -0400
committerGitHub <noreply@github.com>2021-10-16 15:50:41 -0400
commit7c00af18febf6c0b833c7633b4fb60a9a1bb93af (patch)
treef02de145362d6a1399651ade4a130d565d7f0ba3 /src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java
parentb11742988dec635b5c5da7c2363803cbfafb37b1 (diff)
downloadnotenoughupdates-7c00af18febf6c0b833c7633b4fb60a9a1bb93af.tar.gz
notenoughupdates-7c00af18febf6c0b833c7633b4fb60a9a1bb93af.tar.bz2
notenoughupdates-7c00af18febf6c0b833c7633b4fb60a9a1bb93af.zip
Code Clean Up (#2)
* intellij code clean up * optimize imports * format * intellij suggestions * fix empty catch issues
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.java615
1 files changed, 311 insertions, 304 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 0e4fbdea..d1df10c8 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java
@@ -26,14 +26,14 @@ 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.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TradeWindow {
- private static ResourceLocation location = new ResourceLocation("notenoughupdates", "custom_trade.png");
+ private static final ResourceLocation location = new ResourceLocation("notenoughupdates", "custom_trade.png");
private static final int xSize = 176;
private static final int ySize = 204;
@@ -53,20 +53,19 @@ public class TradeWindow {
private static int lastBackpackX;
private static int lastBackpackY;
-
public static boolean hypixelTradeWindowActive(String containerName) {
return containerName != null && containerName.trim().startsWith("You ");
}
public static boolean tradeWindowActive(String containerName) {
- if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return false;
- if(!NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade) return false;
+ if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return false;
+ if (!NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade) return false;
- if(hypixelTradeWindowActive(containerName)) {
+ if (hypixelTradeWindowActive(containerName)) {
return true;
}
- if(lastTradeMillis != -99) {
+ if (lastTradeMillis != -99) {
lastTradeMillis = -99;
ourTradeIndexes = new Integer[16];
theirTradeIndexes = new Integer[16];
@@ -78,13 +77,13 @@ public class TradeWindow {
}
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)) {
+ 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());
+ x + xOff / 2f, y + yOff / 2f, false, len,
+ new Color(20, 20, 20, 100 / Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB());
}
}
}
@@ -97,17 +96,17 @@ public class TradeWindow {
private static int getPrice(String internalname) {
int pricePer = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname);
- if(pricePer == -1) {
+ if (pricePer == -1) {
JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname);
- if(bazaarInfo != null && bazaarInfo.has("avg_buy")) {
- pricePer = (int)bazaarInfo.get("avg_buy").getAsFloat();
+ if (bazaarInfo != null && bazaarInfo.has("avg_buy")) {
+ pricePer = (int) bazaarInfo.get("avg_buy").getAsFloat();
}
}
- if(pricePer == -1) {
+ if (pricePer == -1) {
JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname);
- if(info != null && !NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(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());
+ int auctionPricePer = (int) (info.get("price").getAsFloat() / info.get("count").getAsFloat());
pricePer = auctionPricePer;
}
@@ -118,27 +117,30 @@ public class TradeWindow {
private static int processTopItems(ItemStack stack, Map<Integer, Set<String>> topItems,
Map<String, ItemStack> topItemsStack, Map<String, Integer> topItemsCount) {
String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack);
- if(internalname == null) {
- if(stack.getDisplayName().endsWith(" coins")) {
+ if (internalname == null) {
+ if (stack.getDisplayName().endsWith(" coins")) {
String clean = Utils.cleanColour(stack.getDisplayName());
int mult = 1;
StringBuilder sb = new StringBuilder();
- for(int index = 0; index < clean.length(); index++) {
+ for (int index = 0; index < clean.length(); index++) {
char c = clean.charAt(index);
- if("0123456789.".indexOf(c) >= 0) {
+ if ("0123456789.".indexOf(c) >= 0) {
sb.append(c);
} else {
- switch(c) {
+ switch (c) {
case 'K':
case 'k':
- mult = 1000; break;
+ mult = 1000;
+ break;
case 'M':
case 'm':
- mult = 1000000; break;
+ mult = 1000000;
+ break;
case 'B':
case 'b':
- mult = 1000000000; break;
+ mult = 1000000000;
+ break;
default:
break;
}
@@ -146,38 +148,38 @@ public class TradeWindow {
}
}
try {
- int coins = (int)(Float.parseFloat(sb.toString())*mult);
+ int coins = (int) (Float.parseFloat(sb.toString()) * mult);
topItemsStack.putIfAbsent("TRADE_COINS", stack);
int existingPrice = coins;
Set<Integer> toRemove = new HashSet<>();
- for(Map.Entry<Integer, Set<String>> entry : topItems.entrySet()) {
- if(entry.getValue().contains("TRADE_COINS")) {
+ for (Map.Entry<Integer, Set<String>> entry : topItems.entrySet()) {
+ if (entry.getValue().contains("TRADE_COINS")) {
entry.getValue().remove("TRADE_COINS");
existingPrice += entry.getKey();
}
- if(entry.getValue().isEmpty()) toRemove.add(entry.getKey());
+ if (entry.getValue().isEmpty()) toRemove.add(entry.getKey());
}
topItems.keySet().removeAll(toRemove);
- Set<String> items = topItems.computeIfAbsent(existingPrice, k->new HashSet<>());
+ Set<String> items = topItems.computeIfAbsent(existingPrice, k -> new HashSet<>());
items.add("TRADE_COINS");
return coins;
- } catch(Exception ignored) {}
+ } catch (Exception ignored) {}
}
} else {
int pricePer = getPrice(internalname);
- if(pricePer > 0) {
+ if (pricePer > 0) {
topItemsStack.putIfAbsent(internalname, stack);
int price = pricePer * stack.stackSize;
int priceInclBackpack = price;
NBTTagCompound tag = stack.getTagCompound();
- if(tag != null && tag.hasKey("ExtraAttributes", 10)) {
+ if (tag != null && tag.hasKey("ExtraAttributes", 10)) {
NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes");
byte[] bytes = null;
@@ -187,22 +189,22 @@ public class TradeWindow {
break;
}
}
- if(bytes != null) {
+ if (bytes != null) {
try {
NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes));
NBTTagList items = contents_nbt.getTagList("i", 10);
- for(int k=0; k<items.tagCount(); k++) {
- if(items.getCompoundTagAt(k).getKeySet().size() > 0) {
+ for (int k = 0; k < items.tagCount(); k++) {
+ if (items.getCompoundTagAt(k).getKeySet().size() > 0) {
NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag");
int id2 = items.getCompoundTagAt(k).getShort("id");
int count2 = items.getCompoundTagAt(k).getByte("Count");
int damage2 = items.getCompoundTagAt(k).getShort("Damage");
- if(id2 == 141) id2 = 391; //for some reason hypixel thinks carrots have id 141
+ if (id2 == 141) id2 = 391; //for some reason hypixel thinks carrots have id 141
Item mcItem = Item.getItemById(id2);
- if(mcItem == null) continue;
+ if (mcItem == null) continue;
ItemStack stack2 = new ItemStack(mcItem, count2, damage2);
stack2.setTagCompound(nbt);
@@ -210,26 +212,26 @@ public class TradeWindow {
priceInclBackpack += processTopItems(stack2, topItems, topItemsStack, topItemsCount);
}
}
- } catch(Exception e) { }
+ } catch (Exception ignored) {}
}
}
int existingPrice = price;
Set<Integer> toRemove = new HashSet<>();
- for(Map.Entry<Integer, Set<String>> entry : topItems.entrySet()) {
- if(entry.getValue().contains(internalname)) {
+ for (Map.Entry<Integer, Set<String>> entry : topItems.entrySet()) {
+ if (entry.getValue().contains(internalname)) {
entry.getValue().remove(internalname);
existingPrice += entry.getKey();
}
- if(entry.getValue().isEmpty()) toRemove.add(entry.getKey());
+ if (entry.getValue().isEmpty()) toRemove.add(entry.getKey());
}
topItems.keySet().removeAll(toRemove);
- Set<String> items = topItems.computeIfAbsent(existingPrice, k->new HashSet<>());
+ Set<String> items = topItems.computeIfAbsent(existingPrice, k -> new HashSet<>());
items.add(internalname);
- int count = topItemsCount.computeIfAbsent(internalname, l->0);
- topItemsCount.put(internalname, count+stack.stackSize);
+ int count = topItemsCount.computeIfAbsent(internalname, l -> 0);
+ topItemsCount.put(internalname, count + stack.stackSize);
return priceInclBackpack;
}
@@ -241,7 +243,7 @@ public class TradeWindow {
int price = 0;
NBTTagCompound tag = stack.getTagCompound();
- if(tag != null && tag.hasKey("ExtraAttributes", 10)) {
+ if (tag != null && tag.hasKey("ExtraAttributes", 10)) {
NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes");
byte[] bytes = null;
@@ -251,40 +253,40 @@ public class TradeWindow {
break;
}
}
- if(bytes != null) {
+ if (bytes != null) {
try {
NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes));
NBTTagList items = contents_nbt.getTagList("i", 10);
- for(int k=0; k<items.tagCount(); k++) {
- if(items.getCompoundTagAt(k).getKeySet().size() > 0) {
+ for (int k = 0; k < items.tagCount(); k++) {
+ if (items.getCompoundTagAt(k).getKeySet().size() > 0) {
NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag");
String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(nbt);
- if(internalname2 != null) {
+ if (internalname2 != null) {
int pricePer2 = getPrice(internalname2);
- if(pricePer2 > 0) {
+ if (pricePer2 > 0) {
int count2 = items.getCompoundTagAt(k).getByte("Count");
price += pricePer2 * count2;
}
}
}
}
- } catch(Exception e) { }
+ } catch (Exception ignored) {}
}
}
return price;
}
public static void render(int mouseX, int mouseY) {
- if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return;
+ if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return;
- GuiContainer chest = ((GuiContainer)Minecraft.getMinecraft().currentScreen);
+ GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen);
ContainerChest cc = (ContainerChest) chest.inventorySlots;
String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
- guiLeft = (scaledResolution.getScaledWidth()-xSize)/2;
- guiTop = (scaledResolution.getScaledHeight()-ySize)/2;
+ guiLeft = (scaledResolution.getScaledWidth() - xSize) / 2;
+ guiTop = (scaledResolution.getScaledHeight() - ySize) / 2;
List<String> tooltipToDisplay = null;
ItemStack stackToRender = null;
@@ -293,38 +295,41 @@ public class TradeWindow {
//Set index mappings
//Our slots
TreeMap<Integer, List<Integer>> ourTradeMap = new TreeMap<>();
- for(int i=0; i<16; i++) {
+ for (int i = 0; i < 16; i++) {
ourTradeIndexes[i] = -1;
int x = i % 4;
int y = i / 4;
- int containerIndex = y*9+x;
+ int containerIndex = y * 9 + x;
ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex);
- if(stack == null) continue;
+ if (stack == null) continue;
String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack);
- if(internalname == null) {
- if(stack.getDisplayName().endsWith(" coins")) {
+ if (internalname == null) {
+ if (stack.getDisplayName().endsWith(" coins")) {
String clean = Utils.cleanColour(stack.getDisplayName());
int mult = 1;
StringBuilder sb = new StringBuilder();
- for(int index = 0; index < clean.length(); index++) {
+ for (int index = 0; index < clean.length(); index++) {
char c = clean.charAt(index);
- if("0123456789.".indexOf(c) >= 0) {
+ if ("0123456789.".indexOf(c) >= 0) {
sb.append(c);
} else {
- switch(c) {
+ switch (c) {
case 'K':
case 'k':
- mult = 1000; break;
+ mult = 1000;
+ break;
case 'M':
case 'm':
- mult = 1000000; break;
+ mult = 1000000;
+ break;
case 'B':
case 'b':
- mult = 1000000000; break;
+ mult = 1000000000;
+ break;
default:
break;
}
@@ -332,12 +337,12 @@ public class TradeWindow {
}
}
try {
- int coins = (int)(Float.parseFloat(sb.toString())*mult);
+ int coins = (int) (Float.parseFloat(sb.toString()) * mult);
List<Integer> list = ourTradeMap.computeIfAbsent(coins, k -> new ArrayList<>());
list.add(containerIndex);
- } catch(Exception ignored) {
+ } catch (Exception ignored) {
List<Integer> list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>());
list.add(containerIndex);
}
@@ -347,7 +352,7 @@ public class TradeWindow {
}
} else {
int price = getPrice(internalname);
- if(price == -1) price = 0;
+ if (price == -1) price = 0;
price += getBackpackValue(stack);
@@ -359,60 +364,63 @@ public class TradeWindow {
List<String> theirTradeCurrent = new ArrayList<>();
TreeMap<Integer, List<Integer>> theirTradeMap = new TreeMap<>();
HashMap<String, Integer> displayCountMap = new HashMap<>();
- for(int i=0; i<16; i++) {
+ for (int i = 0; i < 16; i++) {
theirTradeIndexes[i] = -1;
- if(theirTradeChangesMillis[i] == null || currentTime - theirTradeChangesMillis[i] > CHANGE_EXCLAM_MILLIS) {
+ 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;
+ int containerIndex = y * 9 + x + 5;
ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex);
- if(stack == null) continue;
+ if (stack == null) continue;
NBTTagCompound tag = stack.getTagCompound();
String uuid = null;
- if(tag != null && tag.hasKey("ExtraAttributes", 10)) {
+ if (tag != null && tag.hasKey("ExtraAttributes", 10)) {
NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes");
if (ea.hasKey("uuid", 8)) {
uuid = ea.getString("uuid");
} else {
- int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0);
+ int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k -> 0);
uuid = stack.getDisplayName() + ":" + displayCount;
- displayCountMap.put(stack.getDisplayName(), displayCount+1);
+ displayCountMap.put(stack.getDisplayName(), displayCount + 1);
}
} else {
- int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0);
+ int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k -> 0);
uuid = stack.getDisplayName() + ":" + displayCount;
- displayCountMap.put(stack.getDisplayName(), displayCount+1);
+ displayCountMap.put(stack.getDisplayName(), displayCount + 1);
}
- if(uuid != null) theirTradeCurrent.add(uuid);
+ if (uuid != null) theirTradeCurrent.add(uuid);
String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack);
- if(internalname == null) {
- if(stack.getDisplayName().endsWith(" coins")) {
+ if (internalname == null) {
+ if (stack.getDisplayName().endsWith(" coins")) {
String clean = Utils.cleanColour(stack.getDisplayName());
int mult = 1;
StringBuilder sb = new StringBuilder();
- for(int index = 0; index < clean.length(); index++) {
+ for (int index = 0; index < clean.length(); index++) {
char c = clean.charAt(index);
- if("0123456789.".indexOf(c) >= 0) {
+ if ("0123456789.".indexOf(c) >= 0) {
sb.append(c);
} else {
- switch(c) {
+ switch (c) {
case 'K':
case 'k':
- mult = 1000; break;
+ mult = 1000;
+ break;
case 'M':
case 'm':
- mult = 1000000; break;
+ mult = 1000000;
+ break;
case 'B':
case 'b':
- mult = 1000000000; break;
+ mult = 1000000000;
+ break;
default:
break;
}
@@ -420,12 +428,12 @@ public class TradeWindow {
}
}
try {
- int coins = (int)(Float.parseFloat(sb.toString())*mult);
+ int coins = (int) (Float.parseFloat(sb.toString()) * mult);
List<Integer> list = theirTradeMap.computeIfAbsent(coins, k -> new ArrayList<>());
list.add(containerIndex);
- } catch(Exception ignored) {
+ } catch (Exception ignored) {
List<Integer> list = theirTradeMap.computeIfAbsent(-1, k -> new ArrayList<>());
list.add(containerIndex);
}
@@ -436,14 +444,14 @@ public class TradeWindow {
} 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());
+ 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;
+ if (bazaarInfo != null && bazaarInfo.has("avg_buy")) {
+ price = (int) bazaarInfo.get("avg_buy").getAsFloat() * stack.stackSize;
}
}
@@ -454,58 +462,58 @@ public class TradeWindow {
}
}
int ourTradeIndex = 0;
- for(Map.Entry<Integer, List<Integer>> entry : ourTradeMap.descendingMap().entrySet()) {
- for(Integer index : entry.getValue()) {
+ for (Map.Entry<Integer, List<Integer>> 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<maxMissing) && theirTradeChangesMillis[j] >= 0) j++;
+ int maxMissing = 16 - theirTradeCurrent.size();
+ int j = 0;
+ for (int i = 0; i < 16; i++) {
+ while (j <= 15 && (j - i < maxMissing) && theirTradeChangesMillis[j] >= 0) j++;
j = Math.min(15, j);
String oldUUID = theirTradeOld[i];
- if(oldUUID != null && !theirTradeCurrent.contains(oldUUID)) {
+ if (oldUUID != null && !theirTradeCurrent.contains(oldUUID)) {
theirTradeChangesMillis[j] = System.currentTimeMillis();
}
j++;
}
- for(int i=0; i<16; i++) {
+ for (int i = 0; i < 16; i++) {
theirTradeOld[i] = null;
}
int theirTradeIndex = 0;
displayCountMap.clear();
- j=0;
- for(Map.Entry<Integer, List<Integer>> entry : theirTradeMap.descendingMap().entrySet()) {
- for(Integer index : entry.getValue()) {
- while(j <= 15 && (j-theirTradeIndex<maxMissing) && theirTradeChangesMillis[j] >= 0) j++;
+ j = 0;
+ for (Map.Entry<Integer, List<Integer>> entry : theirTradeMap.descendingMap().entrySet()) {
+ for (Integer index : entry.getValue()) {
+ while (j <= 15 && (j - theirTradeIndex < maxMissing) && theirTradeChangesMillis[j] >= 0) j++;
j = Math.min(15, j);
theirTradeIndexes[j] = index;
ItemStack stack = chest.inventorySlots.getInventory().get(index);
- if(stack == null) continue;
+ if (stack == null) continue;
NBTTagCompound tag = stack.getTagCompound();
String uuid = null;
- if(tag != null && tag.hasKey("ExtraAttributes", 10)) {
+ if (tag != null && tag.hasKey("ExtraAttributes", 10)) {
NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes");
if (ea.hasKey("uuid", 8)) {
uuid = ea.getString("uuid");
} else {
- int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0);
+ int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k -> 0);
uuid = stack.getDisplayName() + ":" + displayCount;
- displayCountMap.put(stack.getDisplayName(), displayCount+1);
+ displayCountMap.put(stack.getDisplayName(), displayCount + 1);
}
} else {
- int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0);
+ int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k -> 0);
uuid = stack.getDisplayName() + ":" + displayCount;
- displayCountMap.put(stack.getDisplayName(), displayCount+1);
+ displayCountMap.put(stack.getDisplayName(), displayCount + 1);
}
//System.out.println(uuid);
theirTradeOld[theirTradeIndex] = uuid;
@@ -517,42 +525,42 @@ public class TradeWindow {
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, guiTop, xSize, ySize, 0, 176 / 256f, 0, 204 / 256f, GL11.GL_NEAREST);
Utils.drawStringF(new ChatComponentTranslation("container.inventory").getUnformattedText(),
- Minecraft.getMinecraft().fontRendererObj, guiLeft+8, guiTop+111, false, 4210752);
- Utils.drawStringF("You", Minecraft.getMinecraft().fontRendererObj, guiLeft+8,
- guiTop+5, false, 4210752);
+ Minecraft.getMinecraft().fontRendererObj, guiLeft + 8, guiTop + 111, false, 4210752);
+ Utils.drawStringF("You", Minecraft.getMinecraft().fontRendererObj, guiLeft + 8,
+ guiTop + 5, false, 4210752);
String[] split = containerName.split(" ");
- if(split.length >= 1) {
- Utils.drawStringF(split[split.length-1], Minecraft.getMinecraft().fontRendererObj,
- guiLeft+167-Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length-1]),
- guiTop+5, false, 4210752);
+ if (split.length >= 1) {
+ Utils.drawStringF(split[split.length - 1], Minecraft.getMinecraft().fontRendererObj,
+ guiLeft + 167 - Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length - 1]),
+ guiTop + 5, false, 4210752);
}
- int index=0;
- for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) {
- int x = 8+18*(index % 9);
- int y = 104+18*(index / 9);
- if(index < 9) y = 180;
+ int index = 0;
+ for (ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) {
+ int x = 8 + 18 * (index % 9);
+ int y = 104 + 18 * (index / 9);
+ if (index < 9) y = 180;
- chest.drawSlot(new Slot(Minecraft.getMinecraft().thePlayer.inventory, index, guiLeft+x, guiTop+y));
+ chest.drawSlot(new Slot(Minecraft.getMinecraft().thePlayer.inventory, index, guiLeft + x, guiTop + y));
//Utils.drawItemStack(stack, guiLeft+x, guiTop+y);
int col = 0x80ffffff;
- if(SlotLocking.getInstance().isSlotIndexLocked(index)) {
+ if (SlotLocking.getInstance().isSlotIndexLocked(index)) {
col = 0x80ff8080;
}
- if(mouseX > guiLeft+x-1 && mouseX < guiLeft+x+18) {
- if(mouseY > guiTop+y-1 && mouseY < guiTop+y+18) {
- if(stack != null) stackToRender = stack;
+ if (mouseX > guiLeft + x - 1 && mouseX < guiLeft + x + 18) {
+ if (mouseY > guiTop + y - 1 && mouseY < guiTop + y + 18) {
+ if (stack != null) stackToRender = stack;
GlStateManager.disableLighting();
GlStateManager.disableDepth();
GlStateManager.colorMask(true, true, true, false);
- Utils.drawGradientRect(guiLeft+x, guiTop+y,
- guiLeft+x + 16, guiTop+y + 16, col, col);
+ Utils.drawGradientRect(guiLeft + x, guiTop + y,
+ guiLeft + x + 16, guiTop + y + 16, col, col);
GlStateManager.colorMask(true, true, true, true);
GlStateManager.enableLighting();
GlStateManager.enableDepth();
@@ -562,27 +570,27 @@ public class TradeWindow {
index++;
}
- for(int i=0; i<16; i++) {
+ for (int i = 0; i < 16; i++) {
int x = i % 4;
int y = i / 4;
int containerIndex = ourTradeIndexes[i];
ItemStack stack = null;
- if(containerIndex >= 0) {
+ if (containerIndex >= 0) {
stack = chest.inventorySlots.getInventory().get(containerIndex);
- Utils.drawItemStack(stack, guiLeft+10+x*18, guiTop+15+y*18);
+ 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) stackToRender = stack;
+ 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) stackToRender = stack;
GlStateManager.disableLighting();
GlStateManager.disableDepth();
GlStateManager.colorMask(true, true, true, false);
- Utils.drawGradientRect(guiLeft+10+x*18, guiTop+15+y*18,
- guiLeft+10+x*18 + 16, guiTop+15+y*18 + 16, -2130706433, -2130706433);
+ Utils.drawGradientRect(guiLeft + 10 + x * 18, guiTop + 15 + y * 18,
+ guiLeft + 10 + x * 18 + 16, guiTop + 15 + y * 18 + 16, -2130706433, -2130706433);
GlStateManager.colorMask(true, true, true, true);
GlStateManager.enableLighting();
GlStateManager.enableDepth();
@@ -591,10 +599,10 @@ public class TradeWindow {
}
ItemStack bidStack = chest.inventorySlots.getInventory().get(36);
- if(bidStack != null) {
- 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) {
+ if (bidStack != null) {
+ 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,
Minecraft.getMinecraft().gameSettings.advancedItemTooltips);
}
@@ -602,62 +610,62 @@ public class TradeWindow {
}
ItemStack confirmStack = chest.inventorySlots.getInventory().get(39);
- if(confirmStack != null) {
+ if (confirmStack != null) {
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) {
+ 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);
+ 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+"\\)");
+ 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!")) {
+ if (!confirmDisplay.equals(EnumChatFormatting.YELLOW + "Warning!") &&
+ !confirmDisplay.equals(EnumChatFormatting.YELLOW + "Deal!")) {
lastTradeMillis = -1;
}
- if(matcher.find()) {
+ 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,
+ } 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) {
+ } 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() - lastTradeM