Fluid data
This commit is contained in:
+14
-7
@@ -8,8 +8,9 @@ import { BlockRegistry, EverythingRegistry, type ItemRegistry } from "$/common/e
|
||||
import type { ClientContext, ClientMenu, InventoryOverlay, KeyMappings, MenuScreen } from "$/common/mod_api/client.ts";
|
||||
import { ModListing, ModLoadError, RecipeBook, register_mod_data } from "$/common/mod_loader.ts";
|
||||
import { type Bmod, read_bmod } from "$/common/bmod.ts";
|
||||
import { display_name, get_state_value, set_state_value } from "$/common/utils.ts";
|
||||
import { get_state_value, set_state_value, shared_items_api } from "$/common/utils.ts";
|
||||
import { BlockRules } from "$/common/block_rules.ts";
|
||||
import { FluidRules } from "$/common/fluids.ts";
|
||||
import { covers_face, EMPTY_SHAPE, FULL_SHAPE, is_solid } from "$/common/block_shapes.ts";
|
||||
import type { SharedContext, SharedWorld } from "$/common/mod_api/shared.ts";
|
||||
import { tag_api } from "$/common/tags.ts";
|
||||
@@ -90,6 +91,8 @@ const rules_world: SharedWorld = {
|
||||
|
||||
// what the mods' shared scripts registered, run to guess ahead of the server, see common/block_rules.ts
|
||||
export let block_rules = new BlockRules(run_mod, rules_world.get_block);
|
||||
// the fluids' rules from shared scripts, the same as the server's, see common/fluids.ts
|
||||
export let fluid_rules = new FluidRules(run_mod);
|
||||
// whether shared scripts are being set up, the only time they can register rules
|
||||
let rules_setup = false;
|
||||
// whether client scripts are being set up, the only time they can register visuals, since chunk workers are told
|
||||
@@ -163,6 +166,7 @@ export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
|
||||
|
||||
// every mod's shared rules first, so client scripts can count on any mod's being there
|
||||
block_rules = new BlockRules(run_mod, rules_world.get_block);
|
||||
fluid_rules = new FluidRules(run_mod);
|
||||
rules_setup = true;
|
||||
for (const [i, bmod] of bmods.entries()) {
|
||||
const code = bmod.scripts.shared;
|
||||
@@ -221,6 +225,13 @@ function shared_context(listing: ModListing): SharedContext {
|
||||
side: "client",
|
||||
tags: tag_api(),
|
||||
blocks: blocks_api(mod),
|
||||
items: shared_items_api(mod),
|
||||
fluids: {
|
||||
register(id, rules) {
|
||||
if (!rules_setup) throw new Error(`[${mod}] rules can only be registered during setup`);
|
||||
fluid_rules.register(mod, id, rules);
|
||||
},
|
||||
},
|
||||
world: rules_world,
|
||||
components: {
|
||||
register_block(id, rules) {
|
||||
@@ -329,20 +340,16 @@ function client_context(listing: ModListing): ClientContext {
|
||||
},
|
||||
},
|
||||
items: {
|
||||
...shared_items_api(mod),
|
||||
ids: () => EverythingRegistry.entries("items").map(([id]) => id),
|
||||
exists: (id) => EverythingRegistry.get("items", id) !== undefined,
|
||||
name: (id) => (known_item(id), display_name(id)),
|
||||
mod(id) {
|
||||
known_item(id);
|
||||
const namespace = id.split(":")[0];
|
||||
return mod_names.get(namespace) ?? namespace;
|
||||
},
|
||||
components: (id) => (known_item(id),
|
||||
structuredClone(
|
||||
EverythingRegistry.get<ItemRegistry>("items", id)?.components ?? {},
|
||||
)),
|
||||
},
|
||||
blocks: blocks_api(mod),
|
||||
fluids: fluid_rules.api(),
|
||||
loot: {
|
||||
table: (id) => structuredClone(EverythingRegistry.get<LootTableJson>("loot_tables", id)),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user