This commit is contained in:
2026-11-16 23:49:42 -03:00
parent 94b0e3789c
commit eedaa955f6
13 changed files with 148 additions and 2 deletions
+14
View File
@@ -231,6 +231,19 @@ function overlaps_solid(min: number[], max: number[], is_solid: BlockCollision)
return false;
}
// every block the body's box is in, whatever's there, like minecraft's checkInsideBlocks. a box resting exactly on
// a face isn't in the block on the other side
export function blocks_inside(body: Body, visit: (x: number, y: number, z: number) => void) {
const half = body.width / 2;
for (let x = Math.floor(body.x - half + EPSILON); x <= Math.floor(body.x + half - EPSILON); x++) {
for (let y = Math.floor(body.y + EPSILON); y <= Math.floor(body.y + body.height - EPSILON); y++) {
for (let z = Math.floor(body.z - half + EPSILON); z <= Math.floor(body.z + half - EPSILON); z++) {
visit(x, y, z);
}
}
}
}
// in water like minecraft's wasTouchingWater, close enough: its feet or the middle of its box are in fluid
export function in_water(body: Body, is_fluid: (x: number, y: number, z: number) => boolean): boolean {
const x = Math.floor(body.x);
@@ -390,6 +403,7 @@ export const physics = {
move_body,
back_off_from_edge,
box_is_free,
blocks_inside,
in_water,
eyes_in_water,
fluid_flow,