Jump to content

Recommended Posts

Posted (edited)

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
Posted
6 hours ago, 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?

Posted (edited)
4 minutes ago, 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
Posted
Just now, 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

Posted
7 hours ago, 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...

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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