From 61cb1ac78b515372f8e4f67c4e551bbb222cf22f Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 31 Jan 2019 12:29:26 +0200 Subject: [PATCH] Fixed edibles not returning their container item correctly --- .../unicopia/edibles/ItemEdible.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java b/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java index b3bedaf0..2eee7275 100644 --- a/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java +++ b/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java @@ -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; }