Skip to content

How to use WrappedBlockState and ItemTypes

DefineOutside edited this page Jan 28, 2023 · 3 revisions

Unlike bukkit, we follow the Mojang convention for separating items types and block types. This means that if you are sending an ItemStack, for example, you must use ItemTypes. However, if you are sending a block, you must use StateTypes.

StateTypes are all the materials that a block can be, across all versions of minecraft. You cannot send a raw state type however, as blocks contain data.

To create block data to send, you may call

WrappedBlockState stone = StateTypes.STONE.createBlockData();

This will create a block data for stone

An example of a more complicated block is

WrappedBlockState stairs = StateTypes.OAK_STAIRS.createBlockData();
stairs.setFacing(BlockFace.SOUTH);

Attempting to set an invalid property will silently be ignored, you may turn on debugging to show this warning, however. Attempting to read an invalid property will throw a null pointer exception.

This system is designed to work on all server versions. This means that you can read the direction of stairs, for example, on both 1.8 and 1.19 while using a modern block system.

If you wish to work and convert between bukkit, you may use SpigotConversionUtil to accomplish this

For 1.13+ servers

SpigotConversionUtil.fromBukkitBlockData(BlockData);
SpigotConversionUtil.toBukkitBlockData(WrappedBlockState);

for 1.12.2 and below servers

SpigotConversionUtil.fromBukkitMaterialData(MaterialData);
SpigotConversionUtil.toBukkitMaterialData(WrappedBlockState);

However, for efficiency reasons as 1.13+ conversions use a lot of strings, you are encouraged to minimize conversions with bukkit if possible.

Should I specify client version?

On backend servers such as paper or spigot, you should not. This option is left in for proxies and should not be used in bukkit. In general, if there is a method to specify client version, there should also be a another method without it that you should use instead.

Clone this wiki locally