For a feature in my mod, I need to loop through a (trapped) chest, and count the total number of items in the inventory.
For some reason, it will always result to 0, even if there are items in the inventory.
When using the debugger, and look at the inventory inside the capability, all slots show "1xtile.air@0"
This is my code for the function. Outside the function I already ensure that there is a chest at the position.
private int countChest(BlockPos pos) {
TileEntityChest chest = (TileEntityChest) world.getTileEntity(pos);
IItemHandler capability = chest.getSingleChestHandler();
int val = 0;
for(int i = 0; i < capability.getSlots(); i++) {
val += capability.getStackInSlot(i).getCount();
}
return val;
}