From 2c0292c3e76e5862176d6ffb2acc2c515e167644 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Mon, 20 Jan 2020 09:42:39 -0800 Subject: [PATCH] Add back in ItemPanel.items as static * Fixes crash in ThermalDyanmics [probably] --- build/build.properties | 2 +- src/codechicken/nei/BookmarkPanel.java | 7 +++- src/codechicken/nei/ItemPanel.java | 36 ++++++++++++------- src/codechicken/nei/SearchField.java | 2 +- .../nei/config/GuiItemIconDumper.java | 10 +++--- .../nei/config/ItemPanelDumper.java | 6 ++-- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/build/build.properties b/build/build.properties index 73683b9ab..3df3bb545 100644 --- a/build/build.properties +++ b/build/build.properties @@ -2,4 +2,4 @@ mc_version=1.7.10 forge_version=10.13.4.1614-1.7.10 ccl_version=1.1.3.138 ccc_version=1.0.7.+ -mod_version=2.0.0-beta-1-GTNH +mod_version=2.0.0-beta-2-GTNH diff --git a/src/codechicken/nei/BookmarkPanel.java b/src/codechicken/nei/BookmarkPanel.java index 55d757e8f..308759a36 100644 --- a/src/codechicken/nei/BookmarkPanel.java +++ b/src/codechicken/nei/BookmarkPanel.java @@ -26,8 +26,13 @@ public void init() { super.init(); } + @Override + protected void setItems() { + realItems = _items; + } + public String getLabelText() { - return super.getLabelText() + " [" + items.size() + "]"; + return super.getLabelText() + " [" + realItems.size() + "]"; } public void addOrRemoveItem(ItemStack item) { diff --git a/src/codechicken/nei/ItemPanel.java b/src/codechicken/nei/ItemPanel.java index d4d2a7eb4..a3b2c3e84 100644 --- a/src/codechicken/nei/ItemPanel.java +++ b/src/codechicken/nei/ItemPanel.java @@ -17,17 +17,22 @@ import static codechicken.nei.NEIClientConfig.canPerformAction; public class ItemPanel extends Widget { + /** + * Backwards compat :-/ + */ + public static ArrayList items = new ArrayList<>(); + /** * Should not be externally modified, use updateItemList */ - public ArrayList items = new ArrayList<>(); + public ArrayList realItems = new ArrayList<>(); /** * Swapped into visible items on update */ - protected ArrayList _items = items; + protected ArrayList _items = realItems; public ArrayList getItems() { - return items; + return realItems; } public static void updateItemList(ArrayList newItems) { @@ -40,7 +45,7 @@ public class ItemPanelSlot public int slotIndex; public ItemPanelSlot(int index) { - item = items.get(index); + item = realItems.get(index); slotIndex = index; } } @@ -145,8 +150,15 @@ public String getLabelText() { return pageLabel.text = "(" + getPage() + "/" + getNumPages() + ")"; } + protected void setItems() { + realItems = _items; + + // Backwards compat + ItemPanels.itemPanel._items = _items; + } + public void resize(GuiContainer gui) { - items = _items; + setItems(); final int buttonHeight = 16; final int buttonWidth = 16; @@ -185,9 +197,9 @@ private void calculatePage() { if (itemsPerPage == 0) numPages = 0; else - numPages = (int) Math.ceil((float) items.size() / (float) itemsPerPage); + numPages = (int) Math.ceil((float) realItems.size() / (float) itemsPerPage); - if (firstIndex >= items.size()) + if (firstIndex >= realItems.size()) firstIndex = 0; if (numPages == 0) @@ -236,13 +248,13 @@ public void draw(int mousex, int mousey) { GuiContainerManager.enableMatrixStackLogging(); int index = firstIndex; - for (int i = 0; i < rows * columns && index < items.size(); i++) { + for (int i = 0; i < rows * columns && index < realItems.size(); i++) { if (validSlotMap[i]) { Rectangle4i rect = getSlotRect(i); if (rect.contains(mousex, mousey)) drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight - GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, items.get(index)); + GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, realItems.get(index)); index++; } @@ -416,7 +428,7 @@ public ItemStack getStackMouseOver(int mousex, int mousey) { public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) { int index = firstIndex; - for (int i = 0; i < rows * columns && index < items.size(); i++) + for (int i = 0; i < rows * columns && index < realItems.size(); i++) if (validSlotMap[i]) { if (getSlotRect(i).contains(mousex, mousey)) return new ItemPanelSlot(index); @@ -430,13 +442,13 @@ public void scroll(int i) { if (itemsPerPage != 0) { int oldIndex = firstIndex; firstIndex += i * itemsPerPage; - if (firstIndex >= items.size()) + if (firstIndex >= realItems.size()) firstIndex = 0; if (firstIndex < 0) if (oldIndex > 0) firstIndex = 0; else - firstIndex = (items.size() - 1) / itemsPerPage * itemsPerPage; + firstIndex = (realItems.size() - 1) / itemsPerPage * itemsPerPage; calculatePage(); } diff --git a/src/codechicken/nei/SearchField.java b/src/codechicken/nei/SearchField.java index c34a5ddc8..9c04d7ecb 100644 --- a/src/codechicken/nei/SearchField.java +++ b/src/codechicken/nei/SearchField.java @@ -64,7 +64,7 @@ public static boolean searchInventories() { @Override public int getTextColour() { - if(ItemPanels.itemPanel.items.size() == 0) { + if(ItemPanels.itemPanel.realItems.size() == 0) { return focused() ? 0xFFcc3300 : 0xFF993300; } else { return focused() ? 0xFFE0E0E0 : 0xFF909090; diff --git a/src/codechicken/nei/config/GuiItemIconDumper.java b/src/codechicken/nei/config/GuiItemIconDumper.java index 083799747..fe180a52a 100644 --- a/src/codechicken/nei/config/GuiItemIconDumper.java +++ b/src/codechicken/nei/config/GuiItemIconDumper.java @@ -100,10 +100,10 @@ private void drawItems() { GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glColor4f(1, 1, 1, 1); - for(int i = 0; drawIndex < ItemPanels.itemPanel.items.size() && i < fit; drawIndex++, i++) { + for(int i = 0; drawIndex < ItemPanels.itemPanel.realItems.size() && i < fit; drawIndex++, i++) { int x = i%cols * 18; int y = i/cols * 18; - GuiContainerManager.drawItem(x+1, y+1, ItemPanels.itemPanel.items.get(drawIndex)); + GuiContainerManager.drawItem(x+1, y+1, ItemPanels.itemPanel.realItems.get(drawIndex)); } GL11.glFlush(); @@ -114,13 +114,13 @@ private void exportItems() throws IOException { int rows = img.getHeight() / boxSize; int cols = img.getWidth() / boxSize; int fit = rows*cols; - for(int i = 0; parseIndex < ItemPanels.itemPanel.items.size() && i < fit; parseIndex++, i++) { + for(int i = 0; parseIndex < ItemPanels.itemPanel.realItems.size() && i < fit; parseIndex++, i++) { int x = i%cols * boxSize; int y = i/cols * boxSize; - exportImage(dir, img.getSubimage(x+borderSize, y+borderSize, iconSize, iconSize), ItemPanels.itemPanel.items.get(parseIndex)); + exportImage(dir, img.getSubimage(x+borderSize, y+borderSize, iconSize, iconSize), ItemPanels.itemPanel.realItems.get(parseIndex)); } - if(parseIndex >= ItemPanels.itemPanel.items.size()) + if(parseIndex >= ItemPanels.itemPanel.realItems.size()) returnScreen(new ChatComponentTranslation(opt.fullName()+".icon.dumped", "dumps/itempanel_icons")); } diff --git a/src/codechicken/nei/config/ItemPanelDumper.java b/src/codechicken/nei/config/ItemPanelDumper.java index 6e61ed180..b51ac5477 100644 --- a/src/codechicken/nei/config/ItemPanelDumper.java +++ b/src/codechicken/nei/config/ItemPanelDumper.java @@ -36,7 +36,7 @@ public String[] header() { @Override public Iterable dump(int mode) { LinkedList list = new LinkedList<>(); - for (ItemStack stack : ItemPanels.itemPanel.items) + for (ItemStack stack : ItemPanels.itemPanel.realItems) list.add(new String[]{ Item.itemRegistry.getNameForObject(stack.getItem()), Integer.toString(Item.getIdFromItem(stack.getItem())), @@ -123,7 +123,7 @@ else if (getMode() == 1) public void dumpNBT(File file) throws IOException { NBTTagList list = new NBTTagList(); - for (ItemStack stack : ItemPanels.itemPanel.items) + for (ItemStack stack : ItemPanels.itemPanel.realItems) list.appendTag(stack.writeToNBT(new NBTTagCompound())); NBTTagCompound tag = new NBTTagCompound(); @@ -134,7 +134,7 @@ public void dumpNBT(File file) throws IOException { public void dumpJson(File file) throws IOException { PrintWriter p = new PrintWriter(file); - for (ItemStack stack : ItemPanels.itemPanel.items) { + for (ItemStack stack : ItemPanels.itemPanel.realItems) { NBTTagCompound tag = stack.writeToNBT(new NBTTagCompound()); tag.removeTag("Count"); p.println(tag);