Fix bug with fences
This commit is contained in:
+14
-13
@@ -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
|
||||
|
||||
@@ -92,6 +92,21 @@ Deno.test("falling more than 3 blocks hurts, 1 per block after that, and water b
|
||||
assertEquals(t.player.health, MAX_HEALTH);
|
||||
});
|
||||
|
||||
Deno.test("landing on a fence ends a fall, so jumping on one and stepping off doesn't hurt", async () => {
|
||||
const t = await setup();
|
||||
// a fence's top is 1.5 blocks up, so standing on it isn't at a whole block
|
||||
t.game.set_block(0, 100, 0, "bworld:oak_fence");
|
||||
const at = (x: number, y: number) => t.send(1, { type: "move", x, y, z: 0.5, yaw: 0, pitch: 0 });
|
||||
at(0.5, 101.5);
|
||||
for (let jump = 0; jump < 4; jump++) {
|
||||
for (const y of [102, 102.5, 102.75, 102.5, 102, 101.5]) at(0.5, y);
|
||||
}
|
||||
// off it, onto the stone
|
||||
at(1.5, 101.5);
|
||||
for (const y of [101, 100.5, 100]) at(1.5, y);
|
||||
assertEquals(t.player.health, MAX_HEALTH);
|
||||
});
|
||||
|
||||
Deno.test("health and hunger are sent to the player when they change, and saved", async () => {
|
||||
const t = await setup();
|
||||
t.take(1);
|
||||
|
||||
Reference in New Issue
Block a user