Waterlogging

This commit is contained in:
2026-10-07 20:56:24 -03:00
parent 78117f65c9
commit 757ee74bc7
26 changed files with 459 additions and 73 deletions
+24 -8
View File
@@ -1,4 +1,11 @@
import { block_value, chunk_key, default_block_value, liquid_in_cell } from "$/common/utils.ts";
import {
block_value,
chunk_key,
default_block_value,
is_waterlogged,
liquid_block,
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";
@@ -340,10 +347,11 @@ export class ClientLevel {
return nid === VOID || nid === AIR ? undefined : liquid_in_cell(value, this.#blocks[nid]);
}
// water, see is_liquid_block. unloaded chunks aren't
// water, or a block waterlogged with it, see liquid_block. unloaded chunks aren't
is_liquid(x: number, y: number, z: number) {
const block = this.get_block(x, y, z);
return block !== VOID && block !== AIR && is_liquid_block(this.#blocks[block]);
const value = this.get_block_value(x, y, z);
const block = value & ID_MASK;
return block !== VOID && block !== AIR && liquid_block(value, this.#blocks[block]) !== undefined;
}
// only changes what this client shows, drops and everything else happen on the server
@@ -360,10 +368,16 @@ export class ClientLevel {
const ly = y;
const index = ly * CHUNK_SIZE * CHUNK_SIZE + lz * CHUNK_SIZE + lx;
const old_nid = chunk.blocks[index] & ID_MASK;
chunk.blocks[index] = AIR;
const old_value = chunk.blocks[index];
const old_nid = old_value & ID_MASK;
const old_block = this.#blocks[old_nid];
// a waterlogged block leaves its liquid, like the server's destroy_block
const liquid = is_waterlogged(old_value, old_block)
? EverythingRegistry.get_id("blocks", old_block!.waterloggable!) ?? AIR
: AIR;
chunk.blocks[index] = liquid;
this.#mark_dirty(chunk);
this.#mark_neighbors_dirty(block_chunk_x, block_chunk_z, lx, lz, old_nid, AIR);
this.#mark_neighbors_dirty(block_chunk_x, block_chunk_z, lx, lz, old_nid, liquid);
}
// a block that lets through or gives off a different amount of light changes the light up to 15 blocks
@@ -714,8 +728,10 @@ export class ClientLevel {
if (!liquids && is_liquid_block(info)) {
continue;
}
// aimed at liquids, the source in a waterlogged block covers it, like the server's raycast_shape
const covered = liquids && is_waterlogged(value, info);
const hit = clip_shape(
info ? shape_at(info, value) : FULL_SHAPE,
!info || covered ? FULL_SHAPE : shape_at(info, value),
bx,
by,
bz,