diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 13840aae6..633f00a3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -48,6 +48,7 @@ public class BlockType { private final String id; private final Function values; private final AtomicReference defaultState = new AtomicReference<>(); + private final AtomicReference emptyFuzzy = new AtomicReference<>(); private final AtomicReference>> properties = new AtomicReference<>(); private final AtomicReference blockMaterial = new AtomicReference<>(); private final AtomicReference, Object>, BlockState>> blockStatesMap = new AtomicReference<>(); @@ -156,6 +157,10 @@ public class BlockType { }); } + public FuzzyBlockState getFuzzyMatcher() { + return updateField(emptyFuzzy, () -> new FuzzyBlockState(this)); + } + /** * Gets a list of all possible states for this BlockType. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java index a2082270e..708c50f3c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java @@ -37,11 +37,16 @@ public class FuzzyBlockState extends BlockState { super(blockType); } - @SuppressWarnings("unchecked") - @Override - public BlockState toImmutableState() { + /** + * Gets a full BlockState from this fuzzy one, filling in + * properties with default values where necessary. + * + * @return The full BlockState + */ + public BlockState getFullState() { BlockState state = getBlockType().getDefaultState(); for (Map.Entry, Object> entry : getStates().entrySet()) { + //noinspection unchecked state = state.with((Property) entry.getKey(), entry.getValue()); } return getBlockType().getDefaultState(); @@ -110,6 +115,9 @@ public class FuzzyBlockState extends BlockState { */ public FuzzyBlockState build() { checkNotNull(internalState); + if (values.isEmpty()) { + return internalState.getBlockType().getFuzzyMatcher(); + } FuzzyBlockState blockState = new FuzzyBlockState(internalState.getBlockType()); for (Map.Entry, Object> entry : values.entrySet()) { blockState.setState(entry.getKey(), entry.getValue());