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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#dropPlayerItemWithRandomChoice() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerEnchantment.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
/**
 * 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 2
Source File: ItemEmptyWirelessMap.java    From WirelessRedstone with MIT License 5 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
{
    ItemStack itemstack1 = new ItemStack(WirelessRedstoneAddons.wirelessMap, 1, p_77659_2_.getUniqueDataId("map"));
    String s = "map_" + itemstack1.getItemDamage();
    MapData mapdata = new MapData(s);
    p_77659_2_.setItemData(s, mapdata);
    mapdata.scale = 0;
    int i = 128 * (1 << mapdata.scale);
    mapdata.xCenter = (int)(Math.round(p_77659_3_.posX / (double)i) * (long)i);
    mapdata.zCenter = (int)(Math.round(p_77659_3_.posZ / (double)i) * (long)i);
    mapdata.dimension = p_77659_2_.provider.dimensionId;
    mapdata.markDirty();
    --p_77659_1_.stackSize;

    if (p_77659_1_.stackSize <= 0)
    {
        return itemstack1;
    }
    else
    {
        if (!p_77659_3_.inventory.addItemStackToInventory(itemstack1.copy()))
        {
            p_77659_3_.dropPlayerItemWithRandomChoice(itemstack1, false);
        }

        return p_77659_1_;
    }
}
 
Example 3
Source File: InventoryUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Drops all items from inv using getStackInSlotOnClosing
 */
public static void dropOnClose(EntityPlayer player, IInventory inv) {
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.removeStackFromSlot(i);
        if (stack != null)
            player.dropPlayerItemWithRandomChoice(stack, false);
    }
}
 
Example 4
Source File: TileEntityAerialInterface.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setInventorySlotContents(int slot, ItemStack itemStack){
    if(slot < 4) {
        inventory[slot] = itemStack;
        if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
            itemStack.stackSize = getInventoryStackLimit();
        }
    } else {
        EntityPlayer player = getPlayer();
        if(dispenserUpgradeInserted) {
            if(itemStack != null) {
                int startValue = itemStack.stackSize;
                while(itemStack.stackSize > 0) {
                    ItemStack remainingItem = itemStack.onFoodEaten(player.worldObj, player);
                    remainingItem = ForgeEventFactory.onItemUseFinish(player, itemStack, 0, remainingItem);
                    if(remainingItem != null && remainingItem.stackSize > 0 && (remainingItem != itemStack || remainingItem.stackSize != startValue)) {
                        if(!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.stackSize > 0) {
                            player.dropPlayerItemWithRandomChoice(remainingItem, false);
                        }
                    }
                    if(itemStack.stackSize == startValue) break;
                }
            }
        } else {
            InventoryPlayer inventoryPlayer = player != null ? player.inventory : null;
            if(inventoryPlayer != null) {
                inventoryPlayer.setInventorySlotContents(slot - 4, itemStack);
            } else if(worldObj != null && !worldObj.isRemote) {
                EntityItem item = new EntityItem(worldObj, xCoord, yCoord, zCoord, itemStack);
                worldObj.spawnEntityInWorld(item);
            }
        }
    }

}