diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/heightmap/HeightMapType.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/heightmap/HeightMapType.java index cb5339737e..5a576271b8 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/heightmap/HeightMapType.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/heightmap/HeightMapType.java @@ -1,6 +1,7 @@ package com.fastasyncworldedit.core.extent.processor.heightmap; import com.fastasyncworldedit.core.registry.state.PropertyKey; +import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; @@ -17,19 +18,19 @@ public enum HeightMapType { MOTION_BLOCKING { @Override public boolean includes(BlockState state) { - return state.getMaterial().isMovementBlocker() || HeightMapType.hasFluid(state); + return isMovementBlocker(state) || HeightMapType.hasFluid(state); } }, MOTION_BLOCKING_NO_LEAVES { @Override public boolean includes(BlockState state) { - return (state.getMaterial().isMovementBlocker() || HeightMapType.hasFluid(state)) && !HeightMapType.isLeaf(state); + return (isMovementBlocker(state) || HeightMapType.hasFluid(state)) && !HeightMapType.isLeaf(state); } }, OCEAN_FLOOR { @Override public boolean includes(BlockState state) { - return state.getMaterial().isMovementBlocker(); + return HeightMapType.isMovementBlocker(state); } }, WORLD_SURFACE { @@ -39,6 +40,10 @@ public boolean includes(BlockState state) { } }; + private static boolean isMovementBlocker(BlockState state) { + return SolidBlockMask.isSolid(state); + } + static { BlockCategories.LEAVES.getAll(); // make sure this category is initialized, otherwise isLeaf might fail } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java index 1dccfdc49e..28584ababa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java @@ -47,6 +47,7 @@ import com.sk89q.worldedit.function.mask.BlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.BlockPattern; @@ -456,17 +457,17 @@ default int getNearestSurfaceTerrainBlock( int clearanceBelow = y - minY; int clearance = Math.min(clearanceAbove, clearanceBelow); BlockState block = getBlock(x, y, z); - boolean state = !block.getBlockType().getMaterial().isMovementBlocker(); + boolean state = !SolidBlockMask.isSolid(block); int offset = state ? 0 : 1; for (int d = 0; d <= clearance; d++) { int y1 = y + d; block = getBlock(x, y1, z); - if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) { + if (matchesSolidState(block, state)) { return y1 - offset; } int y2 = y - d; block = getBlock(x, y2, z); - if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) { + if (matchesSolidState(block, state)) { return y2 + offset; } } @@ -474,14 +475,14 @@ default int getNearestSurfaceTerrainBlock( if (clearanceAbove < clearanceBelow) { for (int layer = y - clearance - 1; layer >= minY; layer--) { block = getBlock(x, layer, z); - if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) { + if (matchesSolidState(block, state)) { return layer + offset; } } } else { for (int layer = y + clearance + 1; layer <= maxY; layer++) { block = getBlock(x, layer, z); - if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) { + if (matchesSolidState(block, state)) { return layer - offset; } } @@ -495,6 +496,10 @@ default int getNearestSurfaceTerrainBlock( return result; } + private static boolean matchesSolidState(BlockState block, boolean state) { + return SolidBlockMask.isSolid(block) == state && block.getBlockType() != BlockTypes.__RESERVED__; + } + default void addCaves(Region region) throws WorldEditException { generate(region, new CavesGen(8)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java index b1608e2cee..7a248e1e3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java @@ -21,6 +21,7 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypesCache; public class SolidBlockMask extends AbstractExtentMask { @@ -52,6 +53,15 @@ public boolean test(final BlockVector3 vector) { return test(getExtent(), vector); } + /** + * {@return whether the given block state is considered solid by this mask} + * @since TODO + */ + public static boolean isSolid(BlockState blockState) { + return SOLID[blockState.getOrdinal()]; + } + + @Override public Mask copy() { return new SolidBlockMask(getExtent());