From 7c00af18febf6c0b833c7633b4fb60a9a1bb93af Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sat, 16 Oct 2021 15:50:41 -0400 Subject: Code Clean Up (#2) * intellij code clean up * optimize imports * format * intellij suggestions * fix empty catch issues --- .../miscgui/GuiInvButtonEditor.java | 399 ++++++++++----------- 1 file changed, 197 insertions(+), 202 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java index 22a17c9f..07f514cc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java @@ -1,13 +1,11 @@ package io.github.moulberry.notenoughupdates.miscgui; import com.google.gson.*; -import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.GlScissorStack; import io.github.moulberry.notenoughupdates.core.GuiElementTextField; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import io.github.moulberry.notenoughupdates.options.NEUConfig; -import io.github.moulberry.notenoughupdates.util.TexLoc; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -31,8 +29,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.util.*; import java.util.List; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; @@ -48,8 +46,8 @@ public class GuiInvButtonEditor extends GuiScreen { private static final String sharePrefix = "NEUBUTTONS/"; - private int xSize = 176; - private int ySize = 166; + private final int xSize = 176; + private final int ySize = 166; private int guiLeft; private int guiTop; @@ -58,15 +56,16 @@ public class GuiInvButtonEditor extends GuiScreen { private static final int ICON_TYPES = 3; private int iconTypeIndex = 0; - private int editorXSize = 150; - private int editorYSize = 204; + private final int editorXSize = 150; + private final int editorYSize = 204; private int editorLeft; private int editorTop; - private GuiElementTextField commandTextField = new GuiElementTextField("", editorXSize-14, 16, GuiElementTextField.SCALE_TEXT); - private GuiElementTextField iconTextField = new GuiElementTextField("", editorXSize-14, 16, GuiElementTextField.SCALE_TEXT); + private final GuiElementTextField commandTextField = new GuiElementTextField("", editorXSize - 14, 16, GuiElementTextField.SCALE_TEXT); + private final GuiElementTextField iconTextField = new GuiElementTextField("", editorXSize - 14, 16, GuiElementTextField.SCALE_TEXT); private static final HashSet prioritisedIcons = new HashSet<>(); + static { prioritisedIcons.add("WORKBENCH"); prioritisedIcons.add("LEATHER_CHESTPLATE"); @@ -91,6 +90,7 @@ public class GuiInvButtonEditor extends GuiScreen { private static HashMap extraIcons = null; private static final HashMap skullIcons = new HashMap<>(); + static { skullIcons.put("personal bank", "skull:e36e94f6c34a35465fce4a90f2e25976389eb9709a12273574ff70fd4daa6852"); skullIcons.put("skyblock hub", "skull:d7cc6687423d0570d556ac53e0676cb563bbdd9717cd8269bdebed6f6d4e7bf8"); @@ -129,31 +129,30 @@ public class GuiInvButtonEditor extends GuiScreen { private static void reloadExtraIcons() { extraIcons = new HashMap<>(); - try(BufferedReader reader = new BufferedReader(new InputStreamReader( + try (BufferedReader reader = new BufferedReader(new InputStreamReader( Minecraft.getMinecraft().getResourceManager().getResource(EXTRA_ICONS_JSON).getInputStream(), StandardCharsets.UTF_8))) { JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); - for(Map.Entry entry : json.entrySet()) { - if(entry.getValue().isJsonPrimitive()) { - extraIcons.put(entry.getKey(), "extra:"+entry.getValue().getAsString()); + for (Map.Entry entry : json.entrySet()) { + if (entry.getValue().isJsonPrimitive()) { + extraIcons.put(entry.getKey(), "extra:" + entry.getValue().getAsString()); } } - } catch(Exception e) { - } + } catch (Exception ignored) {} } private static void reloadPresets() { presets = new LinkedHashMap<>(); - try(BufferedReader reader = new BufferedReader(new InputStreamReader( + try (BufferedReader reader = new BufferedReader(new InputStreamReader( Minecraft.getMinecraft().getResourceManager().getResource(PRESETS_JSON).getInputStream(), StandardCharsets.UTF_8))) { JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); - for(Map.Entry entry : json.entrySet()) { - if(entry.getValue().isJsonArray()) { + for (Map.Entry entry : json.entrySet()) { + if (entry.getValue().isJsonArray()) { JsonArray arr = entry.getValue().getAsJsonArray(); List buttons = new ArrayList<>(); - for(int i=0; i prioritisingComparator = (o1, o2) -> { boolean c1 = prioritisedIcons.contains(o1); boolean c2 = prioritisedIcons.contains(o2); - if(c1 && !c2) return -1; - if(!c1 && c2) return 1; + if (c1 && !c2) return -1; + if (!c1 && c2) return 1; return o1.compareTo(o2); }; private final List searchedIcons = new ArrayList<>(); - private LerpingInteger itemScroll = new LerpingInteger(0, 100); + private final LerpingInteger itemScroll = new LerpingInteger(0, 100); private NEUConfig.InventoryButton editingButton = null; - private static HashMap skullMap = new HashMap<>(); + private static final HashMap skullMap = new HashMap<>(); public static void renderIcon(String icon, int x, int y) { - if(extraIcons == null) { + if (extraIcons == null) { reloadExtraIcons(); } - if(icon.startsWith("extra:")) { + if (icon.startsWith("extra:")) { String name = icon.substring("extra:".length()); - ResourceLocation resourceLocation = new ResourceLocation("notenoughupdates:invbuttons/extraicons/"+name+".png"); + ResourceLocation resourceLocation = new ResourceLocation("notenoughupdates:invbuttons/extraicons/" + name + ".png"); Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation); GlStateManager.color(1, 1, 1, 1); Utils.drawTexturedRect(x, y, 16, 16, GL11.GL_NEAREST); @@ -198,11 +196,11 @@ public class GuiInvButtonEditor extends GuiScreen { ItemStack stack = getStack(icon); float scale = 1; - if(icon.startsWith("skull:")) { + if (icon.startsWith("skull:")) { scale = 1.2f; } GlStateManager.pushMatrix(); - GlStateManager.translate(x+8, y+8, 0); + GlStateManager.translate(x + 8, y + 8, 0); GlStateManager.scale(scale, scale, 1); GlStateManager.translate(-8, -8, 0); Utils.drawItemStack(stack, 0, 0); @@ -211,11 +209,11 @@ public class GuiInvButtonEditor extends GuiScreen { } public static ItemStack getStack(String icon) { - if(icon.startsWith("extra:")) { + if (icon.startsWith("extra:")) { return null; - } else if(icon.startsWith("skull:")) { + } else if (icon.startsWith("skull:")) { String link = icon.substring("skull:".length()); - if(skullMap.containsKey(link)) return skullMap.get(link); + if (skullMap.containsKey(link)) return skullMap.get(link); ItemStack render = new ItemStack(Items.skull, 1, 3); NBTTagCompound nbt = new NBTTagCompound(); @@ -228,7 +226,7 @@ public class GuiInvButtonEditor extends GuiScreen { skullOwner.setString("Id", uuid); skullOwner.setString("Name", uuid); - String display = "{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/"+link+"\"}}}"; + String display = "{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + link + "\"}}}"; String displayB64 = Base64.getEncoder().encodeToString(display.getBytes()); textures_0.setString("Value", displayB64); @@ -252,26 +250,26 @@ public class GuiInvButtonEditor extends GuiScreen { super.drawDefaultBackground(); - guiLeft = width/2 - xSize/2; - guiTop = height/2 - ySize/2; + guiLeft = width / 2 - xSize / 2; + guiTop = height / 2 - ySize / 2; GlStateManager.enableDepth(); Minecraft.getMinecraft().getTextureManager().bindTexture(INVENTORY); GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, xSize/256f, 0, ySize/256f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, xSize / 256f, 0, ySize / 256f, GL11.GL_NEAREST); - for(NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - int x = guiLeft+button.x; - int y = guiTop+button.y; - if(button.anchorRight) { + for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { + int x = guiLeft + button.x; + int y = guiTop + button.y; + if (button.anchorRight) { x += xSize; } - if(button.anchorBottom) { + if (button.anchorBottom) { y += ySize; } - if(button.isActive()) { + if (button.isActive()) { GlStateManager.color(1, 1, 1, 1f); } else { GlStateManager.color(1, 1, 1, 0.5f); @@ -279,177 +277,178 @@ public class GuiInvButtonEditor extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR); Utils.drawTexturedRect(x, y, 18, 18, - button.backgroundIndex*18/256f, (button.backgroundIndex*18+18)/256f, 18/256f, 36/256f, GL11.GL_NEAREST); + button.backgroundIndex * 18 / 256f, (button.backgroundIndex * 18 + 18) / 256f, 18 / 256f, 36 / 256f, GL11.GL_NEAREST); - if(button.isActive()) { - if(button.icon != null && !button.icon.trim().isEmpty()) { + if (button.isActive()) { + if (button.icon != null && !button.icon.trim().isEmpty()) { GlStateManager.enableDepth(); - renderIcon(button.icon, x+1, y+1); + renderIcon(button.icon, x + 1, y + 1); } } else { - fontRendererObj.drawString("+", x+6, y+5, 0xffcccccc); + fontRendererObj.drawString("+", x + 6, y + 5, 0xffcccccc); } } Minecraft.getMinecraft().getTextureManager().bindTexture(custom_ench_colour); GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(guiLeft-88-2-22, guiTop+2, 88, 20, 64/217f, 152/217f, 48/78f, 68/78f, GL11.GL_NEAREST); - Utils.drawTexturedRect(guiLeft-88-2-22, guiTop+2+24, 88, 20, 64/217f, 152/217f, 48/78f, 68/78f, GL11.GL_NEAREST); - Utils.drawStringCenteredScaledMaxWidth("Load preset", fontRendererObj, guiLeft-44-2-22, guiTop+8, false, 86, 4210752); - Utils.drawStringCenteredScaledMaxWidth("from Clipboard", fontRendererObj, guiLeft-44-2-22, guiTop+16, false, 86, 4210752); - Utils.drawStringCenteredScaledMaxWidth("Save preset", fontRendererObj, guiLeft-44-2-22, guiTop+8+24, false, 86, 4210752); - Utils.drawStringCenteredScaledMaxWidth("to Clipboard", fontRendererObj, guiLeft-44-2-22, guiTop+16+24, false, 86, 4210752); - - if(!validShareContents()) { - Gui.drawRect(guiLeft-88-2-22, guiTop+2, guiLeft-2-22, guiTop+2+20, 0x80000000); + Utils.drawTexturedRect(guiLeft - 88 - 2 - 22, guiTop + 2, 88, 20, 64 / 217f, 152 / 217f, 48 / 78f, 68 / 78f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft - 88 - 2 - 22, guiTop + 2 + 24, 88, 20, 64 / 217f, 152 / 217f, 48 / 78f, 68 / 78f, GL11.GL_NEAREST); + Utils.drawStringCenteredScaledMaxWidth("Load preset", fontRendererObj, guiLeft - 44 - 2 - 22, guiTop + 8, false, 86, 4210752); + Utils.drawStringCenteredScaledMaxWidth("from Clipboard", fontRendererObj, guiLeft - 44 - 2 - 22, guiTop + 16, false, 86, 4210752); + Utils.drawStringCenteredScaledMaxWidth("Save preset", fontRendererObj, guiLeft - 44 - 2 - 22, guiTop + 8 + 24, false, 86, 4210752); + Utils.drawStringCenteredScaledMaxWidth("to Clipboard", fontRendererObj, guiLeft - 44 - 2 - 22, guiTop + 16 + 24, false, 86, 4210752); + + if (!validShareContents()) { + Gui.drawRect(guiLeft - 88 - 2 - 22, guiTop + 2, guiLeft - 2 - 22, guiTop + 2 + 20, 0x80000000); } GlStateManager.color(1, 1, 1, 1); - if(presets != null) { + if (presets != null) { Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR); - Utils.drawTexturedRect(guiLeft+xSize+22, guiTop, 80, ySize, - editorXSize/256f, (editorXSize+80)/256f, 41/256f, (41+ySize)/256f, GL11.GL_NEAREST); - Utils.drawStringCenteredScaledMaxWidth("\u00a7nPresets", fontRendererObj, guiLeft+xSize+22+40, guiTop+10, false, 70, 0xffa0a0a0); + Utils.drawTexturedRect(guiLeft + xSize + 22, guiTop, 80, ySize, + editorXSize / 256f, (editorXSize + 80) / 256f, 41 / 256f, (41 + ySize) / 256f, GL11.GL_NEAREST); + Utils.drawStringCenteredScaledMaxWidth("\u00a7nPresets", fontRendererObj, guiLeft + xSize + 22 + 40, guiTop + 10, false, 70, 0xffa0a0a0); int index = 0; - for(String presetName : presets.keySet()) { - Utils.drawStringCenteredScaledMaxWidth(presetName, fontRendererObj, guiLeft+xSize+22+40, guiTop+25+10*(index++), + for (String presetName : presets.keySet()) { + Utils.drawStringCenteredScaledMaxWidth(presetName, fontRendererObj, guiLeft + xSize + 22 + 40, guiTop + 25 + 10 * (index++), false, 70, 0xff909090); } } - if(editingButton != null) { - int x = guiLeft+editingButton.x; - int y = guiTop+editingButton.y; - if(editingButton.anchorRight) { + if (editingButton != null) { + int x = guiLeft + editingButton.x; + int y = guiTop + editingButton.y; + if (editingButton.anchorRight) { x += xSize; } - if(editingButton.anchorBottom) { + if (editingButton.anchorBottom) { y += ySize; } GlStateManager.translate(0, 0, 300); - editorLeft = x + 8 - editorXSize/2; + editorLeft = x + 8 - editorXSize / 2; editorTop = y + 18 + 2; boolean showArrow = true; - if(editorTop+editorYSize+5 > height) { - editorTop = height-editorYSize-5; + if (editorTop + editorYSize + 5 > height) { + editorTop = height - editorYSize - 5; showArrow = false; } - if(editorLeft < 5) { + if (editorLeft < 5) { editorLeft = 5; showArrow = false; } - if(editorLeft+editorXSize+5 > width) { - editorLeft = width-editorXSize-5; + if (editorLeft + editorXSize + 5 > width) { + editorLeft = width - editorXSize - 5; showArrow = false; } Minecraft.getMinecraft().getTextureManager().bindTexture(EDITOR); GlStateManager.color(1, 1, 1, 1f); - Utils.drawTexturedRect(editorLeft, editorTop, editorXSize, editorYSize, 0, editorXSize/256f, 41/256f, (41+editorYSize)/256f, GL11.GL_NEAREST); + Utils.drawTexturedRect(editorLeft, editorTop, editorXSize, editorYSize, 0, editorXSize / 256f, 41 / 256f, (41 + editorYSize) / 256f, GL11.GL_NEAREST); - if(showArrow) Utils.drawTexturedRect(x+8-3, y+18, 10, 5, 0, 6/256f, 36/256f, 41/256f, GL11.GL_NEAREST); + if (showArrow) + Utils.drawTexturedRect(x + 8 - 3, y + 18, 10, 5, 0, 6 / 256f, 36 / 256f, 41 / 256f, GL11.GL_NEAREST); - fontRendererObj.drawString("Command", editorLeft+7, editorTop+7, 0xffa0a0a0, false); + fontRendererObj.drawString("Command", editorLeft + 7, editorTop + 7, 0xffa0a0a0, false); - commandTextField.setSize(editorXSize-14, 16); + commandTextField.setSize(editorXSize - 14, 16); commandTextField.setText(commandTextField.getText().replaceAll("^ +", "")); - if(commandTextField.getText().startsWith("/")) { + if (commandTextField.getText().startsWith("/")) { commandTextField.setPrependText(""); } else { commandTextField.setPrependText("\u00a77/\u00a7r"); } - commandTextField.render(editorLeft+7, editorTop+19); + commandTextField.render(editorLeft + 7, editorTop + 19); - fontRendererObj.drawString("Background", editorLeft+7, editorTop+40, 0xffa0a0a0, false); + fontRendererObj.drawString("Background", editorLeft + 7, editorTop + 40, 0xffa0a0a0, false); - for(int i=0; i max) scroll = max; + if (scroll > max) scroll = max; - int scrollBarHeight = (int)Math.ceil(3f*54f/(searchedIcons.size()-18)); - if(scrollBarHeight < 0) scrollBarHeight = 54; - if(scrollBarHeight < 2) scrollBarHeight = 2; - int scrollY = (int)Math.floor(54f*((scroll/20f) / ((searchedIcons.size()-18)/6f))); - if(scrollY+scrollBarHeight > 54) scrollY = 54-scrollBarHeight; + int scrollBarHeight = (int) Math.ceil(3f * 54f / (searchedIcons.size() - 18)); + if (scrollBarHeight < 0) scrollBarHeight = 54; + if (scrollBarHeight < 2) scrollBarHeight = 2; + int scrollY = (int) Math.floor(54f * ((scroll / 20f) / ((searchedIcons.size() - 18) / 6f))); + if (scrollY + scrollBarHeight > 54) scrollY = 54 - scrollBarHeight; - Gui.drawRect(editorLeft+137, editorTop+139+scrollY, editorLeft+139, editorTop+139+scrollY+scrollBarHeight, 0xff202020); + Gui.drawRect(editorLeft + 137, editorTop + 139 + scrollY, editorLeft + 139, editorTop + 139 + scrollY + scrollBarHeight, 0xff202020); int endIndex = searchedIcons.size(); - int startIndex = scroll/20*6; - if(startIndex < 0) startIndex = 0; - if(endIndex > startIndex+24) endIndex = startIndex+24; + int startIndex = scroll / 20 * 6; + if (startIndex < 0) startIndex = 0; + if (endIndex > startIndex + 24) endIndex = startIndex + 24; - for(int i=startIndex; i 1) scroll = 8; - if(scroll < -1) scroll = -8; + if (scroll > 1) scroll = 8; + if (scroll < -1) scroll = -8; int delta = Math.abs(itemScroll.getTarget() - itemScroll.getValue()); - float acc = delta/20+1; + float acc = delta / 20 + 1; scroll *= acc; - int max = (searchedIcons.size()-1)/6*20-40; + int max = (searchedIcons.size() - 1) / 6 * 20 - 40; int newTarget = itemScroll.getTarget() + scroll; - if(newTarget > max) newTarget = max; - if(newTarget < 0) newTarget = 0; + if (newTarget > max) newTarget = max; + if (newTarget < 0) newTarget = 0; itemScroll.setTarget(newTarget); itemScroll.resetTimer(); @@ -486,13 +485,13 @@ public class GuiInvButtonEditor extends GuiScreen { private boolean validShareContents() { try { - String base64 = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); + String base64 = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); - if(base64.length() <= sharePrefix.length()) return false; + if (base64.length() <= sharePrefix.length()) return false; try { return new String(Base64.getDecoder().decode(base64)).startsWith(sharePrefix); - } catch (IllegalArgumentException e){ + } catch (IllegalArgumentException e) { return false; } } catch (HeadlessException | IOException | UnsupportedFlavorException | IllegalStateException e) { @@ -504,64 +503,64 @@ public class GuiInvButtonEditor extends GuiScreen { protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); - if(editingButton != null) { - if(mouseX >= editorLeft && mouseX <= editorLeft+editorXSize && + if (editingButton != null) { + if (mouseX >= editorLeft && mouseX <= editorLeft + editorXSize && mouseY >= editorTop & mouseY <= editorTop + editorYSize) { - if(mouseX >= editorLeft+7 && mouseX <= editorLeft+7+commandTextField.getWidth() && - mouseY >= editorTop+12 && mouseY <= editorTop+12+commandTextField.getHeight()) { + if (mouseX >= editorLeft + 7 && mouseX <= editorLeft + 7 + commandTextField.getWidth() && + mouseY >= editorTop + 12 && mouseY <= editorTop + 12 + commandTextField.getHeight()) { commandTextField.mouseClicked(mouseX, mouseY, mouseButton); iconTextField.unfocus(); editingButton.command = commandTextField.getText(); return; } - if(mouseX >= editorLeft+7 && mouseX <= editorLeft+7+iconTextField.getWidth() && - mouseY >= editorTop+50+65 && mouseY <= editorTop+50+65+iconTextField.getHeight()) { + if (mouseX >= editorLeft + 7 && mouseX <= editorLeft + 7 + iconTextField.getWidth() && + mouseY >= editorTop + 50 + 65 && mouseY <= editorTop + 50 + 65 + iconTextField.getHeight()) { iconTextField.mouseClicked(mouseX, mouseY, mouseButton); - if(mouseButton == 1) { + if (mouseButton == 1) { search(); } commandTextField.unfocus(); return; } - if(mouseY >= editorTop+50 && mouseY <= editorTop+50+18) { - for(int i=0; i= editorLeft+7+20*i && mouseX <= editorLeft+7+20*i+18) { + if (mouseY >= editorTop + 50 && mouseY <= editorTop + 50 + 18) { + for (int i = 0; i < BACKGROUND_TYPES; i++) { + if (mouseX >= editorLeft + 7 + 20 * i && mouseX <= editorLeft + 7 + 20 * i + 18) { editingButton.backgroundIndex = i; return; } } } - for(int i=0; i= editorLeft+7+20*i && mouseX <= editorLeft+7+20*i+18 && - mouseY >= editorTop+50+34 && mouseY <= editorTop+50+34+18) { - if(iconTypeIndex != i) { + for (int i = 0; i < ICON_TYPES; i++) { + if (mouseX >= editorLeft + 7 + 20 * i && mouseX <= editorLeft + 7 + 20 * i + 18 && + mouseY >= editorTop + 50 + 34 && mouseY <= editorTop + 50 + 34 + 18) { + if (iconTypeIndex != i) { iconTypeIndex = i; search(); } return; } } - if(mouseX > editorLeft+8 && mouseX < editorLeft+editorXSize-16 && mouseY > editorTop+136 && mouseY < editorTop+196) { - synchronized(searchedIcons) { - int max = (searchedIcons.size()-1)/6*20-40; + if (mouseX > editorLeft + 8 && mouseX < editorLeft + editorXSize - 16 && mouseY > editorTop + 136 && mouseY < editorTop + 196) { + synchronized (searchedIcons) { + int max = (searchedIcons.size() - 1) / 6 * 20 - 40; int scroll = itemScroll.getValue(); - if(scroll > max) scroll = max; + if (scroll > max) scroll = max; int endIndex = searchedIcons.size(); - int startIndex = scroll/20*6; - if(startIndex < 0) startIndex = 0; - if(endIndex > startIndex+24) endIndex = startIndex+24; + int startIndex = scroll / 20 * 6; + if (startIndex < 0) startIndex = 0; + if (endIndex > startIndex + 24) endIndex = startIndex + 24; - for(int i=startIndex; i= x && mouseX <= x+18 && - mouseY >= y && mouseY <= y+18) { + if (mouseX >= x && mouseX <= x + 18 && + mouseY >= y && mouseY <= y + 18) { editingButton.icon = iconS; return; } @@ -572,19 +571,19 @@ public class GuiInvButtonEditor extends GuiScreen { } } - for(NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - int x = guiLeft+button.x; - int y = guiTop+button.y; - if(button.anchorRight) { + for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { + int x = guiLeft + button.x; + int y = guiTop + button.y; + if (button.anchorRight) { x += xSize; } - if(button.anchorBottom) { + if (button.anchorBottom) { y += ySize; } - if(mouseX >= x && mouseY >= y && - mouseX <= x+18 && mouseY <= y+18) { - if(editingButton == button) { + if (mouseX >= x && mouseY >= y && + mouseX <= x + 18 && mouseY <= y + 18) { + if (editingButton == button) { editingButton = null; } else { editingButton = button; @@ -594,7 +593,7 @@ public class GuiInvButtonEditor extends GuiScreen { } } - if(mouseX > guiLeft-2-88-22 && mouseX< guiLeft-2-22) { + if (mouseX > guiLeft - 2 - 88 - 22 && mouseX < guiLeft - 2 - 22) { if (mouseY > guiTop + 2 && mouseY < guiTop + 22) { String base64; @@ -605,12 +604,12 @@ public class GuiInvButtonEditor extends GuiScreen { return; } - if(base64.length() <= sharePrefix.length()) return; + if (base64.length() <= sharePrefix.length()) return; String jsonString; try { jsonString = new String(Base64.getDecoder().decode(base64)); - if(!jsonString.startsWith(sharePrefix)) return; + if (!jsonString.startsWith(sharePrefix)) return; jsonString = jsonString.substring(sharePrefix.length()); } catch (IllegalArgumentException e) { return; @@ -623,13 +622,11 @@ public class GuiInvButtonEditor extends GuiScreen { return; } - List buttons = new ArrayList<>(); System.out.println(presetArray.size()); try { for (int i = 0; i < presetArray.size(); i++) { - JsonElement shittyO = presetArray.get(i); JsonElement lessShittyO = new JsonParser().parse(shittyO.getAsString()); if (lessShittyO.isJsonObject()) { @@ -642,31 +639,29 @@ public class GuiInvButtonEditor extends GuiScreen { NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons = buttons; return; - } catch(JsonParseException | ClassCastException | IllegalStateException e){ + } catch (JsonParseException | ClassCastException | IllegalStateException e) { return; } - } else if (mouseY > guiTop + 26 && mouseY < guiTop + 26 + 20) { List result = NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons; JsonArray jsonArray = new JsonArray(); - for (int i = 0; i < result.size(); i++) { - - jsonArray.add(new JsonPrimitive(NotEnoughUpdates.INSTANCE.manager.gson.toJson(result.get(i), NEUConfig.InventoryButton.class))); + for (NEUConfig.InventoryButton inventoryButton : result) { + jsonArray.add(new JsonPrimitive(NotEnoughUpdates.INSTANCE.manager.gson.toJson(inventoryButton, NEUConfig.InventoryButton.class))); } - String base64String = Base64.getEncoder().encodeToString((sharePrefix+jsonArray).getBytes(StandardCharsets.UTF_8)); + String base64String = Base64.getEncoder().encodeToString((sharePrefix + jsonArray).getBytes(StandardCharsets.UTF_8)); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(base64String), null); return; } } - if(editingButton == null) { + if (editingButton == null) { int index = 0; - for(List buttons : presets.values()) { - if(mouseX >= guiLeft+xSize+22 && mouseX <= guiLeft+xSize+22+80 && - mouseY >= guiTop+21+10*index && mouseY <= guiTop+21+10*index+10) { + for (List buttons : presets.values()) { + if (mouseX >= guiLeft + xSize + 22 && mouseX <= guiLeft + xSize + 22 + 80 && + mouseY >= guiTop + 21 + 10 * index && mouseY <= guiTop + 21 + 10 * index + 10) { NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons = buttons; return; } @@ -681,30 +676,30 @@ public class GuiInvButtonEditor extends GuiScreen { protected void keyTyped(char typedChar, int keyCode) throws IOException { super.keyTyped(typedChar, keyCode); - if(editingButton != null && commandTextField.getFocus()) { + if (editingButton != null && commandTextField.getFocus()) { commandTextField.keyTyped(typedChar, keyCode); editingButton.command = commandTextField.getText(); - } else if(editingButton != null && iconTextField.getFocus()) { + } else if (editingButton != null && iconTextField.getFocus()) { String old = iconTextField.getText().trim(); iconTextField.keyTyped(typedChar, keyCode); String newText = iconTextField.getText().trim(); - if(!old.equalsIgnoreCase(newText)) { + if (!old.equalsIgnoreCase(newText)) { search(); } } } - private ExecutorService searchES = Executors.newSingleThreadExecutor(); - private AtomicInteger searchId = new AtomicInteger(0); + private final ExecutorService searchES = Executors.newSingleThreadExecutor(); + private final AtomicInteger searchId = new AtomicInteger(0); public void search() { final int thisSearchId = searchId.incrementAndGet(); final String searchString = iconTextField.getText(); - if(iconTypeIndex == 0) { - if(searchString.trim().isEmpty()) { - synchronized(searchedIcons) { + if (iconTypeIndex == 0) { + if (searchString.trim().isEmpty()) { + synchronized (searchedIcons) { searchedIcons.clear(); List unsorted = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.getItemInformation().keySet()); @@ -715,64 +710,64 @@ public class GuiInvButtonEditor extends GuiScreen { } searchES.submit(() -> { - if(thisSearchId != searchId.get()) return; + if (thisSearchId != searchId.get()) return; List title = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("title:" + searchString.trim())); - if(thisSearchId != searchId.get()) return; + if (thisSearchId != searchId.get()) return; - if(!searchString.trim().contains(" ")) { + if (!searchString.trim().contains(" ")) { StringBuilder sb = new StringBuilder(); - for(char c : searchString.toCharArray()) { + for (char c : searchString.toCharArray()) { sb.append(c).append(" "); } title.addAll(NotEnoughUpdates.INSTANCE.manager.search("title:" + sb.toString().trim())); } - if(thisSearchId != searchId.get()) return; + if (thisSearchId != searchId.get()) return; List desc = new ArrayList<>(NotEnoughUpdates.INSTANCE.manager.search("desc:" + searchString.trim())); desc.removeAll(title); - if(thisSearchId != searchId.get()) return; + if (thisSearchId != searchId.get()) return; title.sort(prioritisingComparator); desc.sort(prioritisingComparator); - if(thisSearchId != searchId.get()) return; + if (thisSearchId != searchId.get()) return; - synchronized(searchedIcons) { + synchronized (searchedIcons) { searchedIcons.clear(); searchedIcons.addAll(title); searchedIcons.addAll(desc); } }); - } else if(iconTypeIndex == 1) { - if(searchString.trim().isEmpty()) { + } else if (iconTypeIndex == 1) { + if (searchString.trim().isEmpty()) { searchedIcons.clear(); searchedIcons.addAll(skullIcons.values()); return; } - synchronized(searchedIcons) { + synchronized (searchedIcons) { searchedIcons.clear(); - for(Map.Entry entry : skullIcons.entrySet()) { - if(NotEnoughUpdates.INSTANCE.manager.searchString(entry.getKey(), searchString)) { + for (Map.Entry entry : skullIcons.entrySet()) { + if (NotEnoughUpdates.INSTANCE.manager.searchString(entry.getKey(), searchString)) { searchedIcons.add(entry.getValue()); } } } - } else if(iconTypeIndex == 2) { - if(searchString.trim().isEmpty()) { + } else if (iconTypeIndex == 2) { + if (searchString.trim().isEmpty()) { searchedIcons.clear(); searchedIcons.addAll(extraIcons.values()); return; } - synchronized(searchedIcons) { + synchronized (searchedIcons) { searchedIcons.clear(); - for(Map.Entry entry : extraIcons.entrySet()) { - if(NotEnoughUpdates.INSTANCE.manager.searchString(entry.getKey(), searchString)) { + for (Map.Entry entry : extraIcons.entrySet()) { + if (NotEnoughUpdates.INSTANCE.manager.searchString(entry.getKey(), searchString)) { searchedIcons.add(entry.getValue()); } } -- cgit From ea3ec354ba3bb5b4ac64b8032816b8e4c407f099 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 28 Dec 2021 00:49:28 -0500 Subject: more code clean up (#38) --- .../miscgui/GuiInvButtonEditor.java | 95 ++++++++++------------ 1 file changed, 45 insertions(+), 50 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java index 07f514cc..074af960 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java @@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicInteger; import static io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour.custom_ench_colour; public class GuiInvButtonEditor extends GuiScreen { - private static final ResourceLocation INVENTORY = new ResourceLocation("minecraft:textures/gui/container/inventory.png"); private static final ResourceLocation EDITOR = new ResourceLocation("notenoughupdates:invbuttons/editor.png"); private static final ResourceLocation EXTRA_ICONS_JSON = new ResourceLocation("notenoughupdates:invbuttons/extraicons.json"); @@ -64,58 +63,54 @@ public class GuiInvButtonEditor extends GuiScreen { private final GuiElementTextField commandTextField = new GuiElementTextField("", editorXSize - 14, 16, GuiElementTextField.SCALE_TEXT); private final GuiElementTextField iconTextField = new GuiElementTextField("", editorXSize - 14, 16, GuiElementTextField.SCALE_TEXT); - private static final HashSet prioritisedIcons = new HashSet<>(); - - static { - prioritisedIcons.add("WORKBENCH"); - prioritisedIcons.add("LEATHER_CHESTPLATE"); - prioritisedIcons.add("CHEST"); - prioritisedIcons.add("BONE"); - prioritisedIcons.add("ENDER_CHEST"); - prioritisedIcons.add("GOLD_BARDING"); - prioritisedIcons.add("COMPASS"); - prioritisedIcons.add("GOLD_BLOCK"); - prioritisedIcons.add("EMPTY_MAP"); - prioritisedIcons.add("RAW_FISH"); - prioritisedIcons.add("FISHING_ROD"); - prioritisedIcons.add("EMERALD"); - prioritisedIcons.add("IRON_SWORD"); - prioritisedIcons.add("POTION"); - prioritisedIcons.add("NETHER_STAR"); - prioritisedIcons.add("PAINTING"); - prioritisedIcons.add("COMMAND"); - prioritisedIcons.add("BOOK"); - } + private static final HashSet prioritisedIcons = new HashSet() {{ + add("WORKBENCH"); + add("LEATHER_CHESTPLATE"); + add("CHEST"); + add("BONE"); + add("ENDER_CHEST"); + add("GOLD_BARDING"); + add("COMPASS"); + add("GOLD_BLOCK"); + add("EMPTY_MAP"); + add("RAW_FISH"); + add("FISHING_ROD"); + add("EMERALD"); + add("IRON_SWORD"); + add("POTION"); + add("NETHER_STAR"); + add("PAINTING"); + add("COMMAND"); + add("BOOK"); + }}; private static HashMap extraIcons = null; - private static final HashMap skullIcons = new HashMap<>(); - - static { - skullIcons.put("personal bank", "skull:e36e94f6c34a35465fce4a90f2e25976389eb9709a12273574ff70fd4daa6852"); - skullIcons.put("skyblock hub", "skull:d7cc6687423d0570d556ac53e0676cb563bbdd9717cd8269bdebed6f6d4e7bf8"); - skullIcons.put("private island", "skull:c9c8881e42915a9d29bb61a16fb26d059913204d265df5b439b3d792acd56"); - skullIcons.put("castle", "skull:f4559d75464b2e40a518e4de8e6cf3085f0a3ca0b1b7012614c4cd96fed60378"); - skullIcons.put("sirius shack", "skull:7ab83858ebc8ee85c3e54ab13aabfcc1ef2ad446d6a900e471c3f33b78906a5b"); - skullIcons.put("crypts", "skull:25d2f31ba162fe6272e831aed17f53213db6fa1c4cbe4fc827f3963cc98b9"); - skullIcons.put("spiders den", "skull:c754318a3376f470e481dfcd6c83a59aa690ad4b4dd7577fdad1c2ef08d8aee6"); - skullIcons.put("top of the nest", "skull:9d7e3b19ac4f3dee9c5677c135333b9d35a7f568b63d1ef4ada4b068b5a25"); - skullIcons.put("blazing fortress", "skull:c3687e25c632bce8aa61e0d64c24e694c3eea629ea944f4cf30dcfb4fbce071"); - skullIcons.put("blazing fortress magma boss", "skull:38957d5023c937c4c41aa2412d43410bda23cf79a9f6ab36b76fef2d7c429"); - skullIcons.put("the end", "skull:7840b87d52271d2a755dedc82877e0ed3df67dcc42ea479ec146176b02779a5"); - skullIcons.put("the end dragons nest", "skull:a1cd6d2d03f135e7c6b5d6cdae1b3a68743db4eb749faf7341e9fb347aa283b"); - skullIcons.put("the park", "skull:a221f813dacee0fef8c59f76894dbb26415478d9ddfc44c2e708a6d3b7549b"); - skullIcons.put("the park jungle", "skull:79ca3540621c1c79c32bf42438708ff1f5f7d0af9b14a074731107edfeb691c"); - skullIcons.put("the park howling cave", "skull:1832d53997b451635c9cf9004b0f22bb3d99ab5a093942b5b5f6bb4e4de47065"); - skullIcons.put("gold mines", "skull:73bc965d579c3c6039f0a17eb7c2e6faf538c7a5de8e60ec7a719360d0a857a9"); - skullIcons.put("deep caverns", "skull:569a1f114151b4521373f34bc14c2963a5011cdc25a6554c48c708cd96ebfc"); - skullIcons.put("the barn", "skull:4d3a6bd98ac1833c664c4909ff8d2dc62ce887bdcf3cc5b3848651ae5af6b"); - skullIcons.put("mushroom desert", "skull:2116b9d8df346a25edd05f842e7a9345beaf16dca4118abf5a68c75bcaae10"); - skullIcons.put("dungeon hub", "skull:9b56895b9659896ad647f58599238af532d46db9c1b0389b8bbeb70999dab33d"); - skullIcons.put("dwarven mines", "skull:569a1f114151b4521373f34bc14c2963a5011cdc25a6554c48c708cd96ebfc"); - skullIcons.put("hotm heart of the mountain", "skull:86f06eaa3004aeed09b3d5b45d976de584e691c0e9cade133635de93d23b9edb"); - skullIcons.put("bazaar dude", "skull:c232e3820897429157619b0ee099fec0628f602fff12b695de54aef11d923ad7"); - } + private static final HashMap skullIcons = new HashMap() {{ + put("personal bank", "skull:e36e94f6c34a35465fce4a90f2e25976389eb9709a12273574ff70fd4daa6852"); + put("skyblock hub", "skull:d7cc6687423d0570d556ac53e0676cb563bbdd9717cd8269bdebed6f6d4e7bf8"); + put("private island", "skull:c9c8881e42915a9d29bb61a16fb26d059913204d265df5b439b3d792acd56"); + put("castle", "skull:f4559d75464b2e40a518e4de8e6cf3085f0a3ca0b1b7012614c4cd96fed60378"); + put("sirius shack", "skull:7ab83858ebc8ee85c3e54ab13aabfcc1ef2ad446d6a900e471c3f33b78906a5b"); + put("crypts", "skull:25d2f31ba162fe6272e831aed17f53213db6fa1c4cbe4fc827f3963cc98b9"); + put("spiders den", "skull:c754318a3376f470e481dfcd6c83a59aa690ad4b4dd7577fdad1c2ef08d8aee6"); + put("top of the nest", "skull:9d7e3b19ac4f3dee9c5677c135333b9d35a7f568b63d1ef4ada4b068b5a25"); + put("blazing fortress", "skull:c3687e25c632bce8aa61e0d64c24e694c3eea629ea944f4cf30dcfb4fbce071"); + put("blazing fortress magma boss", "skull:38957d5023c937c4c41aa2412d43410bda23cf79a9f6ab36b76fef2d7c429"); + put("the end", "skull:7840b87d52271d2a755dedc82877e0ed3df67dcc42ea479ec146176b02779a5"); + put("the end dragons nest", "skull:a1cd6d2d03f135e7c6b5d6cdae1b3a68743db4eb749faf7341e9fb347aa283b"); + put("the park", "skull:a221f813dacee0fef8c59f76894dbb26415478d9ddfc44c2e708a6d3b7549b"); + put("the park jungle", "skull:79ca3540621c1c79c32bf42438708ff1f5f7d0af9b14a074731107edfeb691c"); + put("the park howling cave", "skull:1832d53997b451635c9cf9004b0f22bb3d99ab5a093942b5b5f6bb4e4de47065"); + put("gold mines", "skull:73bc965d579c3c6039f0a17eb7c2e6faf538c7a5de8e60ec7a719360d0a857a9"); + put("deep caverns", "skull:569a1f114151b4521373f34bc14c2963a5011cdc25a6554c48c708cd96ebfc"); + put("the barn", "skull:4d3a6bd98ac1833c664c4909ff8d2dc62ce887bdcf3cc5b3848651ae5af6b"); + put("mushroom desert", "skull:2116b9d8df346a25edd05f842e7a9345beaf16dca4118abf5a68c75bcaae10"); + put("dungeon hub", "skull:9b56895b9659896ad647f58599238af532d46db9c1b0389b8bbeb70999dab33d"); + put("dwarven mines", "skull:569a1f114151b4521373f34bc14c2963a5011cdc25a6554c48c708cd96ebfc"); + put("hotm heart of the mountain", "skull:86f06eaa3004aeed09b3d5b45d976de584e691c0e9cade133635de93d23b9edb"); + put("bazaar dude", "skull:c232e3820897429157619b0ee099fec0628f602fff12b695de54aef11d923ad7"); + }}; private static LinkedHashMap> presets = null; -- cgit From b09f774d422263ce15b97d6d0804beddf856176d Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sun, 27 Feb 2022 11:53:57 -0500 Subject: feat: improve formating :) --- .../miscgui/GuiInvButtonEditor.java | 1600 +++++++++++--------- 1 file changed, 869 insertions(+), 731 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java index 074af960..7c74c6e2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiInvButtonEditor.java @@ -38,735 +38,873 @@ import java.util.concurrent.atomic.AtomicInteger; import static io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour.custom_ench_colour; public class GuiInvButtonEditor extends GuiScreen { - private static final ResourceLocation INVENTORY = new ResourceLocation("minecraft:textures/gui/container/inventory.png"); - private static final ResourceLocation EDITOR = new ResourceLocation("notenoughupdates:invbuttons/editor.png"); - private static final ResourceLocation EXTRA_ICONS_JSON = new ResourceLocation("notenoughupdates:invbuttons/extraicons.json"); - private static final ResourceLocation PRESETS_JSON = new ResourceLocation("notenoughupdates:invbuttons/presets.json"); - - private static final String sharePrefix = "NEUBUTTONS/"; - - private final int xSize = 176; - private final int ySize = 166; - - private int guiLeft; - private int guiTop; - - private static final int BACKGROUND_TYPES = 5; - private static final int ICON_TYPES = 3; - private int iconTypeIndex = 0; - - private final int editorXSize = 150; - private final int editorYSize = 204; - private int editorLeft; - private int editorTop; - - private final GuiElementTextField commandTextField = new GuiElementTextField("", editorXSize - 14, 16, GuiElementTextField.SCALE_TEXT); - private final GuiElementTextField iconTextField = new GuiElementTextField("", editorXSize - 14, 16, GuiElementTextField.SCALE_TEXT); - - private static final HashSet prioritisedIcons = new HashSet() {{ - add("WORKBENCH"); - add("LEATHER_CHESTPLATE"); - add("CHEST"); - add("BONE"); - add("ENDER_CHEST"); - add("GOLD_BARDING"); - add("COMPASS"); - add("GOLD_BLOCK"); - add("EMPTY_MAP"); - add("RAW_FISH"); - add("FISHING_ROD"); - add("EMERALD"); - add("IRON_SWORD"); - add("POTION"); - add("NETHER_STAR"); - add("PAINTING"); - add("COMMAND"); - add("BOOK"); - }}; - - private static HashMap extraIcons = null; - - private static final HashMap skullIcons = new HashMap() {{ - put("personal bank", "skull:e36e94f6c34a35465fce4a90f2e25976389eb9709a12273574ff70fd4daa6852"); - put("skyblock hub", "skull:d7cc6687423d0570d556ac53e0676cb563bbdd9717cd8269bdebed6f6d4e7bf8"); - put("private island", "skull:c9c8881e42915a9d29bb61a16fb26d059913204d265df5b439b3d792acd56"); - put("castle", "skull:f4559d75464b2e40a518e4de8e6cf3085f0a3ca0b1b7012614c4cd96fed60378"); - put("sirius shack", "skull:7ab83858ebc8ee85c3e54ab13aabfcc1ef2ad446d6a900e471c3f33b78906a5b"); - put("crypts", "skull:25d2f31ba162fe6272e831aed17f53213db6fa1c4cbe4fc827f3963cc98b9"); - put("spiders den", "skull:c754318a3376f470e481dfcd6c83a59aa690ad4b4dd7577fdad1c2ef08d8aee6"); - put("top of the nest", "skull:9d7e3b19ac4f3dee9c5677c135333b9d35a7f568b63d1ef4ada4b068b5a25"); - put("blazing fortress", "skull:c3687e25c632bce8aa61e0d64c24e694c3eea629ea944f4cf30dcfb4fbce071"); - put("blazing fortress magma boss", "skull:38957d5023c937c4c41aa2412d43410bda23cf79a9f6ab36b76fef2d7c429"); - put("the end", "skull:7840b87d52271d2a755dedc82877e0ed3df67dcc42ea479ec146176b02779a5"); - put("the end dragons nest", "skull:a1cd6d2d03f135e7c6b5d6cdae1b3a68743db4eb749faf7341e9fb347aa283b"); - put("the park", "skull:a221f813dacee0fef8c59f76894dbb26415478d9ddfc44c2e708a6d3b7549b"); - put("the park jungle", "skull:79ca3540621c1c79c32bf42438708ff1f5f7d0af9b14a074731107edfeb691c"); - put("the park howling cave", "skull:1832d53997b451635c9cf9004b0f22bb3d99ab5a093942b5b5f6bb4e4de47065"); - put("gold mines", "skull:73bc965d579c3c6039f0a17eb7c2e6faf538c7a5de8e60ec7a719360d0a857a9"); - put("deep caverns", "skull:569a1f114151b4521373f34bc14c2963a5011cdc25a6554c48c708cd96ebfc"); - put("the barn", "skull:4d3a6bd98ac1833c664c4909ff8d2dc62ce887bdcf3cc5b3848651ae5af6b"); - put("mushroom desert", "skull:2116b9d8df346a25edd05f842e7a9345beaf16dca4118abf5a68c75bcaae10"); - put("dungeon hub", "skull:9b56895b9659896ad647f58599238af532d46db9c1b0389b8bbeb70999dab33d"); - put("dwarven mines", "skull:569a1f114151b4521373f34bc14c2963a5011cdc25a6554c48c708cd96ebfc"); - put("hotm heart of the mountain", "skull:86f06eaa3004aeed09b3d5b45d976de584e691c0e9cade133635de93d23b9edb"); - put("bazaar dude", "skull:c232e3820897429157619b0ee099fec0628f602fff12b695de54aef11d923ad7"); - }}; - - private static LinkedHashMap> presets = null; - - public GuiInvButtonEditor() { - super(); - reloadExtraIcons(); - reloadPresets(); - Keyboard.enableRepeatEvents(true); - } - - private static void reloadExtraIcons() { - extraIcons = new HashMap<>(); - - try (BufferedReader reader = new BufferedReader(new InputStreamReader( - Minecraft.getMinecraft().getResourceManager().getResource(EXTRA_ICONS_JSON).getInputStream(), StandardCharsets.UTF_8))) { - JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); - - for (Map.Entry entry : json.entrySet()) { - if (entry.getValue().isJsonPrimitive()) { - extraIcons.put(entry.getKey(), "extra:" + entry.getValue().getAsString()); - } - } - } catch (Exception ignored) {} - } - - private static void reloadPresets() { - presets = new LinkedHashMap<>(); - - try (BufferedReader reader = new BufferedReader(new InputStreamReader( - Minecraft.getMinecraft().getResourceManager().getResource(PRESETS_JSON).getInputStream(), StandardCharsets.UTF_8))) { - JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); - - for (Map.Entry entry : json.entrySet()) { - if (entry.getValue().isJsonArray()) { - JsonArray arr = entry.getValue().getAsJsonArray(); - List buttons = new ArrayList<>(); - for (int i = 0; i < arr.size(); i++) { - JsonObject o = arr.get(i).getAsJsonObject(); - NEUConfig.InventoryButton button = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(o, NEUConfig.InventoryButton.class); - buttons.add(button); - } - presets.put(entry.getKey(), buttons); - } - } - } catch (Exception ignored) {} - } - - private static final Comparator prioritisingComparator = (o1, o2) -> { - boolean c1 = prioritisedIcons.contains(o1); - boolean c2 = prioritisedIcons.contains(o2); - - if (c1 && !c2) return -1; - if (!c1 && c2) return 1; - - return o1.compareTo(o2); - }; - - private final List searchedIcons = new ArrayList<>(); - - private final LerpingInteger itemScroll = new LerpingInteger(0, 100); - - private NEUConfig.InventoryButton editingButton = null; - - private static final HashMap skullMap = new HashMap<>(); - - public static void renderIcon(String icon, int x, int y) { - if (extraIcons == null) { - reloadExtraIcons(); - } - - if (icon.startsWith("extra:")) { - String name = icon.substring("extra:".length()); - ResourceLocation resourceLocation = new ResourceLocation("notenoughupdates:invbuttons/extraicons/" + name + ".png"); - Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(x, y, 16, 16, GL11.GL_NEAREST); - } else { - ItemStack stack = getStack(icon); - - float scale = 1; - if (icon.startsWith("skull:")) { - scale = 1.2f; - } - GlStateManager.pushMatrix(); - GlStateManager.translate(x + 8, y + 8, 0); - GlStateManager.scale(scale, scale, 1); - GlStateManager.translate(-8, -8, 0); - Utils.drawItemStack(stack, 0, 0); - GlStateManager.popMatrix(); - } - } - - public static ItemStack getStack(String icon) { - if (icon.startsWith("extra:")) { - return null; - } else if (icon.startsWith("skull:")) { - String link = icon.substring("skull:".length()); - if (skullMap.containsKey(link)) return skullMap.get(link); - - ItemStack render = new ItemStack(Items.skull, 1, 3); - NBTTagCompound nbt = new NBTTagCompound(); - NBTTagCompound skullOwner = new NBTTagCompound(); - NBTTagCompound properties = new NBTTagCompound(); - NBTTagList textures = new NBTTagList(); - NBTTagCompound textures_0 = new NBTTagCompound(); - - String uuid = UUID.nameUUIDFromBytes(link.getBytes()).toString(); - skullOwner.setString("Id", uuid); - skullOwner.setString("Name", uuid); - - String display = "{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + link + "\"}}}"; - String displayB64 = Base64.getEncoder().encodeToString(display.getBytes()); - - textures_0.setString("Value", displayB64); - textures.appendTag(textures_0); - - properties.setTag("textures", textures); - skullOwner.setTag("Properties", properties); - nbt.setTag("SkullOwner", skullOwner); - render.setTagCompound(nbt); - - skullMap.put(link, render); - return render; - } else { - return NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(icon)); - } - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - - super.drawDefaultBackground(); - - guiLeft = width / 2 - xSize / 2; - guiTop = height / 2 - ySize / 2; - - GlStateManager.enableDepth(); - - Minecraft.getMinecraft().getTextureManager().bindTexture(INVENTORY); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, xSize / 256f, 0, ySize / 256f, GL11.GL_NEAREST); - - for (NEUConfig.InventoryButton button : NotEnoughUpdates.INSTANCE.config.hidden.inventoryButtons) { - int x = guiLeft + button.x; - int y = guiTop + button.y; - if (button.anchorRight) { - x += xSize; - } - if (button.anchorBottom) { - y += ySize; - } - - if (button.isActive()) { - GlStateManager.color(1, 1, 1, 1f); - } else { - GlStateManager.color(1, 1, 1, 0.5f);