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,29 +18,29 @@ 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;
} }
/** Throws the items from the manipulator into the world. /** Throws the items from the manipulator into the world.
* *
* @param outputPosition * @param outputPosition
* @param items */ * @param items */
public void throwItem(Vector3 outputPosition, ItemStack items) public void throwItem(Vector3 outputPosition, ItemStack items)
@ -57,7 +57,7 @@ public class InvInteractionHelper
} }
/** Tries to place an itemStack in a specific position if it is an inventory. /** Tries to place an itemStack in a specific position if it is an inventory.
* *
* @return The ItemStack remained after place attempt */ * @return The ItemStack remained after place attempt */
public ItemStack tryPlaceInPosition(ItemStack itemStack, Vector3 position, ForgeDirection dir) public ItemStack tryPlaceInPosition(ItemStack itemStack, Vector3 position, ForgeDirection dir)
{ {
@ -194,7 +194,7 @@ public class InvInteractionHelper
} }
/** Tries to get an item from a position /** Tries to get an item from a position
* *
* @param position - location of item * @param position - location of item
* @param direction - direction this item is from the original * @param direction - direction this item is from the original
* @param ammount - amount up to one stack to grab * @param ammount - amount up to one stack to grab
@ -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;
}
} }