From 71130025e845f009429725e381fa740841047f46 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 10 Jun 2021 12:46:19 +0100 Subject: [PATCH] Allow `^` mask to be used between blocks that may have different properties, only keeping the shared properties Fixes #1092 --- .../worldedit/function/pattern/StateApplyingPattern.java | 5 ++++- .../worldedit/function/pattern/TypeApplyingPattern.java | 7 +------ .../java/com/sk89q/worldedit/world/block/BlockState.java | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/StateApplyingPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/StateApplyingPattern.java index 5f429d264..a9545c518 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/StateApplyingPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/StateApplyingPattern.java @@ -23,6 +23,7 @@ import com.google.common.collect.Maps; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; +import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -47,7 +48,9 @@ public class StateApplyingPattern extends AbstractExtentPattern { BlockState block = getExtent().getBlock(position); for (Entry, Object> entry : cache .computeIfAbsent(block.getBlockType(), (b -> resolveProperties(states, b))).entrySet()) { - block = block.with(entry.getKey(), entry.getValue()); + if (block.getBlockType().hasProperty(entry.getKey().getKey())) { + block = block.with(entry.getKey(), entry.getValue()); + } } return block.toBaseBlock(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/TypeApplyingPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/TypeApplyingPattern.java index ce2cb8a35..a1db9db3a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/TypeApplyingPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/TypeApplyingPattern.java @@ -41,12 +41,7 @@ public class TypeApplyingPattern extends AbstractExtentPattern { @Override public BaseBlock apply(BlockVector3 position) { BlockState oldBlock = getExtent().getBlock(position); - BlockState newBlock = blockState; - for (Entry, Object> entry : oldBlock.getStates().entrySet()) { - @SuppressWarnings("unchecked") - Property prop = (Property) entry.getKey(); - newBlock = newBlock.with(prop, entry.getValue()); - } + BlockState newBlock = blockState.withProperties(oldBlock); return newBlock.toBaseBlock(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 4572cedda..b2fac7206 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -308,7 +308,7 @@ public class BlockState implements BlockStateHolder, Pattern { newState = newState.with(key, other.getState(key)); } } - return this; + return newState; } @Override