Skip to content

Commit

Permalink
Replace more isMovementBlocker calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell committed Jan 8, 2025
1 parent ce5bbe7 commit bf062a6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -456,32 +457,32 @@ 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;
}
}
if (clearanceAbove != clearanceBelow) {
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;
}
}
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit bf062a6

Please sign in to comment.