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

The following are Jave code examples for showing how to use dropPlayerItemWithRandomChoice() 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: BaseClient   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.dropPlayerItemWithRandomChoice(new ItemStack(fullBucket, 1, 0), false);
        }

        return emptyBuckets;
    }
}
 
Example 2
Project: BaseClient   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.dropPlayerItemWithRandomChoice(itemstack, false);
            }
        }
    }
}
 
Example 3
Project: BaseClient   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.dropPlayerItemWithRandomChoice(itemstack, false);
            }
        }
    }
}
 
Example 4
Project: DecompiledMinecraft   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 != null)
            {
                playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
            }
        }
    }
}
 
Example 5
Project: BaseClient   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 != null)
            {
                playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
            }
        }
    }
}
 
Example 6
Project: DecompiledMinecraft   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.dropPlayerItemWithRandomChoice(itemstack, false);
            }
        }
    }
}
 
Example 7
Project: BaseClient   File: EntityCow.java   View Source Code Vote up 6 votes
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.bucket && !player.capabilities.isCreativeMode && !this.isChild())
    {
        if (itemstack.stackSize-- == 1)
        {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Items.milk_bucket));
        }
        else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.milk_bucket)))
        {
            player.dropPlayerItemWithRandomChoice(new ItemStack(Items.milk_bucket, 1, 0), false);
        }

        return true;
    }
    else
    {
        return super.interact(player);
    }
}
 
Example 8
Project: BaseClient   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 != null)
            {
                playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
            }
        }
    }
}
 
Example 9
Project: DecompiledMinecraft   File: EntityCow.java   View Source Code Vote up 6 votes
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.bucket && !player.capabilities.isCreativeMode && !this.isChild())
    {
        if (itemstack.stackSize-- == 1)
        {
            player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Items.milk_bucket));
        }
        else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.milk_bucket)))
        {
            player.dropPlayerItemWithRandomChoice(new ItemStack(Items.milk_bucket, 1, 0), false);
        }

        return true;
    }
    else
    {
        return super.interact(player);
    }
}
 
Example 10
Project: BaseClient   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.dropPlayerItemWithRandomChoice(new ItemStack(fullBucket, 1, 0), false);
        }

        return emptyBuckets;
    }
}
 
Example 11
Project: DecompiledMinecraft   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 != null)
        {
            playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
        }
    }

    this.craftResult.setInventorySlotContents(0, (ItemStack)null);
}
 
Example 12
Project: BaseClient   File: Container.java   View Source Code Vote up 5 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    InventoryPlayer inventoryplayer = playerIn.inventory;

    if (inventoryplayer.getItemStack() != null)
    {
        playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), false);
        inventoryplayer.setItemStack((ItemStack)null);
    }
}
 
Example 13
Project: BaseClient   File: Container.java   View Source Code Vote up 5 votes
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer playerIn)
{
    InventoryPlayer inventoryplayer = playerIn.inventory;

    if (inventoryplayer.getItemStack() != null)
    {
        playerIn.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), false);
        inventoryplayer.setItemStack((ItemStack)null);
    }
}
 
Example 14
Project: connor41-etfuturum2   File: ContainerEnchantment.java   View Source Code Vote up 5 votes
/**
 * Called when the container is closed.
 */
@Override
public void onContainerClosed(EntityPlayer player) {
	super.onContainerClosed(player);

	if (!world.isRemote)
		for (int i = 0; i < tableInventory.getSizeInventory(); i++) {
			ItemStack stack = tableInventory.getStackInSlotOnClosing(i);
			if (stack != null)
				player.dropPlayerItemWithRandomChoice(stack, false);
		}
}
 
Example 15
Project: DecompiledMinecraft   File: ItemEmptyMap.java   View Source Code Vote up 5 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    ItemStack itemstack = new ItemStack(Items.filled_map, 1, worldIn.getUniqueDataId("map"));
    String s = "map_" + itemstack.getMetadata();
    MapData mapdata = new MapData(s);
    worldIn.setItemData(s, mapdata);
    mapdata.scale = 0;
    mapdata.calculateMapCenter(playerIn.posX, playerIn.posZ, mapdata.scale);
    mapdata.dimension = (byte)worldIn.provider.getDimensionId();
    mapdata.markDirty();
    --itemStackIn.stackSize;

    if (itemStackIn.stackSize <= 0)
    {
        return itemstack;
    }
    else
    {
        if (!playerIn.inventory.addItemStackToInventory(itemstack.copy()))
        {
            playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
        }

        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
        return itemStackIn;
    }
}
 
Example 16
Project: BaseClient   File: ItemEmptyMap.java   View Source Code Vote up 5 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    ItemStack itemstack = new ItemStack(Items.filled_map, 1, worldIn.getUniqueDataId("map"));
    String s = "map_" + itemstack.getMetadata();
    MapData mapdata = new MapData(s);
    worldIn.setItemData(s, mapdata);
    mapdata.scale = 0;
    mapdata.calculateMapCenter(playerIn.posX, playerIn.posZ, mapdata.scale);
    mapdata.dimension = (byte)worldIn.provider.getDimensionId();
    mapdata.markDirty();
    --itemStackIn.stackSize;

    if (itemStackIn.stackSize <= 0)
    {
        return itemstack;
    }
    else
    {
        if (!playerIn.inventory.addItemStackToInventory(itemstack.copy()))
        {
            playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
        }

        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
        return itemStackIn;
    }
}
 
Example 17
Project: BaseClient   File: ItemGlassBottle.java   View Source Code Vote up 4 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);

    if (movingobjectposition == null)
    {
        return itemStackIn;
    }
    else
    {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
        {
            BlockPos blockpos = movingobjectposition.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos))
            {
                return itemStackIn;
            }

            if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
            {
                return itemStackIn;
            }

            if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.water)
            {
                --itemStackIn.stackSize;
                playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);

                if (itemStackIn.stackSize <= 0)
                {
                    return new ItemStack(Items.potionitem);
                }

                if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem)))
                {
                    playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false);
                }
            }
        }

        return itemStackIn;
    }
}
 
Example 18
Project: BaseClient   File: CommandGive.java   View Source Code Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.give.usage", new Object[0]);
    }
    else
    {
        EntityPlayer entityplayer = getPlayer(sender, args[0]);
        Item item = getItemByText(sender, args[1]);
        int i = args.length >= 3 ? parseInt(args[2], 1, 64) : 1;
        int j = args.length >= 4 ? parseInt(args[3]) : 0;
        ItemStack itemstack = new ItemStack(item, i, j);

        if (args.length >= 5)
        {
            String s = getChatComponentFromNthArg(sender, args, 4).getUnformattedText();

            try
            {
                itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);

        if (flag)
        {
            entityplayer.worldObj.playSoundAtEntity(entityplayer, "random.pop", 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
            entityplayer.inventoryContainer.detectAndSendChanges();
        }

        if (flag && itemstack.stackSize <= 0)
        {
            itemstack.stackSize = 1;
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
            EntityItem entityitem1 = entityplayer.dropPlayerItemWithRandomChoice(itemstack, false);

            if (entityitem1 != null)
            {
                entityitem1.func_174870_v();
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.stackSize);
            EntityItem entityitem = entityplayer.dropPlayerItemWithRandomChoice(itemstack, false);

            if (entityitem != null)
            {
                entityitem.setNoPickupDelay();
                entityitem.setOwner(entityplayer.getName());
            }
        }

        notifyOperators(sender, this, "commands.give.success", new Object[] {itemstack.getChatComponent(), Integer.valueOf(i), entityplayer.getName()});
    }
}
 
Example 19
Project: DecompiledMinecraft   File: CommandGive.java   View Source Code Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.give.usage", new Object[0]);
    }
    else
    {
        EntityPlayer entityplayer = getPlayer(sender, args[0]);
        Item item = getItemByText(sender, args[1]);
        int i = args.length >= 3 ? parseInt(args[2], 1, 64) : 1;
        int j = args.length >= 4 ? parseInt(args[3]) : 0;
        ItemStack itemstack = new ItemStack(item, i, j);

        if (args.length >= 5)
        {
            String s = getChatComponentFromNthArg(sender, args, 4).getUnformattedText();

            try
            {
                itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);

        if (flag)
        {
            entityplayer.worldObj.playSoundAtEntity(entityplayer, "random.pop", 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
            entityplayer.inventoryContainer.detectAndSendChanges();
        }

        if (flag && itemstack.stackSize <= 0)
        {
            itemstack.stackSize = 1;
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
            EntityItem entityitem1 = entityplayer.dropPlayerItemWithRandomChoice(itemstack, false);

            if (entityitem1 != null)
            {
                entityitem1.func_174870_v();
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.stackSize);
            EntityItem entityitem = entityplayer.dropPlayerItemWithRandomChoice(itemstack, false);

            if (entityitem != null)
            {
                entityitem.setNoPickupDelay();
                entityitem.setOwner(entityplayer.getName());
            }
        }

        notifyOperators(sender, this, "commands.give.success", new Object[] {itemstack.getChatComponent(), Integer.valueOf(i), entityplayer.getName()});
    }
}
 
Example 20
Project: DecompiledMinecraft   File: ItemGlassBottle.java   View Source Code Vote up 4 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);

    if (movingobjectposition == null)
    {
        return itemStackIn;
    }
    else
    {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
        {
            BlockPos blockpos = movingobjectposition.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos))
            {
                return itemStackIn;
            }

            if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
            {
                return itemStackIn;
            }

            if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.water)
            {
                --itemStackIn.stackSize;
                playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);

                if (itemStackIn.stackSize <= 0)
                {
                    return new ItemStack(Items.potionitem);
                }

                if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem)))
                {
                    playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false);
                }
            }
        }

        return itemStackIn;
    }
}