Better block models !

This commit is contained in:
2026-10-03 15:57:47 -03:00
parent ecc0295f6d
commit 24fe7cdede
23 changed files with 678 additions and 122 deletions
+9 -4
View File
@@ -1,6 +1,7 @@
import { ID_MASK, STATE_SHIFT } from "./constants.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_registry.ts";
import { block_item_texture, cube_face_texture } from "./block_models.ts";
import { FULL_SHAPE, type Shape } from "./block_shapes.ts";
import type { ItemStack } from "./inventory.ts";
import { list_matches } from "./tags.ts";
@@ -163,17 +164,21 @@ export function can_place(
return in_ok && can_stand_on(block, below);
}
// whether an entity's collision box, centered on x and z with its feet at y, overlaps the block at bx, by, bz
// whether an entity's collision box, centered on x and z with its feet at y, overlaps the block at bx, by, bz. only
// the block's boxes count when given its shape, so a slab's empty half doesn't
export function box_overlaps_block(
entity: { x: number; y: number; z: number; width: number; height: number },
bx: number,
by: number,
bz: number,
shape: Shape = FULL_SHAPE,
): boolean {
const half = entity.width / 2;
return entity.x + half > bx && entity.x - half < bx + 1 &&
entity.y + entity.height > by && entity.y < by + 1 &&
entity.z + half > bz && entity.z - half < bz + 1;
return shape.some((box) =>
entity.x + half > bx + box[0] && entity.x - half < bx + box[3] &&
entity.y + entity.height > by + box[1] && entity.y < by + box[4] &&
entity.z + half > bz + box[2] && entity.z - half < bz + box[5]
);
}
// numeric so looking chunks up doesnt allocate a string every time, fine for |x|, |z| < 32768