aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.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/infopanes/CollectionLogInfoPane.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/infopanes/CollectionLogInfoPane.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java208
1 files changed, 105 insertions, 103 deletions
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 fadb148d..d8e4ef68 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,6 @@ import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.NEUOverlay;
import io.github.moulberry.notenoughupdates.util.NEUResourceManager;
-import io.github.moulberry.notenoughupdates.util.SpecialColour;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
@@ -18,8 +17,8 @@ import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
-import java.util.*;
import java.util.List;
+import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -28,8 +27,8 @@ import static io.github.moulberry.notenoughupdates.util.GuiTextures.item_mask;
public class CollectionLogInfoPane extends ScrollableInfoPane {
- private String mobRegex = ".*?((_MONSTER)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$";
- private String petRegex = ".*?;[0-4]$";
+ private final String mobRegex = ".*?((_MONSTER)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$";
+ private final String petRegex = ".*?;[0-4]$";
TreeSet<String> items = new TreeSet<>(getItemComparator());
@@ -52,8 +51,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
private static final int FILTER_SLAYER_WOLF = 7;
private static final int FILTER_SLAYER_SPIDER = 8;
private int filterMode = FILTER_ALL;
- private String[] filterPrettyNames = new String[]{"ALL","WEAPON","ARMOR",
- "ACCESSORY","PET","DUNGEON","ZOMBIE SLAYER","WOLF SLAYER","SPIDER SLAYER"};
+ private final String[] filterPrettyNames = new String[]{"ALL", "WEAPON", "ARMOR",
+ "ACCESSORY", "PET", "DUNGEON", "ZOMBIE SLAYER", "WOLF SLAYER", "SPIDER SLAYER"};
private Framebuffer itemFramebuffer = null;
private Framebuffer itemBGFramebuffer = null;
@@ -68,43 +67,47 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
}
private boolean loreContains(JsonArray lore, String str) {
- for(int i=0; i<lore.size(); i++) {
+ for (int i = 0; i < lore.size(); i++) {
String line = lore.get(i).getAsString();
- if(line.contains(str)) return true;
+ if (line.contains(str)) return true;
}
return false;
}
private void refreshItems() {
items.clear();
- for(String internalname : manager.getItemInformation().keySet()) {
- if(!manager.auctionManager.isVanillaItem(internalname) && !internalname.matches(mobRegex)) {
+ for (String internalname : manager.getItemInformation().keySet()) {
+ if (!manager.auctionManager.isVanillaItem(internalname) && !internalname.matches(mobRegex)) {
JsonObject item = manager.getItemInformation().get(internalname);
JsonArray lore = manager.getItemInformation().get(internalname).get("lore").getAsJsonArray();
- switch(filterMode) {
+ switch (filterMode) {
case FILTER_WEAPON:
- if(overlay.checkItemType(lore, "SWORD", "BOW", "WAND") < 0) continue;
+ if (overlay.checkItemType(lore, "SWORD", "BOW", "WAND") < 0) continue;
break;
case FILTER_ARMOR:
- if(overlay.checkItemType(lore, "HELMET", "CHESTPLATE", "LEGGINGS", "BOOTS") < 0) continue;
+ if (overlay.checkItemType(lore, "HELMET", "CHESTPLATE", "LEGGINGS", "BOOTS") < 0) continue;
break;
case FILTER_ACCESSORY:
- if(overlay.checkItemType(lore, "ACCESSORY") < 0) continue;
+ if (overlay.checkItemType(lore, "ACCESSORY") < 0) continue;
break;
case FILTER_PET:
- if(!internalname.matches(petRegex) || !item.get("displayname").getAsString().contains("[")) continue;
+ if (!internalname.matches(petRegex) || !item.get("displayname").getAsString().contains("["))
+ continue;
break;
case FILTER_DUNGEON:
- if(Utils.checkItemType(lore, true, "DUNGEON") < 0) continue;
+ if (Utils.checkItemType(lore, true, "DUNGEON") < 0) continue;
break;
case FILTER_SLAYER_ZOMBIE:
- if(!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("ZOMBIE")) continue;
+ if (!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("ZOMBIE"))
+ continue;
break;
case FILTER_SLAYER_WOLF:
- if(!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("WOLF")) continue;
+ if (!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("WOLF"))
+ continue;
break;
case FILTER_SLAYER_SPIDER:
- if(!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("SPIDER")) continue;
+ if (!item.has("slayer_req") || !item.get("slayer_req").getAsString().startsWith("SPIDER"))
+ continue;
break;
}
items.add(internalname);
@@ -121,11 +124,11 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
float cost1 = manager.auctionManager.getLowestBin(o1);
float cost2 = manager.auctionManager.getLowestBin(o2);
- if(cost1 == -1) cost1 = manager.auctionManager.getCraftCost(o1).craftCost;
- if(cost2 == -1) cost2 = manager.auctionManager.getCraftCost(o2).craftCost;
+ if (cost1 == -1) cost1 = manager.auctionManager.getCraftCost(o1).craftCost;
+ if (cost2 == -1) cost2 = manager.auctionManager.getCraftCost(o2).craftCost;
- if(cost1 < cost2) return 1;
- if(cost1 > cost2) return -1;
+ if (cost1 < cost2) return 1;
+ if (cost1 > cost2) return -1;
return o1.compareTo(o2);
};
@@ -133,17 +136,17 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
public void mouseInput(int width, int height, int mouseX, int mouseY, boolean mouseDown) {
super.mouseInput(width, height, mouseX, mouseY, mouseDown);
- if(mouseDown) {
- if(buttonHover == 0) {
- if(Mouse.getEventButton() == 0) {
+ if (mouseDown) {
+ if (buttonHover == 0) {
+ if (Mouse.getEventButton() == 0) {
filterMode++;
- if(filterMode >= filterPrettyNames.length) {
+ if (filterMode >= filterPrettyNames.length) {
filterMode = 0;
}
- } else if(Mouse.getEventButton() == 1) {
+ } else if (Mouse.getEventButton() == 1) {
filterMode--;
- if(filterMode < 0) {
- filterMode = filterPrettyNames.length-1;
+ if (filterMode < 0) {
+ filterMode = filterPrettyNames.length - 1;
}
}
}
@@ -152,32 +155,32 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
}
public void render(int width, int height, Color bg, Color fg, ScaledResolution scaledresolution, int mouseX, int mouseY) {
- int paneWidth = (int)(width/3*overlay.getWidthMult());
- int rightSide = (int)(width*overlay.getInfoPaneOffsetFactor());
+ int paneWidth = (int) (width / 3 * overlay.getWidthMult());
+ int rightSide = (int) (width * overlay.getInfoPaneOffsetFactor());
int leftSide = rightSide - paneWidth;
int padding = overlay.getBoxPadding();
renderDefaultBackground(width, height, bg);
- renderControls(height, padding, leftSide+padding, rightSide-padding, 20, fg);
- renderCollectionLog(fg, width, height, leftSide+padding, rightSide-padding, padding+25, height-padding);
+ renderControls(height, padding, leftSide + padding, rightSide - padding, 20, fg);
+ renderCollectionLog(fg, width, height, leftSide + padding, rightSide - padding, padding + 25, height - padding);
}
private float getCompletedness() {
int total = items.size();
int own = 0;
- for(String item : items) {
- if(getAcquiredItems() != null &&
+ for (String item : items) {
+ if (getAcquiredItems() != null &&
getAcquiredItems().containsKey(manager.getCurrentProfile()) &&
getAcquiredItems().get(manager.getCurrentProfile()).contains(item)) {
own++;
}
}
- return own/(float)total;
+ return own / (float) total;
}
- private EnumChatFormatting[] rainbow = new EnumChatFormatting[]{
+ private final EnumChatFormatting[] rainbow = new EnumChatFormatting[]{
EnumChatFormatting.RED,
EnumChatFormatting.GOLD,
EnumChatFormatting.YELLOW,
@@ -189,13 +192,13 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
private String getCompletednessString() {
float completedness = getCompletedness();
- String text = (int)(completedness*100)+"% Complete";
- if(completedness >= 1) {
+ String text = (int) (completedness * 100) + "% Complete";
+ if (completedness >= 1) {
StringBuilder rainbowText = new StringBuilder();
- for(int i=0; i<text.length(); i++) {
+ for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
- int index = (int)(i-System.currentTimeMillis()/100)%rainbow.length;
- if(index < 0) index += rainbow.length;
+ int index = (int) (i - System.currentTimeMillis() / 100) % rainbow.length;
+ if (index < 0) index += rainbow.length;
rainbowText.append(rainbow[index]).append(c);
}
text = rainbowText.toString();
@@ -211,39 +214,39 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
buttonHover = -1;
- int totalAvailable = right-left;
+ int totalAvailable = right - left;
int controlPadding = 3;
String[] controls = new String[]{
- "Filter: "+filterPrettyNames[filterMode],
+ "Filter: " + filterPrettyNames[filterMode],
getCompletednessString()};
int numControls = controls.length;
- int available = totalAvailable-(numControls-1)*controlPadding;
- int controlSize = available/numControls;
- int extraPadding = (available%controlSize)/2;
+ int available = totalAvailable - (numControls - 1) * controlPadding;
+ int controlSize = available / numControls;
+ int extraPadding = (available % controlSize) / 2;
- for(int i=0; i<numControls; i++) {
- int width = controlSize+controlPadding;
- int x = left+extraPadding+i*width;
+ for (int i = 0; i < numControls; i++) {
+ int width = controlSize + controlPadding;
+ int x = left + extraPadding + i * width;
- if(mouseX > x && mouseX < x+controlSize) {
- if(mouseY > top && mouseY < top+ySize) {
+ if (mouseX > x && mouseX < x + controlSize) {
+ if (mouseY > top && mouseY < top + ySize) {
buttonHover = i;
}
}
- drawRect(x, top, x+controlSize, top+ySize,
- new Color(177,177,177).getRGB());
- drawRect(x+1, top+1, x+controlSize, top+ySize,
- new Color(50,50,50).getRGB());
- drawRect(x+1, top+1, x+controlSize-1, top+ySize-1, fg.getRGB());
+ drawRect(x, top, x + controlSize, top + ySize,
+ new Color(177, 177, 177).getRGB());
+ drawRect(x + 1, top + 1, x + controlSize, top + ySize,
+ new Color(50, 50, 50).getRGB());
+ drawRect(x + 1, top + 1, x + controlSize - 1, top + ySize - 1, fg.getRGB());
Utils.drawStringCenteredScaledMaxWidth(controls[i], Minecraft.getMinecraft().fontRendererObj,
- x+width/2f, top+ySize/2f, true, controlSize-4, Color.WHITE.getRGB());
+ x + width / 2f, top + ySize / 2f, true, controlSize - 4, Color.WHITE.getRGB());
}
}
public int getCurrentAcquiredCount() {
- if(getAcquiredItems() == null) return 0;
- if(!getAcquiredItems().containsKey(manager.getCurrentProfile())) return 0;
+ if (getAcquiredItems() == null) return 0;
+ if (!getAcquiredItems().containsKey(manager.getCurrentProfile())) return 0;
return getAcquiredItems().get(manager.getCurrentProfile()).size();
}
@@ -253,10 +256,10 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
int mouseX = Mouse.getX() / scaledresolution.getScaleFactor();
int mouseY = height - Mouse.getY() / scaledresolution.getScaleFactor();
- if(itemFramebuffer != null && grayscaleShader != null &&
+ if (itemFramebuffer != null && grayscaleShader != null &&
(itemFramebuffer.framebufferWidth != width || itemFramebuffer.framebufferHeight != height)) {
grayscaleShader.setProjectionMatrix(Utils.createProjectionMatrix(
- width*scaledresolution.getScaleFactor(), height*scaledresolution.getScaleFactor()));
+ width * scaledresolution.getScaleFactor(), height * scaledresolution.getScaleFactor()));
}
itemFramebuffer = checkFramebufferSizes(itemFramebuffer, width, height,
@@ -282,14 +285,14 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
renderFromImage(itemBGFramebuffer, width, height, left, right, top, bottom);
renderFromImage(itemFramebuffer, width, height, left, right, top, bottom);
- if(grayscaleShader == null) {
+ if (grayscaleShader == null) {
try {
grayscaleShader = new Shader(new NEUResourceManager(Minecraft.getMinecraft().getResourceManager()),
"grayscale",
itemFramebuffer, itemFramebufferGrayscale);
grayscaleShader.setProjectionMatrix(Utils.createProjectionMatrix(
- width*scaledresolution.getScaleFactor(), height*scaledresolution.getScaleFactor()));
- } catch(Exception e) {
+ width * scaledresolution.getScaleFactor(), height * scaledresolution.getScaleFactor()));
+ } catch (Exception e) {
return;
}
}
@@ -313,46 +316,45 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
iterateItemSlots(new ItemSlotConsumer() {
@Override
public void consume(int x, int y, int id) {
- if(id < items.length) {
+ if (id < items.length) {
String internalname = items[id];
- if(id == 0) isTop.set(true);
+ if (id == 0) isTop.set(true);
- int leftI = x-1;
- int rightI = x+17;
- int topI = y-1;
- int bottomI = y+17;
+ int leftI = x - 1;
+ int rightI = x + 17;
+ int topI = y - 1;
+ int bottomI = y + 17;
lowestY.set(Math.max(bottomI, lowestY.get()));
- if(mouseX > leftI && mouseX < rightI) {
- if(mouseY > topI && mouseY < bottomI) {
+ if (mouseX > leftI && mouseX < rightI) {
+ if (mouseY > topI && mouseY < bottomI) {
tooltipToDisplay.set(manager.jsonToStack(manager.getItemInformation().get(internalname), true));
}
}
- if(getAcquiredItems() != null &&
+ if (getAcquiredItems() != null &&
getAcquiredItems().containsKey(manager.getCurrentProfile()) &&
getAcquiredItems().get(manager.getCurrentProfile()).contains(internalname)) {
return;
}
-
topI = Math.max(topI, top);
bottomI = Math.min(bottomI, bottom);
- Utils.drawTexturedRect(leftI, topI, rightI-leftI, bottomI-topI,
- leftI/(float)width, rightI/(float)width,
- (height-topI)/(float)height, (height-bottomI)/(float)height);
+ Utils.drawTexturedRect(leftI, topI, rightI - leftI, bottomI - topI,
+ leftI / (float) width, rightI / (float) width,
+ (height - topI) / (float) height, (height - bottomI) / (float) height);
}
}
- }, left+5, right, top+1, bottom);
+ }, left + 5, right, top + 1, bottom);
- if(!isTop.get()) {
- if(lowestY.get() == -1) {
+ if (!isTop.get()) {
+ if (lowestY.get() == -1) {
scrollHeight.setValue(0);
} else {
int dist = bottom - lowestY.get() - 10;
- if(dist > 0) {
+ if (dist > 0) {
scrollHeight.setValue(scrollHeight.getValue() - dist);
}
}
@@ -361,7 +363,7 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
itemFramebufferGrayscale.unbindFramebufferTexture();
ItemStack displayStack = tooltipToDisplay.get();
- if(displayStack != null) {
+ if (displayStack != null) {
List<String> text = displayStack.getTooltip(Minecraft.getMinecraft().thePlayer, true);
Utils.drawHoveringText(text, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj);
}
@@ -369,8 +371,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
private String[] getItemList() {
String[] items_arr = new String[items.size()];
- int i=0;
- for(String internalname : items) {
+ int i = 0;
+ for (String internalname : items) {
items_arr[i++] = internalname;
}
return items_arr;
@@ -384,7 +386,7 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
String[] items = getItemList();
iterateItemSlots(new ItemSlotConsumer() {
public void consume(int x, int y, int id) {
- if(id < items.length) {
+ if (id < items.length) {
String internalname = items[id];
ItemStack stack = manager.jsonToStack(manager.getItemInformation().get(internalname));
@@ -401,11 +403,11 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
String[] items = getItemList();
iterateItemSlots(new ItemSlotConsumer() {
public void consume(int x, int y, int id) {
- if(id < items.length) {
+ if (id < items.length) {
String internalname = items[id];
Color color = fgCustomOpacity;
- if(getAcquiredItems() != null &&
+ if (getAcquiredItems() != null &&
getAcquiredItems().containsKey(manager.getCurrentProfile()) &&
getAcquiredItems().get(manager.getCurrentProfile()).contains(internalname)) {
color = fgGold;
@@ -430,11 +432,11 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
* itemPane should be redrawn.
*/
private Framebuffer checkFramebufferSizes(Framebuffer framebuffer, int width, int height, int scaleFactor) {
- int sw = width*scaleFactor;
- int sh = height*scaleFactor;
+ int sw = width * scaleFactor;
+ int sh = height * scaleFactor;
- if(framebuffer == null || framebuffer.framebufferWidth != sw || framebuffer.framebufferHeight != sh) {
- if(framebuffer == null) {
+ if (framebuffer == null || framebuffer.framebufferWidth != sw || framebuffer.framebufferHeight != sh) {
+ if (framebuffer == null) {
framebuffer = new Framebuffer(sw, sh, true);
} else {
framebuffer.createBindFramebuffer(sw, sh);
@@ -471,27 +473,27 @@ public class CollectionLogInfoPane extends ScrollableInfoPane {
private void renderFromImage(Framebuffer framebuffer, int width, int height, int left, int right, int top, int bottom) {
framebuffer.bindFramebufferTexture();
GlStateManager.color(1f, 1f, 1f, 1f);
- Utils.drawTexturedRect(left, top, right-left, bottom-top,
- left/(float)width, right/(float)width,
- (height-top)/(float)height, (height-bottom)/(float)height);
+ Utils.drawTexturedRect(left, top, right - left, bottom - top,
+ left / (float) width, right / (float) width,
+ (height - top) / (float) height, (height - bottom) / (float) height);
framebuffer.unbindFramebufferTexture();
}
- private abstract class ItemSlotConsumer {
+ private abstract static class ItemSlotConsumer {
public abstract void consume(int x, int y, int id);
}
public void iterateItemSlots(ItemSlotConsumer itemSlotConsumer, int left, int right, int top, int bottom) {
- int scrolledTop = top-scrollHeight.getValue();
+ int scrolledTop = top - scrollHeight.getValue();
int id = 0;
- int extraSize = overlay.ITEM_SIZE+overlay.ITEM_PADDING;
- for(int y=scrolledTop; y<bottom; y+=extraSize) {
- for(int x=left; x<right-extraSize; x+=extraSize) {
- if(y > top-extraSize) {
+ int extraSize = NEUOverlay.ITEM_SIZE + NEUOverlay.ITEM_PADDING;
+ for (int y = scrolledTop; y < bottom; y += extraSize) {
+ for (int x = left; x < right - extraSize; x += extraSize) {
+ if (y > top - extraSize) {
itemSlotConsumer.consume(x, y, id);
}
- if(++id >= items.size()) {
+ if (++id >= items.size()) {
return;
}
}