Water phyisics

This commit is contained in:
2026-10-07 19:38:27 -03:00
parent d101fa2ef3
commit 78117f65c9
13 changed files with 338 additions and 13 deletions
+8
View File
@@ -144,6 +144,14 @@ export class LocalPlayer extends Player {
this.gravity = this.flying ? 0 : !this.#in_water ? LAND_GRAVITY : this.swimming ? 0 : WATER_GRAVITY;
this.drag = this.flying ? FLY_VERTICAL_DRAG : this.#in_water ? WATER_DRAG : LAND_DRAG;
if (this.swimming && this.#in_water) this.#steer(input);
if (!this.flying) {
physics.push_by_liquid(
this,
(x, y, z) => this.level.liquid_at(x, y, z),
(x, y, z) => this.level.collision_shape(x, y, z),
true,
);
}
this.#prev_eye_height = this.eye_height;
const eye_height = this.swimming
? PLAYER_SWIM_EYE_HEIGHT
+8 -1
View File
@@ -1,4 +1,4 @@
import { block_value, chunk_key, default_block_value } from "$/common/utils.ts";
import { block_value, chunk_key, default_block_value, liquid_in_cell } from "$/common/utils.ts";
import { AIR_ID } from "$/common/protocol.ts";
import { decode_level_chunk } from "$/common/chunk_streaming.ts";
import { DEFAULT_WATER_COLOR, foliage_color, grass_color, water_color } from "$/common/worldgen/biome_colors.ts";
@@ -333,6 +333,13 @@ export class ClientLevel {
.biome_colors[CHUNK_AREA * 2 + (z - chunk_z * CHUNK_SIZE) * CHUNK_SIZE + (x - chunk_x * CHUNK_SIZE)];
}
// the liquid there and how high it is, for liquids pushing things along. unloaded chunks have none
liquid_at(x: number, y: number, z: number) {
const value = this.get_block_value(x, y, z);
const nid = value & ID_MASK;
return nid === VOID || nid === AIR ? undefined : liquid_in_cell(value, this.#blocks[nid]);
}
// water, see is_liquid_block. unloaded chunks aren't
is_liquid(x: number, y: number, z: number) {
const block = this.get_block(x, y, z);