I have created a block with a TileEntity and when the player right clicks on it with a empty bucket it adds a bucket of milk to their inventory. I have it all working except for some reason when the milk bucket is added to the player's inventory it is invisible until the player interacts with one of the invisible milk buckets.
public void giveMilk(EntityPlayer playerIn) {
if (milkBucketCount > 0) {
if (ItemStack.areItemsEqual(playerIn.inventory.getCurrentItem(), new ItemStack(Items.bucket))) {
this.fillBucket(playerIn);
}
}
}
private void fillBucket(EntityPlayer playerIn) {
ItemStack emptyBuckets = playerIn.inventory.getCurrentItem();
int currentSlot = playerIn.inventory.currentItem;
if (playerIn.capabilities.isCreativeMode) {
return;
}
else if (emptyBuckets.stackSize <= 1)
{
playerIn.inventory.setInventorySlotContents(currentSlot, new ItemStack(Items.milk_bucket));
milkBucketCount--;
}
else
{
if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.milk_bucket)))
{
playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.milk_bucket, 1, 0), false);
}
playerIn.inventory.setInventorySlotContents(currentSlot, new ItemStack(Items.bucket, --emptyBuckets.stackSize));
milkBucketCount--;
}
}
Those two functions are in my TileEntity. The giveMilk() function is called when the block is right clicked on by a player. If the player is only holding one bucket the empty bucket gets replaced with a full milk bucket that is visible, so that works fine while for some reason if the player is holding a stack of empty buckets they get the item but as I said it is invisible.
I did some googling and the only results I found were that it was because of a server/client discrepancy, but I have tried checking to see if (!this.worldObj.isRemote) in various places but it had no effect, and if I tried checking for if (this.worldObj.isRemote) then it just never executed whatever was inside that if statement.
I am really stuck on this, I have everything working how I want except that the items are invisible! Any help?