Fluid data

This commit is contained in:
2026-10-25 14:24:16 -03:00
parent 17d83acfc8
commit fc27771a92
12 changed files with 387 additions and 31 deletions
+19 -1
View File
@@ -5,13 +5,21 @@
// see docs/modding/. parts not built yet throw when used, saying so
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, fluid_block, get_state_value, is_waterlogged, set_state_value } from "$/common/utils.ts";
import {
block_states,
fluid_block,
get_state_value,
is_waterlogged,
set_state_value,
shared_items_api,
} 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";
import { physics } from "$/common/physics.ts";
import { clock } from "$/common/time.ts";
import { BlockRules } from "$/common/block_rules.ts";
import { FluidRules } from "$/common/fluids.ts";
import type { SharedContext } from "$/common/mod_api/shared.ts";
import { tag_api } from "$/common/tags.ts";
import { loading_mod } from "$/common/hooks.ts";
@@ -151,6 +159,8 @@ export class ModRuntime {
(x, y, z) => this.game.world.get_block_id(x, y, z),
(x, y, z, from) => this.#neighbor_changed(x, y, z, from),
);
// the fluids' rules from shared scripts, see common/fluids.ts
fluid_rules = new FluidRules(run_guarded);
item_components = new Map<string, { mod: string; component: ItemComponent }>();
effect_components = new Map<string, { mod: string; component: EffectComponent }>();
// every command, the engine's and mods', see common/commands.ts
@@ -268,6 +278,13 @@ export class ModRuntime {
side: "server",
tags: tag_api(),
blocks,
items: shared_items_api(mod),
fluids: {
register: (id, rules) => {
if (!this.#setting_up) throw new ModLoadError(mod, "rules can only be registered during setup");
this.fluid_rules.register(mod, id, rules);
},
},
world: {
get_block: world.get_block,
get_state: world.get_state,
@@ -926,6 +943,7 @@ export class ModRuntime {
return is_solid(block);
},
},
fluids: this.fluid_rules.api(),
recipes: {
furnace_result: (input) => {
const recipe = game().recipes.furnace.get(input);