Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set block data value? [closed]

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

Deprecated. Magic value

Why is that?

like image 909
Myst Avatar asked Jan 28 '15 15:01

Myst


People also ask

How do you set a block of data?

You change the data tag for a block using the /blockdata command in Minecraft. TIP: Starting in Minecraft Java Edition (PC/Mac) 1.13, the /blockdata command was replaced by the /data command.

What is the command to set blocks in Minecraft?

Use /setblock! The /setblock command in Minecraft allows the user to change a block at a specific coordinates in their current Minecraft world to the block specified. The usage and syntax of this command depends on which platform (Java or Bedrock) you are using it.


1 Answers

So far, the only way to do it is by using:

Block.setData(byte data);

So, you could do something like this:

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

Although Block.setData() is deprecated, it still works, and will continue to work (deprecated methods in Bukkit are rarely removed, especially those for which there is no alternative). I wish I could give a better answer, but that's the only thing that you can do, as of now.

The reason it is deprecated is because Minecraft is moving away from item IDs, and switching to item names, to make it easier to expand in the future. Where you used to have to run /give player 19, you are now supposed to run /give player minecraft:sponge (although the ID still works). The same thing is going to happen to data values, instead of giving someone 35:14, you now give them red wool.

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

To set the type of the block, you could use:

Block.setType(Material type);

An example is:

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

You could also use MaterialData, but no one really knows how to use it (as far as I know). It's one of the things included in the Bukkit API, but no one knows why.

The source of WorldEdit and most other big plugins look messy because they use a lot of interfaces. To the developers, it seems very organized, but to someone reading it, it looks very messy, unless you can actually visualize the hierarchy.

like image 81
Jojodmo Avatar answered Oct 23 '22 08:10

Jojodmo