mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-20 07:02:32 +01:00
feat: expose isFaceFull for testing if a block shape has a full face
(cherry picked from commit cf4a2d134e
)
This commit is contained in:
parent
38076fe707
commit
35a4c803d9
@ -9,6 +9,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public interface Shape {
|
public interface Shape {
|
||||||
boolean isOccluded(@NotNull Shape shape, @NotNull BlockFace face);
|
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.
|
* Checks if two bounding boxes intersect.
|
||||||
*
|
*
|
||||||
|
@ -150,6 +150,11 @@ public final class ShapeImpl implements Shape {
|
|||||||
return isFaceCovered(allRectangles) == 2;
|
return isFaceCovered(allRectangles) == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFaceFull(@NotNull BlockFace face) {
|
||||||
|
return (((blockOcclusion >> face.ordinal()) & 1) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersectBox(@NotNull Point position, @NotNull BoundingBox boundingBox) {
|
public boolean intersectBox(@NotNull Point position, @NotNull BoundingBox boundingBox) {
|
||||||
for (BoundingBox blockSection : collisionBoundingBoxes) {
|
for (BoundingBox blockSection : collisionBoundingBoxes) {
|
||||||
|
32
src/test/java/net/minestom/server/collision/TestShape.java
Normal file
32
src/test/java/net/minestom/server/collision/TestShape.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user