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
+8 -2
View File
@@ -2,7 +2,7 @@
// see docs/modding/. parts not built yet throw when used, saying so
import { BlockRegistry, EverythingRegistry, ItemRegistry, liquid_height } from "$/common/everything_registry.ts";
import { Container as EngineContainer, ItemStack as EngineItemStack } from "$/common/inventory.ts";
import { get_state_value, set_state_value } from "$/common/utils.ts";
import { get_state_value, is_waterlogged, liquid_block, set_state_value } from "$/common/utils.ts";
import { collision_shape_at, covers_face, raycast_blocks, type Shape } from "$/common/block_shapes.ts";
import { AIR, ID_MASK } from "$/common/constants.ts";
import { BlockRules } from "$/common/block_rules.ts";
@@ -666,8 +666,12 @@ export class ModRuntime {
(x, y, z) => raycast_shape(world, x, y, z, liquids),
);
if (!hit) return undefined;
// what was hit in a waterlogged block with liquids on is its liquid, see raycast_shape
const value = world.get_block_value(hit.x, hit.y, hit.z);
const block = world.get_block_info(hit.x, hit.y, hit.z);
const liquid = liquids === "none" ? undefined : liquid_block(value, block);
return {
id: world.get_block_id(hit.x, hit.y, hit.z),
id: liquid?.id ?? world.get_block_id(hit.x, hit.y, hit.z),
x: hit.x,
y: hit.y,
z: hit.z,
@@ -1099,6 +1103,8 @@ function raycast_shape(
if (liquids === "none" || (liquids === "source_only" && level !== 0)) return undefined;
return [[0, 0, 0, 1, liquid_height(level, block.liquid.range), 1]];
}
// the source in a waterlogged block covers the block, like minecraft's fluid clip
if (liquids !== "none" && is_waterlogged(value, block)) return [[0, 0, 0, 1, 1, 1]];
const shape = collision_shape_at(block, value);
return shape.length > 0 ? shape : undefined;
}