A stack in the inventory reports as empty? (user reported crash)
AlexiyOrlov opened this issue ยท 2 comments
A user reported a crash for my mod when my pipe tries to insert an item into a Stockpile barrel. https://pastebin.com/EqrJbeFi.
Looks like my pipe thinks that the barrel is always empty, thus it always tries to insert an item. Here is the function which I use to check whether a pipe can insert an item:
private boolean canInsertInto(Inventory inventory, PipedItem item)
{
if(inventory instanceof ChestBlockEntity)
{
ChestBlockEntity chestBlockEntity= (ChestBlockEntity) inventory;
inventory= ChestBlock.getInventory((ChestBlock) Blocks.CHEST,chestBlockEntity.getCachedState(),chestBlockEntity.getWorld(),chestBlockEntity.getPos(),true);
}
if(inventory!=null)
{
ItemStack stack = item.getContent();
for (int i = 0; i < inventory.size(); i++)
{
ItemStack next = inventory.getStack(i);
int count = next.getCount();
if (Functions.areItemTypesEqual(stack, next) && count < next.getMaxCount() && count + stack.getCount() <= next.getMaxCount())
{
return true;
}
}
for (int i = 0; i < inventory.size(); i++)
{
if (inventory.getStack(i).isEmpty())
{
return true;
}
}
}
return false;
}
Unfortunately that's not a foolproof way to test if the inventory can accept a given item - you'd also need to check Inventory.isValid(int slot, ItemStack stack)
with the (copied) combined stack.