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
+4 -4
View File
@@ -8,7 +8,7 @@ import { TICKS_PER_SECOND } from "$/common/constants.ts";
import type { BlockRegistry } from "$/common/everything_registry.ts";
import type { ItemStack } from "$/common/inventory.ts";
import type { Shape } from "$/common/block_shapes.ts";
import { type Collisions, eyes_in_water, in_water, move_body } from "$/common/physics.ts";
import { type Collisions, physics } from "$/common/physics.ts";
import type { EntityData, EntityEvent, EntityInfo } from "$/common/protocol.ts";
import type { ServerPlayer } from "../player.ts";
@@ -247,19 +247,19 @@ export abstract class Entity {
}
update_in_water() {
this.in_water = in_water(this, (x, y, z) => this.level.is_liquid(x, y, z));
this.in_water = physics.in_water(this, (x, y, z) => this.level.is_liquid(x, y, z));
}
// its eyes are in water, so it can't breathe
get eyes_in_water() {
return eyes_in_water(this, this.eye_height, (x, y, z) => this.level.is_liquid(x, y, z));
return physics.eyes_in_water(this, this.eye_height, (x, y, z) => this.level.is_liquid(x, y, z));
}
// falls and moves by its velocity for one tick (see move_body), and counts how far it fell. returns what it hit
move(): Collisions {
const is_solid = (x: number, y: number, z: number) => this.level.collision_shape(x, y, z);
const from_y = this.y;
const collisions = move_body(
const collisions = physics.move_body(
this,
this.no_gravity ? 0 : this.gravity,
is_solid,