Rename all "liquid" mentions to "fluid"
This commit is contained in:
+18
-18
@@ -3,9 +3,9 @@
|
||||
|
||||
// runs mods' server scripts: builds each one's ServerContext and keeps what they register.
|
||||
// see docs/modding/. parts not built yet throw when used, saying so
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry, liquid_height } from "$/common/everything_registry.ts";
|
||||
import { BlockRegistry, EverythingRegistry, fluid_height, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { Container as EngineContainer, ItemStack as EngineItemStack } from "$/common/inventory.ts";
|
||||
import { block_states, get_state_value, is_waterlogged, liquid_block, set_state_value } from "$/common/utils.ts";
|
||||
import { block_states, fluid_block, get_state_value, is_waterlogged, set_state_value } from "$/common/utils.ts";
|
||||
import { LootTables } from "./loot.ts";
|
||||
import { collision_shape_at, covers_face, is_solid, raycast_blocks, type Shape } from "$/common/block_shapes.ts";
|
||||
import { AIR, CHUNK_SIZE, faces, ID_MASK } from "$/common/constants.ts";
|
||||
@@ -803,9 +803,9 @@ export class ModRuntime {
|
||||
return entity_ref(entity);
|
||||
},
|
||||
raycast: (from, to, options) => {
|
||||
const liquids = options?.liquids ?? "none";
|
||||
if (!["none", "source_only", "any"].includes(liquids)) {
|
||||
throw new Error(`liquids must be "none", "source_only" or "any", not ${liquids}`);
|
||||
const fluids = options?.fluids ?? "none";
|
||||
if (!["none", "source_only", "any"].includes(fluids)) {
|
||||
throw new Error(`fluids must be "none", "source_only" or "any", not ${fluids}`);
|
||||
}
|
||||
const origin = [from.x, from.y, from.z];
|
||||
const length = Math.hypot(to.x - from.x, to.y - from.y, to.z - from.z);
|
||||
@@ -817,15 +817,15 @@ export class ModRuntime {
|
||||
origin,
|
||||
direction,
|
||||
length,
|
||||
(x, y, z) => raycast_shape(world, x, y, z, liquids),
|
||||
(x, y, z) => raycast_shape(world, x, y, z, fluids),
|
||||
);
|
||||
if (!hit) return undefined;
|
||||
// what was hit in a waterlogged block with liquids on is its liquid, see raycast_shape
|
||||
// what was hit in a waterlogged block with fluids on is its fluid, 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);
|
||||
const fluid = fluids === "none" ? undefined : fluid_block(value, block);
|
||||
return {
|
||||
id: liquid?.id ?? world.get_block_id(hit.x, hit.y, hit.z),
|
||||
id: fluid?.id ?? world.get_block_id(hit.x, hit.y, hit.z),
|
||||
x: hit.x,
|
||||
y: hit.y,
|
||||
z: hit.z,
|
||||
@@ -837,12 +837,12 @@ export class ModRuntime {
|
||||
},
|
||||
};
|
||||
},
|
||||
liquid_flow: (x, y, z) => {
|
||||
const [fx, fy, fz] = physics.liquid_flow(
|
||||
fluid_flow: (x, y, z) => {
|
||||
const [fx, fy, fz] = physics.fluid_flow(
|
||||
Math.floor(x),
|
||||
Math.floor(y),
|
||||
Math.floor(z),
|
||||
(x, y, z) => game().entities.liquid_at(x, y, z),
|
||||
(x, y, z) => game().entities.fluid_at(x, y, z),
|
||||
(x, y, z) => game().world.collision_shape(x, y, z),
|
||||
);
|
||||
// without any -0
|
||||
@@ -1315,27 +1315,27 @@ function container_api(game: GameServer, id: string, container: EngineContainer)
|
||||
return api;
|
||||
}
|
||||
|
||||
// what ServerWorld.raycast hits in a block: what entities bump into, and liquids up to their surface when it's
|
||||
// what ServerWorld.raycast hits in a block: what entities bump into, and fluids up to their surface when it's
|
||||
// looking for them
|
||||
function raycast_shape(
|
||||
world: GameServer["world"],
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
liquids: "none" | "source_only" | "any",
|
||||
fluids: "none" | "source_only" | "any",
|
||||
): Shape | undefined {
|
||||
const value = world.get_block_value(x, y, z);
|
||||
const nid = value & ID_MASK;
|
||||
if (nid === AIR) return undefined;
|
||||
const block = EverythingRegistry.get_by_id<BlockRegistry>("blocks", nid);
|
||||
if (!block) return undefined;
|
||||
if (block.liquid) {
|
||||
if (block.fluid) {
|
||||
const level = get_state_value(value, block, "level") ?? 0;
|
||||
if (liquids === "none" || (liquids === "source_only" && level !== 0)) return undefined;
|
||||
return [[0, 0, 0, 1, liquid_height(level, block.liquid.range), 1]];
|
||||
if (fluids === "none" || (fluids === "source_only" && level !== 0)) return undefined;
|
||||
return [[0, 0, 0, 1, fluid_height(level, block.fluid.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]];
|
||||
if (fluids !== "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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user