How to set the value of block data?

Bukkit setData(data) and getData() are deprecated. But there is no replacement. Bukkit / Spigot JavaDoc says this about setData() :

Outdated. Magical meaning

Why is this?

+5
source share
1 answer

So far, the only way to do this is to use:

 Block.setData(byte data); 

So you can do something like this:

 myBlock.setData(2); // Set block data to 2 

Although Block.setData() deprecated, it still works and will continue to work (legacy methods in Bukkit are rarely deleted, especially those for which there is no alternative). I would like to give a better answer, but this is the only thing you can do at the moment.

The reason it is deprecated is because Minecraft is moving away from item identifiers and switching to item names to make it easier to expand in the future. Where you had to run /give player 19 , you should now run /give player minecraft:sponge (although the identifier still works). The same thing will happen with the data, instead of giving someone 35:14 , now you give them red wool .

To get rid of the warning given by the deprecated method, put @SuppressWarnings("deprecation") above the deprecated method when using it or above the method in which it is used.

To specify the type of block, you can use:

 Block.setType(Material type); 

Example:

 myBlock.setType(Material.GOLD_BLOCK); // Set block to gold block 

You can also use MaterialData , but no one knows how to use it (as far as I know). This is one of the things included in the Bukkit API, but no one knows why.

The source of WorldEdit and most of the other plugins look messy because they use many interfaces. For developers, this seems very organized, but for someone who reads it, it looks very dirty if you cannot really visualize the hierarchy.

+9
source

Source: https://habr.com/ru/post/1212114/


All Articles