Jump to content

[1.7.10] How would you Force Item Drop from Inventory?


Recommended Posts

Posted

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;
}

Posted

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

Posted

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

Posted

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);
        }
    }

Posted

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);
			}

Posted

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);

 

 

// BSc CIS, hardcore gamer and a big fan of Minecraft.

 

TmzOS ::..

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.