Is it possible to convert a String to ItemStack?

Started by Xedroc on

Topic category: Help with MCreator software

Last seen on 01:26, 31. Dec 2021
Joined Jan 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is it possible to convert a String to ItemStack?

Hi, I want to make a enchantment that makes the wood logs you break with an axe drop planks of the same wood type.
It could be made by adding a conditional per each wood type (if block at x y z = X_WOOD do Spawn gem at x y z of type X_PLANKS)

But I wondered then if it could be made on a simplier way that makes the code shorter and saves resources (and maybe gives better performance), like taking the display name of the wood block at x y z and with some text operations (like replace) convert its display name to the one of their corresponding planks, and using it to get the planks block

Will be there a procedure that does something like that on future versions or is there a way to code something like that?

Last seen on 23:21, 17. Jun 2022
Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well yes with coding. If you…
Sun, 03/21/2021 - 18:11

Well yes with coding. If you need to get Item by it's id you can use:

ForgeRegistries.ITEMS.getValue(new ResourceLocation(*your string's name or string itself*))

for e.g: ForgeRegistries.ITEMS.getValue(new ResourceLocation("minecraft:bedrock")) returns bedrock item.

You can also use this for your own items

 

 

Last seen on 01:26, 31. Dec 2021
Joined Jan 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can it be passed to a…
Tue, 03/23/2021 - 15:26

Can it be passed to a itemstack object (like with the "new ItemStack" method)?
Since I need it to spawn four item entities on the floor

Last seen on 23:21, 17. Jun 2022
Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes
Fri, 03/26/2021 - 11:22

Yes

Last seen on 01:26, 5. Jan 2023
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I've been thinking about…
Sun, 09/11/2022 - 01:23

I've been thinking about spawning the item with commands to an open area in the chunk and then get that item stack, after which you can just quickly despawn the item