Thornack Posted September 7, 2015 Posted September 7, 2015 Hi Everyone, I have access to the itemstack. How do you force an itemstack to be dropped from the players inventory? I have this function that returns the itemstack from the specified slot in the hud inventory. I need to force this item to be dropepd on the ground. any ideas? public ItemStack getHeldItem(EntityPlayer player){ if(player.inventory.mainInventory[5] != null){ heldItem[0] = player.inventory.mainInventory[5]; return heldItem[0]; } return null; } Quote
Failender Posted September 7, 2015 Posted September 7, 2015 player.inventory.seInventorySlotContents(desiredSlot, null) removes the item from the inventory. To drop it in the world look at InventoryHelper.dropInventorySlotContents. u should find help there Quote
Thornack Posted September 7, 2015 Author Posted September 7, 2015 hmm I cant seem to find the Inventory Helper where is it located Quote
Failender Posted September 7, 2015 Posted September 7, 2015 are u using eclipse? if u do strg+shift+ t Quote
Thornack Posted September 7, 2015 Author Posted September 7, 2015 Ya I am using eclipse but it isnt there. ctrl + shift T and Inventory in search bar returns InventoryPlayer, InventoryBasic, InventoryCrafting, InventoryCraftResuld, InventoryEffectRenderer, InventoryEnderChest, InventoryLargeChest, InventoryMerchant Quote
Failender Posted September 7, 2015 Posted September 7, 2015 Hmm didnt knew it was a new thing in 1.8 , I apologize. private static void spawnItemStack(World worldIn, double p_180173_1_, double p_180173_3_, double p_180173_5_, ItemStack p_180173_7_) { float f = RANDOM.nextFloat() * 0.8F + 0.1F; float f1 = RANDOM.nextFloat() * 0.8F + 0.1F; float f2 = RANDOM.nextFloat() * 0.8F + 0.1F; while (p_180173_7_.stackSize > 0) { int i = RANDOM.nextInt(21) + 10; if (i > p_180173_7_.stackSize) { i = p_180173_7_.stackSize; } p_180173_7_.stackSize -= i; EntityItem entityitem = new EntityItem(worldIn, p_180173_1_ + (double)f, p_180173_3_ + (double)f1, p_180173_5_ + (double)f2, new ItemStack(p_180173_7_.getItem(), i, p_180173_7_.getMetadata())); if (p_180173_7_.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)p_180173_7_.getTagCompound().copy()); } float f3 = 0.05F; entityitem.motionX = RANDOM.nextGaussian() * (double)f3; entityitem.motionY = RANDOM.nextGaussian() * (double)f3 + 0.20000000298023224D; entityitem.motionZ = RANDOM.nextGaussian() * (double)f3; worldIn.spawnEntityInWorld(entityitem); } } Quote
Thornack Posted September 7, 2015 Author Posted September 7, 2015 This worked if(getHeldItem(player) != null){ ItemStack myItemStack = new ItemStack(getHeldItem(player).getItem(), 1); EntityItem entityitem = new EntityItem(player.worldObj, player.posX, player.posY+1, player.posZ, myItemStack); entityitem.delayBeforeCanPickup = 10; player.worldObj.spawnEntityInWorld(entityitem); } Quote
TmzOS Posted September 7, 2015 Posted September 7, 2015 Well.. you can consume the item and spawn the entityitem with a pickup delay. player.inventory.consumeInventoryItem(itemobject); [b]From spawnAsEntity(...) in Block.class (mc 1.[/b] EntityItem entityitem = new EntityItem(worldIn, (double)pos.getX() + d0, (double)pos.getY() + d1, (double)pos.getZ() + d2, stack); entityitem.setDefaultPickupDelay(); worldIn.spawnEntityInWorld(entityitem); Quote // BSc CIS, hardcore gamer and a big fan of Minecraft. TmzOS ::..
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.