Engine api

This commit is contained in:
2026-10-06 20:27:17 -03:00
parent d13938550d
commit 69c5c187db
27 changed files with 1026 additions and 90 deletions
+6 -4
View File
@@ -1,5 +1,5 @@
import { PLAYER_EYE_HEIGHT, PLAYER_HEIGHT, PLAYER_SWIM_EYE_HEIGHT, TICK_DELTA } from "$/common/constants.ts";
import { back_off_from_edge, box_is_free } from "$/common/physics.ts";
import { physics } from "$/common/physics.ts";
import type { Client } from "../client.ts";
import { InputManager } from "../input_manager.ts";
import { ClientInventories } from "../inventory.ts";
@@ -158,7 +158,7 @@ export class LocalPlayer extends Player {
// not while jumping, so it can still jump off a ledge
if (this.sneaking && this.on_ground && this.vy <= 0) {
const is_solid = (x: number, y: number, z: number) => this.level.collision_shape(x, y, z);
const [dx, dz] = back_off_from_edge(
const [dx, dz] = physics.back_off_from_edge(
this,
this.vx * TICK_DELTA,
this.vz * TICK_DELTA,
@@ -195,7 +195,9 @@ export class LocalPlayer extends Player {
vy: 0,
vz: 0,
};
if (box_is_free(standing, 0, 0, 0, (x, y, z) => this.level.collision_shape(x, y, z))) this.set_swimming(false);
if (physics.box_is_free(standing, 0, 0, 0, (x, y, z) => this.level.collision_shape(x, y, z))) {
this.set_swimming(false);
}
}
// turns up or down toward where it's looking. not up once its head is out, so it swims along the surface instead
@@ -234,7 +236,7 @@ export class LocalPlayer extends Player {
const blocked = (x: number, y: number, z: number) =>
this.level.is_liquid(x, y, z) || this.level.collision_shape(x, y, z);
const dy = from_y - this.y + this.vy * TICK_DELTA + WATER_HOP_HEIGHT;
if (box_is_free(this, this.vx * TICK_DELTA, dy, this.vz * TICK_DELTA, blocked)) this.vy = WATER_HOP;
if (physics.box_is_free(this, this.vx * TICK_DELTA, dy, this.vz * TICK_DELTA, blocked)) this.vy = WATER_HOP;
}
// how much wider the view is than the fov option, between the last tick and this one