Better recipe api and port smithing to it
This commit is contained in:
@@ -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