Fixed edibles not returning their container item correctly

This commit is contained in:
Sollace 2019-01-31 12:29:26 +02:00
parent 8478c0a0da
commit 61cb1ac78b

View file

@ -66,8 +66,10 @@ public class ItemEdible extends ItemFood implements IEdible {
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer)entityLiving;
EntityPlayer entityplayer = entityLiving instanceof EntityPlayer ? (EntityPlayer)entityLiving : null;
if (entityplayer != null) {
entityplayer.getFoodStats().addStats(this, stack);
worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
@ -80,15 +82,23 @@ public class ItemEdible extends ItemFood implements IEdible {
if (entityplayer instanceof EntityPlayerMP) {
CriteriaTriggers.CONSUME_ITEM.trigger((EntityPlayerMP)entityplayer, stack);
}
}
if (entityplayer == null || !entityplayer.capabilities.isCreativeMode) {
stack.shrink(1);
}
ItemStack container = getContainerItem(stack);
if (!container.isEmpty()) {
return container;
}
if (!container.isEmpty() && entityplayer != null && !entityplayer.capabilities.isCreativeMode) {
if (stack.isEmpty()) {
return getContainerItem(stack);
}
stack.shrink(1);
entityplayer.inventory.addItemStackToInventory(getContainerItem(stack));
}
return stack;
}