Fix ItemHandlerHelper.giveItemToPlayer creating item entities with incorrect contents (#5007)
This commit is contained in:
parent
0cf5ef221c
commit
58d570a6f1
1 changed files with 5 additions and 3 deletions
|
@ -162,18 +162,20 @@ public class ItemHandlerHelper
|
|||
*/
|
||||
public static void giveItemToPlayer(EntityPlayer player, @Nonnull ItemStack stack, int preferredSlot)
|
||||
{
|
||||
if (stack.isEmpty()) return;
|
||||
|
||||
IItemHandler inventory = new PlayerMainInvWrapper(player.inventory);
|
||||
World world = player.world;
|
||||
|
||||
// try adding it into the inventory
|
||||
ItemStack remainder = stack;
|
||||
// insert into preferred slot first
|
||||
if(preferredSlot >= 0)
|
||||
if (preferredSlot >= 0 && preferredSlot < inventory.getSlots())
|
||||
{
|
||||
remainder = inventory.insertItem(preferredSlot, stack, false);
|
||||
}
|
||||
// then into the inventory in general
|
||||
if(!remainder.isEmpty())
|
||||
if (!remainder.isEmpty())
|
||||
{
|
||||
remainder = insertItemStacked(inventory, remainder, false);
|
||||
}
|
||||
|
@ -188,7 +190,7 @@ public class ItemHandlerHelper
|
|||
// drop remaining itemstack into the world
|
||||
if (!remainder.isEmpty() && !world.isRemote)
|
||||
{
|
||||
EntityItem entityitem = new EntityItem(world, player.posX, player.posY + 0.5, player.posZ, stack);
|
||||
EntityItem entityitem = new EntityItem(world, player.posX, player.posY + 0.5, player.posZ, remainder);
|
||||
entityitem.setPickupDelay(40);
|
||||
entityitem.motionX = 0;
|
||||
entityitem.motionZ = 0;
|
||||
|
|
Loading…
Reference in a new issue