get item id in procedure

Started by T-cat2.0 on

Topic category: Advanced modding

Active 2 years ago
Joined Jan 2020
Points:
678

User statistics:

  • Modifications: 0
  • Forum topics: 6
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 20
get item id in procedure

is there a way to get the item id from an item in a slot e.g. I put cobblestone in slot 0 and i make it print that to chat: it prints 1xminecraft:stone 2.

I need it to print minecraft:stone:2 not 1xminecraft:stone 2, is this posable?

Active 2 years ago
Joined Nov 2020
Points:
645

User statistics:

  • Modifications: 2
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 50
yes just remove each letter…
Sun, 07/24/2022 - 19:48

yes just remove each letter until the letter is x and then remove x

 

Active 2 years ago
Joined Feb 2022
Points:
621

User statistics:

  • Modifications: 1
  • Forum topics: 13
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 161
If you can use custom code…
Sun, 08/21/2022 - 20:44

If you can use custom code at all you can use this to get the namespace and then do whatever you want with the string. I couldn't figure out how to get the namespace of an item anymore I looked everywhere in minecraft's code that I could think of but I could only find getDesciptionId() which is different. There used to be plugins that did it but that code didn't work anymore. This will get the namespace of a block or item though.

Rename item to whatever the itemstack your using is.

//Get Item Namespace
                    String descriptionId = item.getDescriptionId().toString();
                    String[] stringSplit = descriptionId.split("\\.");
                    String modName = stringSplit[1];
                    String itemName = stringSplit[2];
                    String namespace = modName + ":" + itemName;

If anyone else has a better way to get the namespace in code than converting the desciption id please lmk.