Skip to content

Commit

Permalink
Add back in ItemPanel.items as static
Browse files Browse the repository at this point in the history
* Fixes crash in ThermalDyanmics [probably]
  • Loading branch information
mitchej123 committed Jan 20, 2020
1 parent 3c5e180 commit 2c0292c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion src/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 24 additions & 12 deletions src/codechicken/nei/ItemPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@
import static codechicken.nei.NEIClientConfig.canPerformAction;

public class ItemPanel extends Widget {
/**
* Backwards compat :-/
*/
public static ArrayList<ItemStack> items = new ArrayList<>();

/**
* Should not be externally modified, use updateItemList
*/
public ArrayList<ItemStack> items = new ArrayList<>();
public ArrayList<ItemStack> realItems = new ArrayList<>();
/**
* Swapped into visible items on update
*/
protected ArrayList<ItemStack> _items = items;
protected ArrayList<ItemStack> _items = realItems;

public ArrayList<ItemStack> getItems() {
return items;
return realItems;
}

public static void updateItemList(ArrayList<ItemStack> newItems) {
Expand All @@ -40,7 +45,7 @@ public class ItemPanelSlot
public int slotIndex;

public ItemPanelSlot(int index) {
item = items.get(index);
item = realItems.get(index);
slotIndex = index;
}
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/codechicken/nei/SearchField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/codechicken/nei/config/GuiItemIconDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"));
}

Expand Down
6 changes: 3 additions & 3 deletions src/codechicken/nei/config/ItemPanelDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String[] header() {
@Override
public Iterable<String[]> dump(int mode) {
LinkedList<String[]> 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())),
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 2c0292c

Please sign in to comment.