Prevent players from placing blocks inside themselves

This commit is contained in:
2026-09-29 19:09:20 -03:00
parent f76cf2bf38
commit f0cf4e4eeb
5 changed files with 93 additions and 3 deletions
+13
View File
@@ -162,6 +162,19 @@ 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
export function box_overlaps_block(
entity: { x: number; y: number; z: number; width: number; height: number },
bx: number,
by: number,
bz: number,
): 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;
}
// numeric so looking chunks up doesnt allocate a string every time, fine for |x|, |z| < 32768
export function chunk_key(x: number, z: number) {
return (x + 32768) * 65536 + (z + 32768);