From 7581cde32e80d5c4f7d82dd97c5aa417bf9b9fd0 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 15 Jan 2024 20:33:17 +1100 Subject: [PATCH] #1333: Add BlockData#copyTo By: Jishuna --- .../craftbukkit/block/data/CraftBlockData.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index 61b37f516c..ffbe9b3958 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -660,6 +660,23 @@ public class CraftBlockData implements BlockData { this.state = state.mirror(EnumBlockMirror.valueOf(mirror.name())); } + @Override + public void copyTo(BlockData blockData) { + CraftBlockData other = (CraftBlockData) blockData; + IBlockData nms = other.state; + for (IBlockState property : state.getBlock().getStateDefinition().getProperties()) { + if (nms.hasProperty(property)) { + nms = copyProperty(state, nms, property); + } + } + + other.state = nms; + } + + private > IBlockData copyProperty(IBlockData source, IBlockData target, IBlockState property) { + return target.setValue(property, source.getValue(property)); + } + @NotNull @Override public BlockState createBlockState() {