ID System (Item & Block ids)

Minecraft has stopped using their legacy id system from the 1.13 update and up-wards. That means that legacy id's will only work for 1.8.*-1.12.* . This ID system has been created to help with this.

It is recommended to use Blocks.Instance.GetId in the Start function of your ITask class, and store results in variables for the whole class to use. This is considered best practice for performance.

Blocks

The simplest form of getting a numeric id for both legacy ids (1.8-1.12) and the flattened ids is to use the static Blocks.Instance global variable.

Example usage:

var redstoneLampId = Blocks.Instance.GetId("minecraft:redstone_lamp").Value;

Note how GetId() returns a ushort?, this means that in cases where the passed string, in this case "minecraft:resdstone_lamp" is not a valid or a matching name, then null is returned.

This null mechanism is useful in casses where Minecraft uses different names for different versions, as in some cases you can do the following:

var someBlockId = Blocks.Instance.GetId("minecraft:some_block_1_8_name") ?? Blocks.Instance.GetId("minecraft:some_block_1_13_name");

Block more utility

There are also more functions on Blocks.Instance that make it easier to work with ids. The notable ones are:

  • Blocks.Instance.GetIds - get an array of ids for an array of inputs, example usage:

var fallingBlocks = Blocks.Instance.GetIds("minecraft:sand", "minecraft:red_sand", "minecraft:gravel");
  • ...

Items

Item ids work in the exact same way as the Block system, except it uses *Items*.Instance.GetId, instead of *Blocks*.Instance.GetId!

Example usage:

var fishingRodId= Items.Instance.GetId("minecraft:fishing_rod").Value;

Note how GetId() returns a ushort?, this means that in cases where the passed string, in this case "minecraft:fishing_rod" is not a valid or a matching name, then null is returned.

This null mechanism is useful in casses where Minecraft uses different names for different versions, as in some cases you can do the following:

var someItemId = Items.Instance.GetId("minecraft:some_item_1_8_name") ?? Items.Instance.GetId("minecraft:some_item_1_13_name");

Items more utility

There are also more functions on Items.Instance that make it easier to work with ids. The notable ones are:

  • Items.Instance.GetIds - get an array of ids for an array of inputs, example usage:

var food = Items.Instance.GetIds("minecraft:apple", "minecraft:bread", "minecraft:cooked_porkchop", "minecraft:cooked_fish", "minecraft:cookie", "minecraft:melon", "minecraft:cooked_beef", "minecraft:cooked_chicken", "minecraft:carrot", "minecraft:baked_potato",
                "minecraft:pumpkin_pie", "minecraft:cooked_mutton", "minecraftA:cooked_salmon", "minecraft:beetroot", "minecraft:beetroot_soup", "minecraft:dried_kelp", "minecraft:honey_bottle", "minecraft:cooked_rabbit", "minecraft:suspicious_stew", "minecraft:cooked_cod"
            );
  • ...

Last updated