Jump to content

Forge 1.19.3 How to get a block from an itemstack and compare it to an item


DinoPawz

Recommended Posts

I have created a plant using a seed item using ItemNameBlockItem and the corresponding block using the BushBlock classes.

However when setting the block as an entity's favorite block, I need to test it as an item, but when I use the block.asItem() I target the seed, not the plant. I cannot figure out a way to get a block from an ItemStack, cos casting to ItemLike and BlockItem don't work and Item doesn't have an Item.getItemFromBlock method (and perhaps if it did it would just return the seed item, not the plant block as an item). I tried using the block's resource location to identify the block but ItemStack doesn't return a resource location. I printed out the block name and mc just adds prepends item to the block name. So, is this the correct way to do it?

 

if (stack.getDescriptionId().equalsIgnoreCase("itemblock_name")) {}

Edited by DinoPawz
more info
Link to comment
Share on other sites

outside of registration class, there should be no "string representations" or paths to your items and blocks (tags are okay). and what you used is for translation and displaying on screen.

now during registration, did you make a BlockItem instance for the purpose of creative tab? if you did, do stack.getItem().equals(staticBlockItemFromRegistration)

frankly, i'm not sure what you need to do so if the above row didn't help, please paste problematic method.

  • Like 1
Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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