feat: expose isFaceFull for testing if a block shape has a full face

(cherry picked from commit cf4a2d134e)
This commit is contained in:
mworzala 2024-01-27 12:09:41 -05:00 committed by Matt Worzala
parent 38076fe707
commit 35a4c803d9
3 changed files with 45 additions and 0 deletions

View File

@ -9,6 +9,14 @@ import org.jetbrains.annotations.NotNull;
public interface Shape {
boolean isOccluded(@NotNull Shape shape, @NotNull BlockFace face);
/**
* Returns true if the given block face is completely covered by this shape, false otherwise.
* @param face The face to test
*/
default boolean isFaceFull(@NotNull BlockFace face) {
return false;
}
/**
* Checks if two bounding boxes intersect.
*

View File

@ -150,6 +150,11 @@ public final class ShapeImpl implements Shape {
return isFaceCovered(allRectangles) == 2;
}
@Override
public boolean isFaceFull(@NotNull BlockFace face) {
return (((blockOcclusion >> face.ordinal()) & 1) == 1);
}
@Override
public boolean intersectBox(@NotNull Point position, @NotNull BoundingBox boundingBox) {
for (BoundingBox blockSection : collisionBoundingBoxes) {

View File

@ -0,0 +1,32 @@
package net.minestom.server.collision;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockFace;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestShape {
private static @NotNull Stream<Arguments> isFullFaceCases() {
return Stream.of(
Arguments.of(Block.STONE, BlockFace.BOTTOM, true),
Arguments.of(Block.ENCHANTING_TABLE, BlockFace.BOTTOM, true),
Arguments.of(Block.ENCHANTING_TABLE, BlockFace.TOP, false),
Arguments.of(Block.ENCHANTING_TABLE, BlockFace.NORTH, false),
Arguments.of(Block.ACACIA_FENCE, BlockFace.TOP, false),
Arguments.of(Block.IRON_BARS, BlockFace.TOP, false)
);
}
@ParameterizedTest
@MethodSource("isFullFaceCases")
void isFullFace(@NotNull Block block, @NotNull BlockFace face, boolean isFullFace) {
assertEquals(block.registry().collisionShape().isFaceFull(face), isFullFace);
}
}