[SPIGOT-5512] Allow changing the type of a block while retaining the data of BlockData Created: 12/Jan/20  Updated: 21/Jan/24  Resolved: 21/Jan/24

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: KoekenMeneer Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: BlockData

Issue Links:
Duplicate
is duplicated by SPIGOT-5438 Updating a sign type using BlockState... Resolved
Version: 1.15
Guidelines Read: Yes

 Description   

There are several Material's which share the same BlockData class, such as Door, Leaves, Gate, Stairs and Sign. It would be nice if we could switch out the type while retaining all the other data that resides within the BlockData. That is, as long as the new type also uses the same BlockData class. This would allow changing for example a sign material while retaining it's lines and rotation, or changing a door while keeping the hinge and open state the same.

This feature request is related to:
https://hub.spigotmc.org/jira/browse/SPIGOT-5438



 Comments   
Comment by Marvin Rieple [ 21/Jan/24 ]

This is now possible with the BlockData#copyTo(BlockData) method added in 1.20.4.
Bukkit commit: 8872404e4b706ac9fdbdac45066198eedba06e15
CraftBukkit commit: 95bc1c4f52a23b97d288093c271117801f35a2ae

Comment by user-34831 (Inactive) [ 28/Jan/20 ]

for preserving rotations I use below.

It might not be the best way but it works.

the text on a sign isn't blockdata though. its block state .

 

String data = b.getBlockData().getAsString();
b.setBlockData(Bukkit.createBlockData(data.replaceFirst("birch_leaves", "oak_leaves")));
Generated at Tue Apr 15 09:25:36 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.