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
+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