Basic swimming

This commit is contained in:
2026-10-01 21:12:30 -03:00
parent 6e5703a482
commit d5015edfa1
10 changed files with 203 additions and 20 deletions
+3 -6
View File
@@ -7,7 +7,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 Collisions, move_body } from "$/common/physics.ts";
import { type Collisions, eyes_in_water, in_water, move_body } from "$/common/physics.ts";
import type { EntityData, EntityEvent, EntityInfo } from "$/common/protocol.ts";
import type { ServerPlayer } from "../player.ts";
@@ -239,15 +239,12 @@ export abstract class Entity {
}
update_in_water() {
const x = Math.floor(this.x);
const z = Math.floor(this.z);
this.in_water = this.level.is_liquid(x, Math.floor(this.y), z) ||
this.level.is_liquid(x, Math.floor(this.y + this.height / 2), z);
this.in_water = 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 this.level.is_liquid(Math.floor(this.x), Math.floor(this.y + this.eye_height), Math.floor(this.z));
return 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