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

What's the method for getting an item stack from the slot of either an entity or tile entity? I need to input a slot as an integer and return an ItemStack.

To get it from a tile entity, I've been using 

(IInventory) replace.getSource().getWorld().getTileEntity(sourcePos).getStackInSlot(sourceSlot)

which works properly, but someone else told me that IInventory won't work for anything outside of the vanilla game and that I should instead use the "IItemHandler wrapper." Not sure exactly what that is though.

 

However, I still haven't figured out how to do this with mobs, so I could use some help with that.

 

Edit: I suppose I should specify that this is being used for a command (the above code line is in ".executes((replace) -> {})")

Edited by ChromaKey81
not solved lol

  • Author
  On 7/1/2020 at 7:20 AM, diesieben07 said:

You first need to get the IItemHandler capability from the tile entity (getCapability with CapabilityItemHandler.ITEM_HANDLER_CAPABILITY). This will give you an IItemHandler if the TE has an inventory. You can then interact with that.

Thank you for the explanation on that. Does this work for entities? If not, what is the method for that?

  • Author
  On 7/1/2020 at 2:12 PM, diesieben07 said:

Entities that have an inventory (e.g. the player) also provide this capability, yes.

So it works with players, thanks. Are entities with armor/hand slots (e.g. zombies) included? I need to be able to pass any entity with slots as a source.

Edited by ChromaKey81

  • Author
  On 7/1/2020 at 2:21 PM, diesieben07 said:

Yes, all living entities have equipment and expose it as the IItemHandler capability.

You can even pass in a Direction to only get the hands (Direction.UP or DOWN) or the armor (all other directions). When you pass in null you get a handler that wraps the whole inventory.

Thanks so much. I've been looking for an answer to this for a while

  • Author
  On 7/1/2020 at 7:20 AM, diesieben07 said:

You first need to get the IItemHandler capability from the tile entity (getCapability with CapabilityItemHandler.ITEM_HANDLER_CAPABILITY). This will give you an IItemHandler if the TE has an inventory. You can then interact with that.

Shoot, actually I'm still having a bit of trouble with that.

replace.getSource().getWorld().getTileEntity(BlockPosArgument.getLoadedBlockPos(replace, "sourcePos")).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)

 

This returns LazyOptional<IItemHandler>. How do I get from there to using the IItemHandler methods?

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.