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
+10 -1
View File
@@ -1,8 +1,9 @@
import { ID_MASK, STATE_SHIFT } from "./constants.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_registry.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry, liquid_height } from "./everything_registry.ts";
import { block_item_texture, cube_face_texture } from "./block_models.ts";
import { FULL_SHAPE, type Shape } from "./block_shapes.ts";
import type { ItemStack } from "./inventory.ts";
import type { LiquidInCell } from "./physics.ts";
import { list_matches } from "./tags.ts";
export function point_inside_rec(
@@ -185,3 +186,11 @@ export function box_overlaps_block(
export function chunk_key(x: number, z: number) {
return (x + 32768) * 65536 + (z + 32768);
}
// the liquid a block value is, for liquids pushing things (see push_by_liquid in physics.ts), or undefined for blocks
// that aren't liquids
export function liquid_in_cell(value: number, block: BlockRegistry | undefined): LiquidInCell | undefined {
if (!block?.liquid) return undefined;
const level = get_state_value(value, block, "level") ?? 0;
return { id: value & ID_MASK, height: liquid_height(level, block.liquid.range) };
}