Skip to content

Instantly share code, notes, and snippets.

@dazsim
Created July 2, 2016 10:04
Show Gist options
  • Save dazsim/f38b33fad711292459551adb22473916 to your computer and use it in GitHub Desktop.
Save dazsim/f38b33fad711292459551adb22473916 to your computer and use it in GitHub Desktop.
item handler code insertItem
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (count == 0)
{
this.barrelContents[0]=stack;
count = stack.stackSize;
}
if (count == size)
{
//barrel is full
return stack;
}
if (this.barrelContents[0].isItemEqual(stack))
{
if (stack.stackSize+count<=size)
{
//input stack will not fill barrel
count+=stack.stackSize;
return null;
} else if (stack.stackSize+count>size)
{
//input stack will fill barrel
int a = size - count;
count = size;
stack.stackSize -= a;
return stack;
}
}
return stack;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment