Better recipe api and port smithing to it
This commit is contained in:
@@ -2,7 +2,18 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// what client scripts get, see docs/modding/gui/index.md
|
||||
import type { FluidApi, FluidVariant, Id, ItemStack, KeyCode, ModInfo, Position, Season, TagApi } from "./shared.ts";
|
||||
import type {
|
||||
FluidApi,
|
||||
FluidVariant,
|
||||
Id,
|
||||
ItemStack,
|
||||
KeyCode,
|
||||
ModInfo,
|
||||
Position,
|
||||
RecipeLookup,
|
||||
Season,
|
||||
TagApi,
|
||||
} from "./shared.ts";
|
||||
import type { LootTableJson } from "../loot.ts";
|
||||
|
||||
export type {
|
||||
@@ -82,11 +93,12 @@ export interface ClientContext {
|
||||
// the table's json, a copy, or undefined when no mod has a file for it
|
||||
table(id: Id): LootTableJson | undefined;
|
||||
};
|
||||
// every recipe as its json (see docs/modding/resources/recipes.md), including mods' own types, in load order. copies
|
||||
// every recipe as its json (see docs/modding/resources/recipes.md), including mods' own types, in load order. copies.
|
||||
// find and all read the recipes of types shared scripts registered
|
||||
recipes: {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
list(type?: Id): any[];
|
||||
};
|
||||
} & RecipeLookup;
|
||||
// every mod's block, item and entity tags
|
||||
tags: TagApi;
|
||||
// blocks drawn with code, like a shaft that turns, see docs/modding/blocks/visuals.md
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
ItemStack,
|
||||
ModInfo,
|
||||
Position,
|
||||
RecipeLookup,
|
||||
Season,
|
||||
TagApi,
|
||||
} from "./shared.ts";
|
||||
@@ -641,13 +642,12 @@ export interface ServerFluidApi extends FluidApi {
|
||||
interact(player: Player, handler: FluidHandler): boolean;
|
||||
}
|
||||
|
||||
export interface RecipeApi {
|
||||
// find and all read the recipes of types shared scripts registered
|
||||
export interface RecipeApi extends RecipeLookup {
|
||||
furnace_result(input: Id): { output: ItemStack; cook_time: number } | undefined;
|
||||
fuel_value(item: Id): number; // burn time in ticks, 0 if it isn't fuel
|
||||
is_fuel(item: Id): boolean;
|
||||
is_smeltable(item: Id): boolean;
|
||||
// the smithing recipe for these items, whatever the material's count. addition is the optional third item
|
||||
smithing(tool: Id, material: Id, addition?: Id): { result: Id; material_count: number } | undefined;
|
||||
// every recipe of a mod's own type, like "bworld:cooking", as its json. copies, in load order
|
||||
// deno-lint-ignore no-explicit-any
|
||||
list(type: Id): any[];
|
||||
|
||||
@@ -55,6 +55,33 @@ export interface FluidRules {
|
||||
sell_value?(data: unknown): number | undefined;
|
||||
}
|
||||
|
||||
// a recipe type of a mod's own, like neoforge's RecipeType with its serializer and Recipe.matches: R is a recipe of it
|
||||
// once parsed, and I what find is asked with, like the slots of the machine that makes it. see
|
||||
// docs/modding/resources/recipes.md
|
||||
export interface RecipeType<R, I> {
|
||||
// a recipe's json turned into R, checked, like a serializer's codec. throwing stops the mod loading, like a broken
|
||||
// file would. it runs once for each recipe of the type, in load order, on the server and every client
|
||||
// deno-lint-ignore no-explicit-any
|
||||
parse(json: any, read: RecipeReader): R;
|
||||
// whether the recipe is what input makes, for find
|
||||
matches(recipe: R, input: I): boolean;
|
||||
}
|
||||
|
||||
// reads a field of a recipe's json for RecipeType.parse, checked like the engine's own recipes' fields. throws naming
|
||||
// the field when it isn't one, or its item isn't registered
|
||||
export interface RecipeReader {
|
||||
item(json: Record<string, unknown>, field: string): Id;
|
||||
stack(json: Record<string, unknown>, field: string): { id: Id; count: number };
|
||||
}
|
||||
|
||||
// the recipes of registered types, as their parse made them, in load order. not to be changed
|
||||
export interface RecipeLookup {
|
||||
// the first one input makes, like neoforge's RecipeManager.getRecipeFor. undefined for a type nobody registered
|
||||
find<R>(type: Id, input: unknown): R | undefined;
|
||||
// every one of type, empty for a type nobody registered
|
||||
all<R>(type: Id): readonly R[];
|
||||
}
|
||||
|
||||
// the registries tags are for, see docs/modding/resources/tags.md
|
||||
export type TagRegistry = "blocks" | "items" | "entities" | "biomes";
|
||||
|
||||
@@ -142,7 +169,10 @@ export interface SharedContext {
|
||||
// shared scripts that set up before this one registered, which are the dependencies'. like the client's
|
||||
// deno-lint-ignore no-explicit-any
|
||||
list(type?: string): any[];
|
||||
};
|
||||
// a recipe type of the mod's own, in its namespace, only during setup: its recipes, from files and register,
|
||||
// are parsed by it then, and find and all read them from there on every side. see RecipeType
|
||||
register_type<R, I>(type: Id, rules: RecipeType<R, I>): void;
|
||||
} & RecipeLookup;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user