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
+15 -2
View File
@@ -2,10 +2,21 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// what client scripts get, see docs/modding/gui/index.md
import type { Id, ItemStack, KeyCode, ModInfo, Position, Season, TagApi } from "./shared.ts";
import type { FluidApi, Id, ItemStack, KeyCode, ModInfo, Position, Season, TagApi } from "./shared.ts";
import type { LootTableJson } from "../loot.ts";
export type { Id, ItemStack, KeyCode, ModInfo, Position, Season, TagApi, TagRegistry } from "./shared.ts";
export type {
FluidApi,
FluidVariant,
Id,
ItemStack,
KeyCode,
ModInfo,
Position,
Season,
TagApi,
TagRegistry,
} from "./shared.ts";
export interface ClientContext {
mod: ModInfo;
@@ -59,6 +70,8 @@ export interface ClientContext {
// whether it's solid like stone, like the server's ctx.blocks.solid
solid(id: Id): boolean;
};
// every fluid, named and colored by its rules, see docs/modding/resources/fluids.md
fluids: FluidApi;
// the mods' loot table files (see docs/modding/resources/loot_tables.md), to show what they give. tables server
// scripts make with ctx.loot.register_table aren't here
loot: {
+16 -2
View File
@@ -2,13 +2,25 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// what server scripts get, see docs/modding/
import type { EventSignal, Face, Id, ItemStack, ModInfo, Position, Season, TagApi } from "./shared.ts";
import type { EventSignal, Face, FluidApi, Id, ItemStack, ModInfo, Position, Season, TagApi } from "./shared.ts";
import type { ArgumentType, CommandNode } from "../commands.ts";
import type { LootTableJson } from "../loot.ts";
export type { ArgumentType, CommandContext, CommandNode, Suggestion } from "../commands.ts";
export type { EventSignal, Face, Id, ItemStack, ModInfo, Position, Season, TagApi, TagRegistry } from "./shared.ts";
export type {
EventSignal,
Face,
FluidApi,
FluidVariant,
Id,
ItemStack,
ModInfo,
Position,
Season,
TagApi,
TagRegistry,
} from "./shared.ts";
export interface ServerContext {
mod: ModInfo;
@@ -25,6 +37,8 @@ export interface ServerContext {
containers: ContainerApi;
items: ItemApi;
blocks: BlockApi;
// every fluid, named and colored by its rules, see docs/modding/resources/fluids.md
fluids: FluidApi;
recipes: RecipeApi;
tags: TagApi;
loot: LootApi;
+42
View File
@@ -16,6 +16,35 @@ export interface ItemStack {
data?: unknown;
}
// a fluid with its data, like the juice in a bottle, see docs/modding/resources/fluids.md. it has no amount: whatever
// holds fluid keeps that beside it, like a tank's { fluid, amount }
export interface FluidVariant {
readonly id: Id;
// any json value, which tells fluids of one id apart, like which fruit a juice is from
readonly data?: unknown;
}
// ctx.fluids in server and client scripts: every fluid any mod defines, the same on the server and every client
export interface FluidApi {
exists(id: Id): boolean;
// what players see, from the fluid's rules for its data, or else its json
name(fluid: FluidVariant): string;
// a color like "#c42d39", from the fluid's rules for its data, or else its json
color(fluid: FluidVariant): string;
// whether they're one fluid: the same id, and the same data whatever order its keys are in. no data is the same as
// {}, so a fluid whose data was emptied is the plain fluid again
same(a: FluidVariant, b: FluidVariant): boolean;
}
// what a fluid's data makes it, registered by a shared script, like neoforge's FluidType.getDescription and
// FluidTintSource.colorAsStack without the amount. data is the variant's, undefined for none, and isn't to be changed.
// returning undefined keeps what the fluid's json says
export interface FluidRules {
name?(data: unknown): string | undefined;
// a color like "#c42d39"
color?(data: unknown): string | undefined;
}
// the registries tags are for, see docs/modding/resources/tags.md
export type TagRegistry = "blocks" | "items" | "entities" | "biomes";
@@ -75,6 +104,19 @@ export interface SharedContext {
// whether it's solid like stone, like the server's ctx.blocks.solid
solid(id: Id): boolean;
};
// every item any mod registered, like the client's ctx.items, for rules that read one, like a juice named after the
// fruit it's from
readonly items: {
exists(id: Id): boolean;
// what players see, like "Cooked Rice"
name(id: Id): string;
// the components its json lists and their params, a copy
components(id: Id): Record<Id, unknown>;
};
readonly fluids: {
// the rules of one of the mod's fluids, which the server and every client name and color it by
register(id: Id, rules: FluidRules): void;
};
readonly components: {
// the rules of a block component, the same id the server script registers the rest of it under
// deno-lint-ignore no-explicit-any