collisionBoxesOf function

List<CollisionBox> collisionBoxesOf(
  1. BlockShape shape, {
  2. required bool solid,
})

The boxes a body collides with, in the block's own 0..1 space. Empty for a block that stops no body. Stairs: the bottom slab plus the high step at the back, the same halves the mesher draws (N = high step at z 0..0.5, E = at x 0.5..1). A fence is its lone post here and a ladder nothing: the arms and the ladder's wall depend on the neighbours, which collisionBoxesAt reads. The lists are constants: never mutate one.

Implementation

List<CollisionBox> collisionBoxesOf(BlockShape shape, {required bool solid}) {
  if (!solid) return const [];
  const half = CollisionBox(0, 0, 0, 1, 0.5, 1);
  return switch (shape) {
    BlockShape.slab => const [half],
    BlockShape.fence => const [CollisionBox.fencePost],
    BlockShape.stairsN => const [half, CollisionBox(0, 0.5, 0, 1, 1, 0.5)],
    BlockShape.stairsS => const [half, CollisionBox(0, 0.5, 0.5, 1, 1, 1)],
    BlockShape.stairsE => const [half, CollisionBox(0.5, 0.5, 0, 1, 1, 1)],
    BlockShape.stairsW => const [half, CollisionBox(0, 0.5, 0, 0.5, 1, 1)],
    _ => const [CollisionBox.full],
  };
}