protected boolean addItemStackToInventory(IHopper hopper, ItemStack stack)
{
for(int i=0;i<hopper.getSizeInventory();++i)
{
ItemStack hopperSlot = hopper.getStackInSlot(i);
if(hopperSlot!=null && hopperSlot.stackSize<hopper.getInventoryStackLimit() && hopperSlot.getItem() == stack.getItem() && hopperSlot.getItemDamage() == stack.getItemDamage())
{
if(hopperSlot.stackSize + stack.stackSize<=hopper.getInventoryStackLimit())
{
hopperSlot.stackSize+=stack.stackSize;
return true;
}
else
{
int newSize=hopper.getInventoryStackLimit()-hopperSlot.stackSize;
hopperSlot.stackSize=hopper.getInventoryStackLimit();
stack.stackSize-=newSize;
}
}
else if(hopperSlot==null)
{
if(stack.stackSize<=hopper.getInventoryStackLimit())
{
hopper.setInventorySlotContents(i, stack);
return true;
}
else
{
ItemStack stackAdd = stack.splitStack(hopper.getInventoryStackLimit());
hopper.setInventorySlotContents(i, stackAdd);
}
}
}
return false;
}
Display More