Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/net/minestom/server/collision/ShapeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private static CollisionData collisionData(List<BoundingBox> collisionBoundingBo
}

byte fullCollisionFaces = 0;
for (BlockFace f : BlockFace.values()) {
for (BlockFace f : BlockFace.getValues()) {
final byte res = isFaceCovered(computeOcclusionSet(f, collisionBoundingBoxes));
fullCollisionFaces |= ((res == 2) ? 0b1 : 0b0) << (byte) f.ordinal();
}
Expand All @@ -219,7 +219,7 @@ private static CollisionData collisionData(List<BoundingBox> collisionBoundingBo
private static LightData lightData(List<BoundingBox> occlusionBoundingBoxes, int lightEmission) {
byte fullFaces = 0;
byte airFaces = 0;
for (BlockFace f : BlockFace.values()) {
for (BlockFace f : BlockFace.getValues()) {
final byte res = isFaceCovered(computeOcclusionSet(f, occlusionBoundingBoxes));
fullFaces |= ((res == 2) ? 0b1 : 0b0) << (byte) f.ordinal();
airFaces |= ((res == 0) ? 0b1 : 0b0) << (byte) f.ordinal();
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/net/minestom/server/instance/block/BlockFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,39 @@
import net.minestom.server.utils.Direction;
import org.jetbrains.annotations.NotNull;

/**
* The enumeration contains all faces which a block can have in the game.
* It's possible that specific blocks doesn't have all faces
* @version 1.0.1
*/
public enum BlockFace {

BOTTOM(Direction.DOWN),
TOP(Direction.UP),
NORTH(Direction.NORTH),
SOUTH(Direction.SOUTH),
WEST(Direction.WEST),
EAST(Direction.EAST);

private static final BlockFace[] VALUES = values();

private final Direction direction;

BlockFace(Direction direction) {
/**
* Creates a new enum entry
*
* @param direction the direction for the entry
*/
BlockFace(@NotNull Direction direction) {
this.direction = direction;
}

public Direction toDirection() {
/**
* Returns the {@link Direction} which correspond with the face.
*
* @return the given direction
*/
public @NotNull Direction toDirection() {
return direction;
}

Expand Down Expand Up @@ -77,4 +95,12 @@ public static BlockFace fromDirection(Direction direction) {
case EAST -> EAST;
};
}

/**
* Returns the static accessor which caches all entries from the values call.
* @return the given array
*/
public static @NotNull BlockFace[] getValues() {
return VALUES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ShortArrayFIFOQueue buildExternalQueue(Palette blockPalette,
ShortArrayFIFOQueue lightSources = new ShortArrayFIFOQueue();

for (int i = 0; i < neighbors.length; i++) {
final BlockFace face = BlockFace.values()[i];
final BlockFace face = BlockFace.getValues()[i];
Point neighborSection = neighbors[i];
if (neighborSection == null) continue;

Expand Down Expand Up @@ -203,7 +203,7 @@ public Set<Point> calculateExternal(Palette blockPalette,
for (int i = 0; i < neighbors.length; i++) {
final Point neighbor = neighbors[i];
if (neighbor == null) continue;
final BlockFace face = BlockFace.values()[i];
final BlockFace face = BlockFace.getValues()[i];
if (!LightCompute.compareBorders(content, contentPropagation, contentPropagationTemp, face)) {
toUpdate.add(neighbor);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/minestom/server/instance/light/Light.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ static Point[] getNeighbors(Chunk chunk, int sectionY) {
final int chunkX = chunk.getChunkX();
final int chunkZ = chunk.getChunkZ();

Point[] links = new Vec[BlockFace.values().length];
for (BlockFace face : BlockFace.values()) {
final BlockFace[] faces = BlockFace.getValues();

Point[] links = new Vec[faces.length];
for (BlockFace face : faces) {
final Direction direction = face.toDirection();
final int x = chunkX + direction.normalX();
final int z = chunkZ + direction.normalZ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ShortArrayFIFOQueue buildExternalQueue(Palette blockPalette,
ShortArrayFIFOQueue lightSources = new ShortArrayFIFOQueue();

for (int i = 0; i < neighbors.length; i++) {
final BlockFace face = BlockFace.values()[i];
final BlockFace face = BlockFace.getValues()[i];
Point neighborSection = neighbors[i];
if (neighborSection == null) continue;

Expand Down Expand Up @@ -225,7 +225,7 @@ public Set<Point> calculateExternal(Palette blockPalette,
for (int i = 0; i < neighbors.length; i++) {
final Point neighbor = neighbors[i];
if (neighbor == null) continue;
final BlockFace face = BlockFace.values()[i];
final BlockFace face = BlockFace.getValues()[i];
if (!LightCompute.compareBorders(content, contentPropagation, contentPropagationTemp, face)) {
toUpdate.add(neighbor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record ClientPlayerDiggingPacket(@NotNull Status status, @NotNull Point b
@NotNull BlockFace blockFace, int sequence) implements ClientPacket {
public ClientPlayerDiggingPacket(@NotNull NetworkBuffer reader) {
this(reader.readEnum(Status.class), reader.read(BLOCK_POSITION),
BlockFace.values()[reader.read(BYTE)], reader.read(VAR_INT));
BlockFace.getValues()[reader.read(BYTE)], reader.read(VAR_INT));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BlockIsOccludedTest {
void blockAir() {
Shape airBlock = Block.AIR.registry().collisionShape();

for (BlockFace face : BlockFace.values()) {
for (BlockFace face : BlockFace.getValues()) {
assertFalse(airBlock.isOccluded(airBlock, face));
}
}
Expand All @@ -25,7 +25,7 @@ void blockLantern() {
Shape shape = Block.LANTERN.registry().collisionShape();
Shape airBlock = Block.AIR.registry().collisionShape();

for (BlockFace face : BlockFace.values()) {
for (BlockFace face : BlockFace.getValues()) {
assertFalse(shape.isOccluded(airBlock, face));
}
}
Expand All @@ -35,7 +35,7 @@ void blockSpruceLeaves() {
Shape shape = Block.SPRUCE_LEAVES.registry().collisionShape();
Shape airBlock = Block.AIR.registry().collisionShape();

for (BlockFace face : BlockFace.values()) {
for (BlockFace face : BlockFace.getValues()) {
assertFalse(shape.isOccluded(airBlock, face));
}
}
Expand All @@ -45,7 +45,7 @@ void blockCauldron() {
Shape shape = Block.CAULDRON.registry().collisionShape();
Shape airBlock = Block.AIR.registry().collisionShape();

for (BlockFace face : BlockFace.values()) {
for (BlockFace face : BlockFace.getValues()) {
assertFalse(shape.isOccluded(airBlock, face));
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ void blockStone() {
Shape shape = Block.STONE.registry().collisionShape();
Shape airBlock = Block.AIR.registry().collisionShape();

for (BlockFace face : BlockFace.values()) {
for (BlockFace face : BlockFace.getValues()) {
assertTrue(shape.isOccluded(airBlock, face));
}
}
Expand Down