Fix bug with fences

This commit is contained in:
2026-10-11 16:52:55 -03:00
parent cd943246d0
commit c3bc1b3501
2 changed files with 29 additions and 13 deletions
+14 -13
View File
@@ -40,6 +40,7 @@ import {
waterlog_placement,
} from "$/common/utils.ts";
import { collision_shape_at, type Shape } from "$/common/block_shapes.ts";
import { physics } from "$/common/physics.ts";
import { EXHAUSTION } from "./vitals.ts";
import {
type BlockComponentOf,
@@ -1744,20 +1745,20 @@ export class GameServer {
}
}
// feet on top of something solid, anywhere under the player's box
// feet on top of something solid, anywhere under the player's box: a thin box just under their feet touches a
// block's collision shape. shapes, not whole blocks, so standing on a fence, a slab or a path counts too
#on_ground(x: number, y: number, z: number) {
const fraction = y - Math.floor(y);
if (fraction > GROUND_EPSILON && fraction < 1 - GROUND_EPSILON) {
return false;
}
const below = Math.floor(y - GROUND_EPSILON);
const half = PLAYER_WIDTH / 2;
for (const [ox, oz] of [[-half, -half], [half, -half], [-half, half], [half, half]]) {
if (this.world.has_collision(Math.floor(x + ox), below, Math.floor(z + oz))) {
return true;
}
}
return false;
const under_feet = {
x,
y: y - GROUND_EPSILON,
z,
vx: 0,
vy: 0,
vz: 0,
width: PLAYER_WIDTH,
height: GROUND_EPSILON,
};
return !physics.box_is_free(under_feet, 0, 0, 0, (bx, by, bz) => this.world.collision_shape(bx, by, bz));
}
// in liquid, a waterlogged block's too