Java Code Examples for net.minecraft.entity.player.EntityPlayer.dropItem()

The following are Jave code examples for showing how to use dropItem() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: CustomWorldGen   File: ContainerEnchantment.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    if (!this.worldPointer.isRemote)
    {
        for (int i = 0; i < this.tableInventory.getSizeInventory(); ++i)
        {
            ItemStack itemstack = this.tableInventory.removeStackFromSlot(i);

            if (itemstack != null)
            {
                playerIn.dropItem(itemstack, false);
            }
        }
    }
}
 
Example 2
Project: CustomWorldGen   File: ForgeHooks.java   View Source Code Vote up 6 votes
public static EntityItem onPlayerTossEvent(EntityPlayer player, ItemStack item, boolean includeName)
{
    player.captureDrops = true;
    EntityItem ret = player.dropItem(item, false, includeName);
    player.capturedDrops.clear();
    player.captureDrops = false;

    if (ret == null)
    {
        return null;
    }

    ItemTossEvent event = new ItemTossEvent(ret, player);
    if (MinecraftForge.EVENT_BUS.post(event))
    {
        return null;
    }

    if (!player.worldObj.isRemote)
    {
        player.getEntityWorld().spawnEntityInWorld(event.getEntityItem());
    }
    return event.getEntityItem();
}
 
Example 3
Project: Got-Wood   File: SappyLog.java   View Source Code Vote up 6 votes
@Override //&& state.getValue(GENERATED)==1
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
	if(heldItem == null){
		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
	}
	
	if( !worldIn.isRemote  && heldItem.getItem() == Items.BOWL && side != EnumFacing.UP && side != EnumFacing.DOWN){
		
                  ItemStack itemstack1 = new ItemStack(ItemRegistry.rubber_sap);

                  if (--heldItem.stackSize == 0)
                  {
                      playerIn.setHeldItem(hand, itemstack1);
                  }
                  else if (!playerIn.inventory.addItemStackToInventory(itemstack1))
                  {
                      playerIn.dropItem(itemstack1, false);
                  }
	}
	return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
	
}
 
Example 4
Project: Backmemed   File: ContainerEnchantment.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    if (!this.worldPointer.isRemote)
    {
        for (int i = 0; i < this.tableInventory.getSizeInventory(); ++i)
        {
            ItemStack itemstack = this.tableInventory.removeStackFromSlot(i);

            if (!itemstack.func_190926_b())
            {
                playerIn.dropItem(itemstack, false);
            }
        }
    }
}
 
Example 5
Project: CustomWorldGen   File: ContainerWorkbench.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    if (!this.worldObj.isRemote)
    {
        for (int i = 0; i < 9; ++i)
        {
            ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i);

            if (itemstack != null)
            {
                playerIn.dropItem(itemstack, false);
            }
        }
    }
}
 
Example 6
Project: CustomWorldGen   File: ContainerMerchant.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);
    this.theMerchant.setCustomer((EntityPlayer)null);
    super.onContainerClosed(playerIn);

    if (!this.theWorld.isRemote)
    {
        ItemStack itemstack = this.merchantInventory.removeStackFromSlot(0);

        if (itemstack != null)
        {
            playerIn.dropItem(itemstack, false);
        }

        itemstack = this.merchantInventory.removeStackFromSlot(1);

        if (itemstack != null)
        {
            playerIn.dropItem(itemstack, false);
        }
    }
}
 
Example 7
Project: BetterBeginningsReborn   File: ContainerSimpleWorkbench.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
@Override
public void onContainerClosed(EntityPlayer player)
{
	super.onContainerClosed(player);

	if (!worldObj.isRemote)
	{
		for (int i = 0; i < 9; ++i)
		{
			ItemStack itemstack = craftMatrix.removeStackFromSlot(i);

			if (itemstack != null)
			{
				player.dropItem(itemstack, false);
			}
		}
	}
}
 
Example 8
Project: Backmemed   File: ItemGlassBottle.java   View Source Code Vote up 6 votes
protected ItemStack turnBottleIntoItem(ItemStack p_185061_1_, EntityPlayer player, ItemStack stack)
{
    p_185061_1_.func_190918_g(1);
    player.addStat(StatList.getObjectUseStats(this));

    if (p_185061_1_.func_190926_b())
    {
        return stack;
    }
    else
    {
        if (!player.inventory.addItemStackToInventory(stack))
        {
            player.dropItem(stack, false);
        }

        return p_185061_1_;
    }
}
 
Example 9
Project: Backmemed   File: ItemEmptyMap.java   View Source Code Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = ItemMap.func_190906_a(itemStackIn, worldIn.posX, worldIn.posZ, (byte)0, true, false);
    ItemStack itemstack1 = worldIn.getHeldItem(playerIn);
    itemstack1.func_190918_g(1);

    if (itemstack1.func_190926_b())
    {
        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        if (!worldIn.inventory.addItemStackToInventory(itemstack.copy()))
        {
            worldIn.dropItem(itemstack, false);
        }

        worldIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult(EnumActionResult.SUCCESS, itemstack1);
    }
}
 
Example 10
Project: CustomWorldGen   File: ItemGlassBottle.java   View Source Code Vote up 6 votes
protected ItemStack turnBottleIntoItem(ItemStack p_185061_1_, EntityPlayer player, ItemStack stack)
{
    --p_185061_1_.stackSize;
    player.addStat(StatList.getObjectUseStats(this));

    if (p_185061_1_.stackSize <= 0)
    {
        return stack;
    }
    else
    {
        if (!player.inventory.addItemStackToInventory(stack))
        {
            player.dropItem(stack, false);
        }

        return p_185061_1_;
    }
}
 
Example 11
Project: CustomWorldGen   File: ItemBucket.java   View Source Code Vote up 6 votes
private ItemStack fillBucket(ItemStack emptyBuckets, EntityPlayer player, Item fullBucket)
{
    if (player.capabilities.isCreativeMode)
    {
        return emptyBuckets;
    }
    else if (--emptyBuckets.stackSize <= 0)
    {
        return new ItemStack(fullBucket);
    }
    else
    {
        if (!player.inventory.addItemStackToInventory(new ItemStack(fullBucket)))
        {
            player.dropItem(new ItemStack(fullBucket), false);
        }

        return emptyBuckets;
    }
}
 
Example 12
Project: Backmemed   File: ContainerPlayer.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    for (int i = 0; i < 4; ++i)
    {
        ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i);

        if (!itemstack.func_190926_b())
        {
            playerIn.dropItem(itemstack, false);
        }
    }

    this.craftResult.setInventorySlotContents(0, ItemStack.field_190927_a);
}
 
Example 13
Project: Backmemed   File: ContainerRepair.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    if (!this.theWorld.isRemote)
    {
        for (int i = 0; i < this.inputSlots.getSizeInventory(); ++i)
        {
            ItemStack itemstack = this.inputSlots.removeStackFromSlot(i);

            if (!itemstack.func_190926_b())
            {
                playerIn.dropItem(itemstack, false);
            }
        }
    }
}
 
Example 14
Project: Backmemed   File: ContainerMerchant.java   View Source Code Vote up 6 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);
    this.theMerchant.setCustomer((EntityPlayer)null);
    super.onContainerClosed(playerIn);

    if (!this.theWorld.isRemote)
    {
        ItemStack itemstack = this.merchantInventory.removeStackFromSlot(0);

        if (!itemstack.func_190926_b())
        {
            playerIn.dropItem(itemstack, false);
        }

        itemstack = this.merchantInventory.removeStackFromSlot(1);

        if (!itemstack.func_190926_b())
        {
            playerIn.dropItem(itemstack, false);
        }
    }
}
 
Example 15
Project: CustomWorldGen   File: ContainerBeacon.java   View Source Code Vote up 5 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    if (playerIn != null && !playerIn.worldObj.isRemote)
    {
        ItemStack itemstack = this.beaconSlot.decrStackSize(this.beaconSlot.getSlotStackLimit());

        if (itemstack != null)
        {
            playerIn.dropItem(itemstack, false);
        }
    }
}
 
Example 16
Project: harshencastle   File: HarshenUtils.java   View Source Code Vote up 5 votes
public static boolean give(EntityPlayer playerIn, EnumHand hand, ItemStack stack)
{
	if(playerIn.getHeldItem(hand).isEmpty())
           playerIn.setHeldItem(hand, stack);
       else if (!playerIn.inventory.addItemStackToInventory(stack))
           playerIn.dropItem(stack, false);
	return true;
}
 
Example 17
Project: Backmemed   File: ContainerBeacon.java   View Source Code Vote up 5 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    if (playerIn != null && !playerIn.world.isRemote)
    {
        ItemStack itemstack = this.beaconSlot.decrStackSize(this.beaconSlot.getSlotStackLimit());

        if (!itemstack.func_190926_b())
        {
            playerIn.dropItem(itemstack, false);
        }
    }
}
 
Example 18
Project: CustomWorldGen   File: EntityMooshroom.java   View Source Code Vote up 4 votes
@SuppressWarnings("unused")
public boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack)
{
    if (stack != null && stack.getItem() == Items.BOWL && this.getGrowingAge() >= 0 && !player.capabilities.isCreativeMode)
    {
        if (--stack.stackSize == 0)
        {
            player.setHeldItem(hand, new ItemStack(Items.MUSHROOM_STEW));
        }
        else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.MUSHROOM_STEW)))
        {
            player.dropItem(new ItemStack(Items.MUSHROOM_STEW), false);
        }

        return true;
    }
    else if (false && stack != null && stack.getItem() == Items.SHEARS && this.getGrowingAge() >= 0) //Forge Disable, Moved to onSheared
    {
        this.setDead();
        this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);

        if (!this.worldObj.isRemote)
        {
            EntityCow entitycow = new EntityCow(this.worldObj);
            entitycow.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
            entitycow.setHealth(this.getHealth());
            entitycow.renderYawOffset = this.renderYawOffset;

            if (this.hasCustomName())
            {
                entitycow.setCustomNameTag(this.getCustomNameTag());
            }

            this.worldObj.spawnEntityInWorld(entitycow);

            for (int i = 0; i < 5; ++i)
            {
                this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY + (double)this.height, this.posZ, new ItemStack(Blocks.RED_MUSHROOM)));
            }

            stack.damageItem(1, player);
            this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F);
        }

        return true;
    }
    else
    {
        return super.processInteract(player, hand, stack);
    }
}
 
Example 19
Project: VanillaExtras   File: BlockJar.java   View Source Code Vote up 4 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack itemstack = playerIn.getHeldItemMainhand();
	if (itemstack.isEmpty()) {
		return true;
	} else {

		Item item = playerIn.getHeldItemMainhand().getItem();

		if (item == Items.BUCKET) {

			itemstack.shrink(1);

			if (itemstack.isEmpty()) {
				playerIn.setHeldItem(hand, new ItemStack(Items.WATER_BUCKET));
			} else if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET))) {
				playerIn.dropItem(new ItemStack(Items.WATER_BUCKET), false);
			}

			return true;
		} else if (item == Items.GLASS_BOTTLE) {

			itemstack.shrink(1);

			ItemStack itemstack1 = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM),
					PotionTypes.WATER);

			if (itemstack.isEmpty()) {
				playerIn.setHeldItem(hand, itemstack1);
			} else if (!playerIn.inventory.addItemStackToInventory(itemstack1)) {
				playerIn.dropItem(itemstack1, false);
			} else if (playerIn instanceof EntityPlayerMP) {
				((EntityPlayerMP) playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
			}

			return true;
		}
		return false;
	}

}
 
Example 20
Project: Backmemed   File: EntityMooshroom.java   View Source Code Vote up 4 votes
public boolean processInteract(EntityPlayer player, EnumHand hand)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (itemstack.getItem() == Items.BOWL && this.getGrowingAge() >= 0 && !player.capabilities.isCreativeMode)
    {
        itemstack.func_190918_g(1);

        if (itemstack.func_190926_b())
        {
            player.setHeldItem(hand, new ItemStack(Items.MUSHROOM_STEW));
        }
        else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.MUSHROOM_STEW)))
        {
            player.dropItem(new ItemStack(Items.MUSHROOM_STEW), false);
        }

        return true;
    }
    else if (itemstack.getItem() == Items.SHEARS && this.getGrowingAge() >= 0)
    {
        this.setDead();
        this.world.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);

        if (!this.world.isRemote)
        {
            EntityCow entitycow = new EntityCow(this.world);
            entitycow.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
            entitycow.setHealth(this.getHealth());
            entitycow.renderYawOffset = this.renderYawOffset;

            if (this.hasCustomName())
            {
                entitycow.setCustomNameTag(this.getCustomNameTag());
            }

            this.world.spawnEntityInWorld(entitycow);

            for (int i = 0; i < 5; ++i)
            {
                this.world.spawnEntityInWorld(new EntityItem(this.world, this.posX, this.posY + (double)this.height, this.posZ, new ItemStack(Blocks.RED_MUSHROOM)));
            }

            itemstack.damageItem(1, player);
            this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F);
        }

        return true;
    }
    else
    {
        return super.processInteract(player, hand);
    }
}