Obtaining the 'Sub ID' of a modded item

In Minecraft 1.12.2 various items have a ‘sub ID’ (I’m not sure of it’s actual name) which exist in addition to it’s full ID.

For example, andesite has the id minecraft:stone but can be told apart from other stone blocks using it’s sub ID, which is 5. To give andesite to the player one runs /give CrashDive minecraft:stone 1 5 where 5 represents the sub ID fo andesite.

I’m aware that, for vanilla items, this value can be extracted using Keys such as Keys.STONE_TYPE Keys (SpongeAPI 7.2.0 API) . This is fine, but I need a generic way to find this information for any item, including modded ones. For example an ‘Electronic Circuit’ from IC2 Classic has the id ic2:itemmisc and the sub ID 451. If I have an ItemStack of electronic circuits how do I obtain the subID (451)?

I’m using Sponge 7.2.0

You wont find much new support for 7.x. but thankfully i answered this a while ago

While this is for setting the sub id. The same logic can be used to get

Thanks heaps! This worked perfectly and I don’t think I would have ever found it otherwise. Thanks again for helping me so many times (and quickly at that)!

1 Like