Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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

  • Author

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

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

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.