Fixed a crash with filter list being null

This commit is contained in:
DarkGuardsman 2013-11-03 01:34:18 -05:00
parent d124b8ab33
commit 1bc39b050a

View file

@ -18,24 +18,24 @@ public class InvInteractionHelper
{ {
World world; World world;
Vector3 location; Vector3 location;
List<ItemStack> filterItems; List<ItemStack> filteredItems;
boolean inverted; boolean inverted;
public InvInteractionHelper(World world, Vector3 location, List<ItemStack> filters, boolean inverted) public InvInteractionHelper(World world, Vector3 location, List<ItemStack> filters, boolean inverted)
{ {
this.world = world; this.world = world;
this.location = location; this.location = location;
this.filterItems = filters; this.filteredItems = filters;
if (filterItems == null) if (filteredItems == null)
{ {
filterItems = new ArrayList<ItemStack>(); filteredItems = new ArrayList<ItemStack>();
} }
this.inverted = inverted; this.inverted = inverted;
} }
public void setFilter(List<ItemStack> filters, boolean inverted) public void setFilter(List<ItemStack> filters, boolean inverted)
{ {
this.filterItems = filters; this.filteredItems = filters;
this.inverted = inverted; this.inverted = inverted;
} }
@ -304,7 +304,7 @@ public class InvInteractionHelper
{ {
ItemStack itemStack = inventory.getStackInSlot(slotIndex).copy(); ItemStack itemStack = inventory.getStackInSlot(slotIndex).copy();
if (this.filterItems.size() == 0 || this.isFiltering(itemStack)) if (this.getFilters().size() == 0 || this.isFiltering(itemStack))
{ {
amount = Math.min(amount, itemStack.stackSize); amount = Math.min(amount, itemStack.stackSize);
itemStack.stackSize = amount; itemStack.stackSize = amount;
@ -319,13 +319,13 @@ public class InvInteractionHelper
/** is the item being restricted to a filter set */ /** is the item being restricted to a filter set */
public boolean isFiltering(ItemStack itemStack) public boolean isFiltering(ItemStack itemStack)
{ {
if (this.filterItems != null && itemStack != null) if (this.getFilters() != null && itemStack != null)
{ {
for (int i = 0; i < filterItems.size(); i++) for (int i = 0; i < getFilters().size(); i++)
{ {
if (filterItems.get(i) != null) if (getFilters().get(i) != null)
{ {
if (filterItems.get(i).isItemEqual(itemStack)) if (getFilters().get(i).isItemEqual(itemStack))
{ {
return !inverted; return !inverted;
} }
@ -336,4 +336,13 @@ public class InvInteractionHelper
return inverted; return inverted;
} }
public List<ItemStack> getFilters()
{
if (this.filteredItems == null)
{
this.filteredItems = new ArrayList<ItemStack>();
}
return this.filteredItems;
}
} }