Add cooking pot from farmer's delight !
This commit is contained in:
@@ -11,6 +11,8 @@ export interface ModelFaceJson {
|
||||
texture: string;
|
||||
// the part of the texture, [u1, v1, u2, v2] in pixels (0-16). defaults to the part the face covers
|
||||
uv?: [number, number, number, number];
|
||||
// turns the texture on the face clockwise: 0, 90, 180 or 270
|
||||
rotation?: number;
|
||||
// hidden when the neighbor on this side hides faces (a solid block)
|
||||
cullface?: ModelFace;
|
||||
}
|
||||
@@ -234,6 +236,8 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
|
||||
if (!face_json) continue;
|
||||
const index = FACE_INDEX[face];
|
||||
const uv = face_json.uv ?? default_uv(face, element.from, element.to);
|
||||
// each corner takes the uv of the corner a quarter turn along, per 90 degrees
|
||||
const uv_turns = Math.round((face_json.rotation ?? 0) / 90) % 4;
|
||||
|
||||
const positions: number[] = [];
|
||||
const uvs: number[] = [];
|
||||
@@ -242,7 +246,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
|
||||
point = rotate(point);
|
||||
for (let t = 0; t < turns; t++) point = [1 - point[2], point[1], point[0]];
|
||||
positions.push(...point);
|
||||
const [cu, cv] = CORNER_UVS[k];
|
||||
const [cu, cv] = CORNER_UVS[(k + uv_turns) % 4];
|
||||
uvs.push(cu ? uv[2] : uv[0], cv ? uv[3] : uv[1]);
|
||||
});
|
||||
|
||||
|
||||
@@ -252,6 +252,8 @@ export interface ItemApi {
|
||||
exists(id: Id): boolean;
|
||||
// how many fit in one slot
|
||||
max_stack(id: Id): number;
|
||||
// the tool type it is, like "pickaxe" or "shovel", from the item's "tool"
|
||||
tool(id: Id): string | undefined;
|
||||
}
|
||||
|
||||
export interface RecipeApi {
|
||||
@@ -261,6 +263,9 @@ export interface RecipeApi {
|
||||
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 "farmersdelight:cooking", as its json. copies, in load order
|
||||
// deno-lint-ignore no-explicit-any
|
||||
list(type: Id): any[];
|
||||
}
|
||||
|
||||
// guis
|
||||
|
||||
+24
-2
@@ -92,7 +92,20 @@ export type RecipeJson =
|
||||
material: { id: string; count: number };
|
||||
addition?: string;
|
||||
result: string;
|
||||
};
|
||||
}
|
||||
// a mod's own recipe type, like "farmersdelight:cooking" for its cooking pot. the engine only stores these, the mod's
|
||||
// server script reads them with ctx.recipes.list and checks the rest
|
||||
| ModRecipeJson;
|
||||
|
||||
export interface ModRecipeJson {
|
||||
type: `${string}:${string}`;
|
||||
[field: string]: unknown;
|
||||
}
|
||||
|
||||
// a recipe type a mod made up, as opposed to the engine's shaped, furnace, fuel and smithing
|
||||
export function is_mod_recipe(recipe: RecipeJson): recipe is ModRecipeJson {
|
||||
return recipe.type.includes(":");
|
||||
}
|
||||
|
||||
// the crafting grid's format, see server/game/crafting.ts
|
||||
export interface GridRecipe {
|
||||
@@ -417,6 +430,9 @@ export function validate_model(json: unknown): Problems {
|
||||
if (face.uv !== undefined && (!Array.isArray(face.uv) || face.uv.length !== 4)) {
|
||||
problems.push(`${where}.faces.${side}.uv must be [u1, v1, u2, v2] in pixels`);
|
||||
}
|
||||
if (face.rotation !== undefined && ![0, 90, 180, 270].includes(face.rotation as number)) {
|
||||
problems.push(`${where}.faces.${side}.rotation must be 0, 90, 180 or 270`);
|
||||
}
|
||||
if (face.cullface !== undefined && !MODEL_FACES.includes(face.cullface as ModelFace)) {
|
||||
problems.push(`${where}.faces.${side}.cullface isn't one of ${MODEL_FACES.join(", ")}`);
|
||||
}
|
||||
@@ -505,7 +521,13 @@ export function validate_recipe(json: unknown): Problems {
|
||||
if (json.addition !== undefined) problems.push(...validate_id(json.addition, "addition"));
|
||||
break;
|
||||
default:
|
||||
problems.push('type must be "shaped", "furnace", "fuel" or "smithing"');
|
||||
if (typeof json.type !== "string" || !json.type.includes(":")) {
|
||||
problems.push(
|
||||
'type must be "shaped", "furnace", "fuel", "smithing" or a mod\'s own type like "farmersdelight:cooking"',
|
||||
);
|
||||
} else {
|
||||
problems.push(...validate_id(json.type, "type"));
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import {
|
||||
BlockJson,
|
||||
grid_recipe_from_json,
|
||||
GridRecipe,
|
||||
is_mod_recipe,
|
||||
item_from_json,
|
||||
ItemJson,
|
||||
ModRecipeJson,
|
||||
OreJson,
|
||||
RecipeJson,
|
||||
} from "./mod_data.ts";
|
||||
@@ -40,6 +42,8 @@ export class RecipeBook {
|
||||
furnace = new Map<string, { output: { id: string; count: number }; cook_time: number }>();
|
||||
fuel = new Map<string, number>();
|
||||
smithing: Extract<RecipeJson, { type: "smithing" }>[] = [];
|
||||
// recipes of mods' own types, by type
|
||||
by_type = new Map<string, ModRecipeJson[]>();
|
||||
ores: OreJson[] = [];
|
||||
}
|
||||
|
||||
@@ -77,6 +81,12 @@ export function register_mod_data(mods: { id: string; data: ModData }[]): Recipe
|
||||
}
|
||||
|
||||
for (const recipe of data.recipes) {
|
||||
if (is_mod_recipe(recipe)) {
|
||||
const list = recipes.by_type.get(recipe.type) ?? [];
|
||||
recipes.by_type.set(recipe.type, list);
|
||||
list.push(recipe);
|
||||
continue;
|
||||
}
|
||||
switch (recipe.type) {
|
||||
case "shaped":
|
||||
recipes.shaped.push(grid_recipe_from_json(recipe));
|
||||
|
||||
Reference in New Issue
Block a user