From e4c9a2f7f4a77a82c607671ee3292d4aa6b45ae4 Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 27 Sep 2026 01:08:50 -0300 Subject: [PATCH] Add cooking pot from farmer's delight ! --- MODS.md | 26 +- common/block_models.ts | 6 +- common/mod_api/server.ts | 5 + common/mod_data.ts | 26 +- common/mod_loader.ts | 10 + mods/bworld/blocks/furnace.json | 7 + mods/bworld/items/bowl.json | 7 + mods/bworld/recipes/crafting_bowl.json | 17 + mods/bworld/scripts/server.ts | 6 + mods/bworld/textures/bowl.png | Bin 0 -> 178 bytes mods/farmersdelight/blocks/cooking_pot.json | 24 ++ mods/farmersdelight/blocks/stove.json | 38 +++ mods/farmersdelight/items/cabbage_rolls.json | 11 + mods/farmersdelight/items/cooked_rice.json | 13 + mods/farmersdelight/items/cooking_pot.json | 9 + mods/farmersdelight/items/tomato_sauce.json | 12 + mods/farmersdelight/manifest.json | 7 +- mods/farmersdelight/models/cooking_pot.json | 134 ++++++++ .../recipes/cooking_cabbage_rolls.json | 12 + .../recipes/cooking_cooked_rice.json | 10 + .../recipes/cooking_tomato_sauce.json | 10 + .../recipes/crafting_cooking_pot.json | 9 + .../recipes/crafting_stove.json | 9 + mods/farmersdelight/scripts/server.ts | 314 ++++++++++++++++++ .../farmersdelight/textures/cabbage_rolls.png | Bin 0 -> 418 bytes mods/farmersdelight/textures/cooked_rice.png | Bin 0 -> 361 bytes mods/farmersdelight/textures/cooking_pot.png | Bin 0 -> 427 bytes .../textures/cooking_pot_bottom.png | Bin 0 -> 223 bytes .../textures/cooking_pot_parts.png | Bin 0 -> 276 bytes .../textures/cooking_pot_side.png | Bin 0 -> 261 bytes .../textures/cooking_pot_top.png | Bin 0 -> 244 bytes mods/farmersdelight/textures/stove_bottom.png | Bin 0 -> 678 bytes mods/farmersdelight/textures/stove_front.png | Bin 0 -> 540 bytes .../textures/stove_front_on.png | Bin 0 -> 585 bytes mods/farmersdelight/textures/stove_side.png | Bin 0 -> 489 bytes mods/farmersdelight/textures/stove_top.png | Bin 0 -> 453 bytes mods/farmersdelight/textures/stove_top_on.png | Bin 0 -> 555 bytes mods/farmersdelight/textures/tomato_sauce.png | Bin 0 -> 356 bytes server/game/game_server.ts | 3 + server/game/mod_runtime.ts | 6 + tests/commands_test.ts | 1 + tests/cooking_test.ts | 184 ++++++++++ tests/mod_loading_test.ts | 7 +- 43 files changed, 913 insertions(+), 10 deletions(-) create mode 100644 mods/bworld/items/bowl.json create mode 100644 mods/bworld/recipes/crafting_bowl.json create mode 100644 mods/bworld/textures/bowl.png create mode 100644 mods/farmersdelight/blocks/cooking_pot.json create mode 100644 mods/farmersdelight/blocks/stove.json create mode 100644 mods/farmersdelight/items/cabbage_rolls.json create mode 100644 mods/farmersdelight/items/cooked_rice.json create mode 100644 mods/farmersdelight/items/cooking_pot.json create mode 100644 mods/farmersdelight/items/tomato_sauce.json create mode 100644 mods/farmersdelight/models/cooking_pot.json create mode 100644 mods/farmersdelight/recipes/cooking_cabbage_rolls.json create mode 100644 mods/farmersdelight/recipes/cooking_cooked_rice.json create mode 100644 mods/farmersdelight/recipes/cooking_tomato_sauce.json create mode 100644 mods/farmersdelight/recipes/crafting_cooking_pot.json create mode 100644 mods/farmersdelight/recipes/crafting_stove.json create mode 100644 mods/farmersdelight/scripts/server.ts create mode 100644 mods/farmersdelight/textures/cabbage_rolls.png create mode 100644 mods/farmersdelight/textures/cooked_rice.png create mode 100644 mods/farmersdelight/textures/cooking_pot.png create mode 100644 mods/farmersdelight/textures/cooking_pot_bottom.png create mode 100644 mods/farmersdelight/textures/cooking_pot_parts.png create mode 100644 mods/farmersdelight/textures/cooking_pot_side.png create mode 100644 mods/farmersdelight/textures/cooking_pot_top.png create mode 100644 mods/farmersdelight/textures/stove_bottom.png create mode 100644 mods/farmersdelight/textures/stove_front.png create mode 100644 mods/farmersdelight/textures/stove_front_on.png create mode 100644 mods/farmersdelight/textures/stove_side.png create mode 100644 mods/farmersdelight/textures/stove_top.png create mode 100644 mods/farmersdelight/textures/stove_top_on.png create mode 100644 mods/farmersdelight/textures/tomato_sauce.png create mode 100644 tests/cooking_test.ts diff --git a/MODS.md b/MODS.md index e1546ac..565df6b 100644 --- a/MODS.md +++ b/MODS.md @@ -334,6 +334,7 @@ texture per face. `models/slab.json`: | `elements[].faces` | `top`, `bottom`, `north`, `south`, `west` and `east`. Faces are only drawn from the front, so a flat plane needs one face each way. | | `faces.*.texture` | A variable (`"#side"`, filled in by the block's `textures`) or a texture id. | | `faces.*.uv` | `[u1, v1, u2, v2]`, the part of the texture in pixels. Defaults to the part the face covers. | +| `faces.*.rotation` | Turns the texture on the face clockwise by 0, 90, 180 or 270 degrees. | | `faces.*.cullface` | Hidden when the neighbor on that side is a solid block. Only for faces on the block's edge. | Faces flat against the block's edge get smooth lighting and ambient occlusion like a full block's. Anything inside the @@ -478,8 +479,29 @@ A shaped recipe, for the crafting grid in the player's inventory screen: ``` Two furnace recipes with the same `input`, two smithing recipes with the same tool, material and addition, or two -shaped recipes with the same pattern and key, are a load error. Mods can add recipe types of their own for their -machines, see [Common scripts](#common-scripts). +shaped recipes with the same pattern and key, are a load error. + +Mods can use recipe types of their own for their machines: any `type` with a namespace, like Farmer's Delight's +`farmersdelight:cooking` for its cooking pot. The engine only stores them, the mod's server script reads them with +`ctx.recipes.list("farmersdelight:cooking")` and checks the rest of the fields itself (throwing in `setup` makes a bad +recipe a load error). Other mods can add recipes of that type too. `recipes/cooking_cabbage_rolls.json`: + +```json +{ + "format_version": 1, + "recipe": { + "type": "farmersdelight:cooking", + "ingredients": ["farmersdelight:cabbage", ["bworld:carrot", "bworld:potato", "farmersdelight:onion"]], + "result": { "id": "farmersdelight:cabbage_rolls", "count": 1 }, + "cook_time": 100 + } +} +``` + +The cooking pot takes up to 6 `ingredients` in any slots, each an item id or a list of ids any of which will do. The +optional `container` (like `"bworld:bowl"`) is what the meal is served in, and `cook_time` is in ticks, 200 when not +set. It cooks while the block under it is hot: a lit stove (placed lit, relit with coal, put out with a shovel), or a +burning furnace, whose `lit` state is 1 while it has fuel. ## Overrides diff --git a/common/block_models.ts b/common/block_models.ts index 78f85f7..ad79262 100644 --- a/common/block_models.ts +++ b/common/block_models.ts @@ -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]); }); diff --git a/common/mod_api/server.ts b/common/mod_api/server.ts index 185597c..afacefb 100644 --- a/common/mod_api/server.ts +++ b/common/mod_api/server.ts @@ -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 diff --git a/common/mod_data.ts b/common/mod_data.ts index 11c8169..e5dfc2f 100644 --- a/common/mod_data.ts +++ b/common/mod_data.ts @@ -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; } diff --git a/common/mod_loader.ts b/common/mod_loader.ts index 8a51478..2d43362 100644 --- a/common/mod_loader.ts +++ b/common/mod_loader.ts @@ -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(); fuel = new Map(); smithing: Extract[] = []; + // recipes of mods' own types, by type + by_type = new Map(); 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)); diff --git a/mods/bworld/blocks/furnace.json b/mods/bworld/blocks/furnace.json index 08b56c7..35ecb77 100644 --- a/mods/bworld/blocks/furnace.json +++ b/mods/bworld/blocks/furnace.json @@ -13,6 +13,13 @@ }, "drops": "bworld:furnace", "interactive": true, + "states": [ + { + "name": "lit", + "bits": 1, + "default": 0 + } + ], "components": { "bworld:furnace": {} } diff --git a/mods/bworld/items/bowl.json b/mods/bworld/items/bowl.json new file mode 100644 index 0000000..8016789 --- /dev/null +++ b/mods/bworld/items/bowl.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:bowl", + "texture": "bworld:bowl" + } +} diff --git a/mods/bworld/recipes/crafting_bowl.json b/mods/bworld/recipes/crafting_bowl.json new file mode 100644 index 0000000..9448b95 --- /dev/null +++ b/mods/bworld/recipes/crafting_bowl.json @@ -0,0 +1,17 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "P P", + " P " + ], + "key": { + "P": "bworld:planks" + }, + "result": { + "id": "bworld:bowl", + "count": 4 + } + } +} diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index cf25100..f7e9ae7 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -191,6 +191,12 @@ function register_furnace(ctx: ServerContext) { } } + // burning, so it heats what's on top, like farmer's delight's cooking pot + const lit = data.fuel > 0 ? 1 : 0; + if (ctx.world.get_state(block.x, block.y, block.z, "lit") !== lit) { + ctx.world.set_state(block.x, block.y, block.z, "lit", lit); + } + for (const screen of viewers.get(key(block)) ?? []) show(screen, data); }, }); diff --git a/mods/bworld/textures/bowl.png b/mods/bworld/textures/bowl.png new file mode 100644 index 0000000000000000000000000000000000000000..52cde8db2da048711db95c14ffba7364f9e000e5 GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`m7Xq+Ar-fh6C_x#u!k0|`|ns0 zm&zn__=kej`eQ8ev;TJmDJ85~t;Bomn_E_aREuMlgM_oOkMb_Y7i|YJM4W$pYWgRf z%;6W_z{9{P@X7wnYz5~(Z+HUsG8&7jFmC3&$$CQX;Dw$X4iBN}iUx*Fft literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/blocks/cooking_pot.json b/mods/farmersdelight/blocks/cooking_pot.json new file mode 100644 index 0000000..fa37f89 --- /dev/null +++ b/mods/farmersdelight/blocks/cooking_pot.json @@ -0,0 +1,24 @@ +{ + "format_version": 1, + "block": { + "id": "farmersdelight:cooking_pot", + "model": "farmersdelight:cooking_pot", + "textures": { + "side": "farmersdelight:cooking_pot_side", + "top": "farmersdelight:cooking_pot_top", + "bottom": "farmersdelight:cooking_pot_bottom", + "parts": "farmersdelight:cooking_pot_parts" + }, + "render_layer": "cutout", + "mining": { + "toughness": 2, + "tool": "pickaxe" + }, + "drops": "farmersdelight:cooking_pot", + "item": false, + "interactive": true, + "components": { + "farmersdelight:cooking_pot": {} + } + } +} diff --git a/mods/farmersdelight/blocks/stove.json b/mods/farmersdelight/blocks/stove.json new file mode 100644 index 0000000..39e6c62 --- /dev/null +++ b/mods/farmersdelight/blocks/stove.json @@ -0,0 +1,38 @@ +{ + "format_version": 1, + "block": { + "id": "farmersdelight:stove", + "textures": { + "top": "farmersdelight:stove_top", + "bottom": "farmersdelight:stove_bottom", + "front": "farmersdelight:stove_front", + "side": "farmersdelight:stove_side" + }, + "variants": { + "lit=1": { + "textures": { + "top": "farmersdelight:stove_top_on", + "bottom": "farmersdelight:stove_bottom", + "front": "farmersdelight:stove_front_on", + "side": "farmersdelight:stove_side" + } + } + }, + "mining": { + "toughness": 2, + "tool": "pickaxe", + "requires_tool": true + }, + "drops": "farmersdelight:stove", + "states": [ + { + "name": "lit", + "bits": 1, + "default": 1 + } + ], + "components": { + "farmersdelight:stove": {} + } + } +} diff --git a/mods/farmersdelight/items/cabbage_rolls.json b/mods/farmersdelight/items/cabbage_rolls.json new file mode 100644 index 0000000..c6b92ec --- /dev/null +++ b/mods/farmersdelight/items/cabbage_rolls.json @@ -0,0 +1,11 @@ +{ + "format_version": 1, + "item": { + "id": "farmersdelight:cabbage_rolls", + "texture": "farmersdelight:cabbage_rolls", + "food": { + "nutrition": 5, + "saturation_modifier": 0.5 + } + } +} diff --git a/mods/farmersdelight/items/cooked_rice.json b/mods/farmersdelight/items/cooked_rice.json new file mode 100644 index 0000000..54ff563 --- /dev/null +++ b/mods/farmersdelight/items/cooked_rice.json @@ -0,0 +1,13 @@ +{ + "format_version": 1, + "item": { + "id": "farmersdelight:cooked_rice", + "texture": "farmersdelight:cooked_rice", + "max_stack": 16, + "food": { + "nutrition": 6, + "saturation_modifier": 0.4, + "returns": "bworld:bowl" + } + } +} diff --git a/mods/farmersdelight/items/cooking_pot.json b/mods/farmersdelight/items/cooking_pot.json new file mode 100644 index 0000000..0089185 --- /dev/null +++ b/mods/farmersdelight/items/cooking_pot.json @@ -0,0 +1,9 @@ +{ + "format_version": 1, + "item": { + "id": "farmersdelight:cooking_pot", + "texture": "farmersdelight:cooking_pot", + "places": "farmersdelight:cooking_pot", + "max_stack": 1 + } +} diff --git a/mods/farmersdelight/items/tomato_sauce.json b/mods/farmersdelight/items/tomato_sauce.json new file mode 100644 index 0000000..5b155e5 --- /dev/null +++ b/mods/farmersdelight/items/tomato_sauce.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "item": { + "id": "farmersdelight:tomato_sauce", + "texture": "farmersdelight:tomato_sauce", + "food": { + "nutrition": 4, + "saturation_modifier": 0.4, + "returns": "bworld:bowl" + } + } +} diff --git a/mods/farmersdelight/manifest.json b/mods/farmersdelight/manifest.json index a422e18..8e69009 100644 --- a/mods/farmersdelight/manifest.json +++ b/mods/farmersdelight/manifest.json @@ -2,7 +2,7 @@ "format_version": 1, "id": "farmersdelight", "name": "Farmer's Delight", - "description": "A port of vectorwing's Farmer's Delight: its crops for now, cooking to come.", + "description": "A port of vectorwing's Farmer's Delight: its crops and the cooking pot.", "version": "0.1.0", "authors": [ "vectorwing (original)", @@ -15,5 +15,8 @@ "version": "*" } ], - "credits": "CREDITS.md" + "credits": "CREDITS.md", + "scripts": { + "server": "scripts/server.ts" + } } diff --git a/mods/farmersdelight/models/cooking_pot.json b/mods/farmersdelight/models/cooking_pot.json new file mode 100644 index 0000000..ce0b6f0 --- /dev/null +++ b/mods/farmersdelight/models/cooking_pot.json @@ -0,0 +1,134 @@ +{ + "format_version": 1, + "model": { + "id": "farmersdelight:cooking_pot", + "textures": { + "side": "farmersdelight:cooking_pot_side", + "top": "farmersdelight:cooking_pot_top", + "bottom": "farmersdelight:cooking_pot_bottom", + "parts": "farmersdelight:cooking_pot_parts" + }, + "elements": [ + { + "from": [2, 0, 2], + "to": [14, 10, 14], + "faces": { + "north": { + "texture": "#side", + "uv": [2, 6, 14, 16] + }, + "east": { + "texture": "#side", + "uv": [2, 6, 14, 16] + }, + "south": { + "texture": "#side", + "uv": [2, 6, 14, 16] + }, + "west": { + "texture": "#side", + "uv": [2, 6, 14, 16] + }, + "top": { + "texture": "#top", + "uv": [2, 2, 14, 14] + }, + "bottom": { + "texture": "#bottom", + "uv": [2, 2, 14, 14], + "cullface": "bottom" + } + } + }, + { + "from": [7, 3, 7], + "to": [9, 15, 9], + "rotation": { + "angle": -22.5, + "axis": "z", + "origin": [8, 3, 8] + }, + "faces": { + "north": { + "texture": "#parts", + "uv": [2, 2, 0, 14] + }, + "east": { + "texture": "#parts", + "uv": [0, 2, 2, 14] + }, + "south": { + "texture": "#parts", + "uv": [2, 2, 0, 14] + }, + "west": { + "texture": "#parts", + "uv": [0, 2, 2, 14] + }, + "top": { + "texture": "#parts", + "uv": [0, 0, 2, 2] + } + } + }, + { + "from": [14, 7, 5], + "to": [16, 9, 11], + "faces": { + "north": { + "texture": "#parts", + "uv": [10, 0, 12, 2] + }, + "east": { + "texture": "#parts", + "uv": [4, 2, 10, 4], + "cullface": "east" + }, + "south": { + "texture": "#parts", + "uv": [2, 0, 4, 2] + }, + "top": { + "texture": "#parts", + "uv": [4, 0, 10, 2], + "rotation": 90 + }, + "bottom": { + "texture": "#parts", + "uv": [4, 2, 10, 4], + "rotation": 90 + } + } + }, + { + "from": [0, 7, 5], + "to": [2, 9, 11], + "faces": { + "north": { + "texture": "#parts", + "uv": [2, 0, 4, 2] + }, + "south": { + "texture": "#parts", + "uv": [10, 0, 12, 2] + }, + "west": { + "texture": "#parts", + "uv": [4, 2, 10, 4], + "cullface": "west" + }, + "top": { + "texture": "#parts", + "uv": [4, 0, 10, 2], + "rotation": 270 + }, + "bottom": { + "texture": "#parts", + "uv": [4, 2, 10, 4], + "rotation": 270 + } + } + } + ] + } +} diff --git a/mods/farmersdelight/recipes/cooking_cabbage_rolls.json b/mods/farmersdelight/recipes/cooking_cabbage_rolls.json new file mode 100644 index 0000000..6bffa0f --- /dev/null +++ b/mods/farmersdelight/recipes/cooking_cabbage_rolls.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "recipe": { + "type": "farmersdelight:cooking", + "ingredients": [ + "farmersdelight:cabbage", + ["bworld:carrot", "bworld:potato", "farmersdelight:onion", "farmersdelight:tomato"] + ], + "result": { "id": "farmersdelight:cabbage_rolls", "count": 1 }, + "cook_time": 100 + } +} diff --git a/mods/farmersdelight/recipes/cooking_cooked_rice.json b/mods/farmersdelight/recipes/cooking_cooked_rice.json new file mode 100644 index 0000000..75e209b --- /dev/null +++ b/mods/farmersdelight/recipes/cooking_cooked_rice.json @@ -0,0 +1,10 @@ +{ + "format_version": 1, + "recipe": { + "type": "farmersdelight:cooking", + "ingredients": ["farmersdelight:rice"], + "result": { "id": "farmersdelight:cooked_rice", "count": 1 }, + "container": "bworld:bowl", + "cook_time": 100 + } +} diff --git a/mods/farmersdelight/recipes/cooking_tomato_sauce.json b/mods/farmersdelight/recipes/cooking_tomato_sauce.json new file mode 100644 index 0000000..c7561f4 --- /dev/null +++ b/mods/farmersdelight/recipes/cooking_tomato_sauce.json @@ -0,0 +1,10 @@ +{ + "format_version": 1, + "recipe": { + "type": "farmersdelight:cooking", + "ingredients": ["farmersdelight:tomato", "farmersdelight:tomato"], + "result": { "id": "farmersdelight:tomato_sauce", "count": 1 }, + "container": "bworld:bowl", + "cook_time": 100 + } +} diff --git a/mods/farmersdelight/recipes/crafting_cooking_pot.json b/mods/farmersdelight/recipes/crafting_cooking_pot.json new file mode 100644 index 0000000..b930c34 --- /dev/null +++ b/mods/farmersdelight/recipes/crafting_cooking_pot.json @@ -0,0 +1,9 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": ["iSi", "i i", "iii"], + "key": { "i": "bworld:iron_ingot", "S": "bworld:stick" }, + "result": { "id": "farmersdelight:cooking_pot", "count": 1 } + } +} diff --git a/mods/farmersdelight/recipes/crafting_stove.json b/mods/farmersdelight/recipes/crafting_stove.json new file mode 100644 index 0000000..13637b5 --- /dev/null +++ b/mods/farmersdelight/recipes/crafting_stove.json @@ -0,0 +1,9 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": ["iii", "B B", "BCB"], + "key": { "i": "bworld:iron_ingot", "B": "bworld:stone", "C": "bworld:coal" }, + "result": { "id": "farmersdelight:stove", "count": 1 } + } +} diff --git a/mods/farmersdelight/scripts/server.ts b/mods/farmersdelight/scripts/server.ts new file mode 100644 index 0000000..ed27e59 --- /dev/null +++ b/mods/farmersdelight/scripts/server.ts @@ -0,0 +1,314 @@ +// farmer's delight's kitchen. the stove is a heat source, like its StoveBlock. the cooking pot, like its +// CookingPotBlockEntity, cooks its recipes while something hot is under it, keeps the meal, and serves it into the +// container the meal needs (a bowl), or straight out when it needs none +import type { BlockRef, Container, ScreenHandle, ServerContext } from "bworld/server"; + +export function setup(ctx: ServerContext) { + register_stove(ctx); + register_cooking_pot(ctx); +} + +// stove + +// what lights an unlit stove, used up. the java mod's are flint and steel and fire charges, which bworld doesn't have +const STOVE_FUEL = "bworld:coal"; +// what puts it out: any shovel, like the java mod (a water bucket too, once there are buckets) +const STOVE_EXTINGUISHER_TOOL = "shovel"; +// standing on a lit stove hurts, like a magma block: 1 health every 10 ticks +const STOVE_BURN_DAMAGE = 1; +const STOVE_BURN_TICKS = 10; + +function register_stove(ctx: ServerContext) { + const lit = (block: BlockRef) => ctx.world.get_state(block.x, block.y, block.z, "lit") === 1; + const set_lit = (block: BlockRef, value: boolean) => + ctx.world.set_state(block.x, block.y, block.z, "lit", value ? 1 : 0); + + ctx.components.register_block("farmersdelight:stove", { + // placed lit, like the java mod. block data so it ticks, to burn whoever stands on it + on_create(block) { + block.data ??= {}; + }, + on_interact(block, _params, player) { + const held = player.inventory.get(player.selected_slot); + if (!held) return false; + if (lit(block)) { + if (ctx.items.tool(held.id) !== STOVE_EXTINGUISHER_TOOL) return false; + set_lit(block, false); + return true; + } + if (held.id !== STOVE_FUEL) return false; + held.count -= 1; + set_lit(block, true); + return true; + }, + on_tick(block) { + if (ctx.system.current_tick % STOVE_BURN_TICKS !== 0 || !lit(block)) return; + for (const player of ctx.players.all()) { + const { x, y, z } = player.position; + if (Math.floor(x) === block.x && Math.floor(z) === block.z && Math.abs(y - (block.y + 1)) < 0.01) { + player.damage(STOVE_BURN_DAMAGE, "hot_floor"); + } + } + }, + }); +} + +// cooking pot + +// slots 0-5 are the ingredients, 6 the meal waiting to be served, 7 containers for it, 8 the served meal +const INGREDIENT_SLOTS = 6; +const MEAL_SLOT = 6; +const CONTAINER_SLOT = 7; +const OUTPUT_SLOT = 8; +const POT_SIZE = 9; +// ticks, for recipes that don't say +const DEFAULT_COOK_TIME = 200; + +// what's under the pot that heats it, and the state that has to be 1 for it to, like minecraft's heat_sources tag +const HEAT_SOURCES: Record = { + "bworld:furnace": "lit", + "farmersdelight:stove": "lit", +}; + +// a farmersdelight:cooking recipe: the ingredients in any slots, each an item id or a list of ids any of which will do +interface CookingRecipe { + ingredients: (string | string[])[]; + result: { id: string; count: number }; + // what the meal is served in, like a bowl. without it the meal comes out as soon as it's cooked + container?: string; + cook_time: number; +} + +interface PotData { + container: string; + // ticks, counting up to cook_time_total + cook_time: number; + cook_time_total: number; + // what the meal in the meal slot is served in, "" for nothing + meal_container: string; +} + +const POT_BARS = [ + { + x: 2.2, + y: 2, + value: "heat", + max: "heat_max", + direction: "up" as const, + empty_texture: "bworld:fire_empty", + full_texture: "bworld:fire_full", + }, + { + x: 4.6, + y: 0.5, + value: "progress", + max: "progress_max", + direction: "right" as const, + empty_texture: "bworld:arrow_empty", + full_texture: "bworld:arrow_full", + }, +]; + +// checked when the server starts, so a broken recipe is a load error naming it +function load_recipes(ctx: ServerContext): CookingRecipe[] { + return ctx.recipes.list("farmersdelight:cooking").map((json, i) => { + const where = `farmersdelight:cooking recipe ${i + 1} (${json.result?.id ?? "no result"})`; + const item = (id: unknown) => { + if (typeof id !== "string" || !ctx.items.exists(id)) throw new Error(`${where}: there's no item ${id}`); + return id; + }; + const ingredients = json.ingredients; + if (!Array.isArray(ingredients) || ingredients.length < 1 || ingredients.length > INGREDIENT_SLOTS) { + throw new Error(`${where}: ingredients must be 1 to ${INGREDIENT_SLOTS} items`); + } + for (const ingredient of ingredients) { + if (Array.isArray(ingredient)) { + if (ingredient.length === 0) throw new Error(`${where}: an ingredient's list of items is empty`); + ingredient.forEach(item); + } else { + item(ingredient); + } + } + item(json.result?.id); + if (!Number.isInteger(json.result.count) || json.result.count < 1) { + throw new Error(`${where}: result.count must be a positive whole number`); + } + if (json.container !== undefined) item(json.container); + const cook_time = json.cook_time ?? DEFAULT_COOK_TIME; + if (!Number.isInteger(cook_time) || cook_time < 1) { + throw new Error(`${where}: cook_time must be positive ticks`); + } + return { ingredients, result: json.result, container: json.container, cook_time }; + }); +} + +// the recipe whose ingredients are exactly what's in the ingredient slots, one item from each, in any order +function find_recipe(recipes: CookingRecipe[], container: Container): CookingRecipe | undefined { + const items: string[] = []; + for (let slot = 0; slot < INGREDIENT_SLOTS; slot++) { + const item = container.get(slot); + if (item) items.push(item.id); + } + if (items.length === 0) return undefined; + return recipes.find((recipe) => recipe.ingredients.length === items.length && matches(recipe.ingredients, items)); +} + +// pairs every ingredient with a different item, trying each way round, like a shapeless recipe +function matches(ingredients: (string | string[])[], items: string[], used = new Set()): boolean { + if (ingredients.length === 0) return true; + const [first, ...rest] = ingredients; + const fits = (id: string) => Array.isArray(first) ? first.includes(id) : first === id; + for (let i = 0; i < items.length; i++) { + if (used.has(i) || !fits(items[i])) continue; + used.add(i); + if (matches(rest, items, used)) return true; + used.delete(i); + } + return false; +} + +function register_cooking_pot(ctx: ServerContext) { + const recipes = load_recipes(ctx); + // who's looking at each pot, by position, to keep their bars moving + const viewers = new Map>(); + const key = (block: BlockRef) => `${block.x},${block.y},${block.z}`; + + const pot_data = (block: BlockRef): PotData => { + const existing = block.data?.container && ctx.containers.get(block.data.container); + const container = existing || ctx.containers.create(POT_SIZE); + block.data = { cook_time: 0, cook_time_total: 0, meal_container: "", ...block.data, container: container.id }; + return block.data; + }; + + const is_heated = (block: BlockRef) => { + const below = ctx.world.get_block(block.x, block.y - 1, block.z); + if (!below || !(below in HEAT_SOURCES)) return false; + const state = HEAT_SOURCES[below]; + return state === undefined || ctx.world.get_state(block.x, block.y - 1, block.z, state) === 1; + }; + + const show = (screen: ScreenHandle, data: PotData, heated: boolean) => { + screen.set_property("progress", data.cook_time); + screen.set_property("progress_max", data.cook_time_total); + screen.set_property("heat", heated ? 1 : 0); + screen.set_property("heat_max", 1); + }; + + // there's room in the meal slot for what it makes + const can_cook = (container: Container, recipe: CookingRecipe) => { + const meal = container.get(MEAL_SLOT); + if (!meal) return true; + return meal.id === recipe.result.id && meal.count + recipe.result.count <= ctx.items.max_stack(meal.id); + }; + + const cook = (data: PotData, container: Container, recipe: CookingRecipe) => { + const meal = container.get(MEAL_SLOT); + if (meal) { + meal.count += recipe.result.count; + } else { + container.set(MEAL_SLOT, { ...recipe.result }); + } + data.meal_container = recipe.container ?? ""; + for (let slot = 0; slot < INGREDIENT_SLOTS; slot++) { + const item = container.get(slot); + if (item) item.count -= 1; + } + }; + + // the meal goes to the output, into its containers when it needs them, as much as fits + const serve = (data: PotData, container: Container) => { + const meal = container.get(MEAL_SLOT); + if (!meal) { + data.meal_container = ""; + return; + } + const output = container.get(OUTPUT_SLOT); + if (output && output.id !== meal.id) return; + const room = ctx.items.max_stack(meal.id) - (output?.count ?? 0); + let count = Math.min(meal.count, room); + const bowls = container.get(CONTAINER_SLOT); + if (data.meal_container) { + count = bowls?.id === data.meal_container ? Math.min(count, bowls.count) : 0; + } + if (count <= 0) return; + if (data.meal_container) bowls!.count -= count; + if (output) { + output.count += count; + } else { + container.set(OUTPUT_SLOT, { id: meal.id, count }); + } + meal.count -= count; + }; + + ctx.components.register_block("farmersdelight:cooking_pot", { + on_create(block) { + pot_data(block); + }, + on_interact(block, _params, player) { + const data = pot_data(block); + const container = ctx.containers.get(data.container)!; + + // holding what the meal is served in serves one straight into the hand, like the java mod + const meal = container.get(MEAL_SLOT); + const held = player.inventory.get(player.selected_slot); + if (meal && data.meal_container && held?.id === data.meal_container) { + held.count -= 1; + meal.count -= 1; + player.give_item(meal.id, 1); + return true; + } + + const screen = ctx.ui.open_container(player, { + container, + layout: [ + ...Array.from( + { length: INGREDIENT_SLOTS }, + (_, slot) => ({ slot, x: 1.2 + slot % 3, y: Math.floor(slot / 3) }), + ), + // the meal stays in the pot until it's served + { slot: MEAL_SLOT, x: 6.4, y: 0.5, output_only: true, on_take: () => false }, + { slot: CONTAINER_SLOT, x: 4.6, y: 2 }, + { slot: OUTPUT_SLOT, x: 6.4, y: 2, output_only: true }, + ], + rows: 3, + bars: POT_BARS, + }); + show(screen, data, is_heated(block)); + const screens = viewers.get(key(block)) ?? new Set(); + viewers.set(key(block), screens); + screens.add(screen); + screen.on_close(() => screens.delete(screen)); + return true; + }, + on_break(block) { + const container = block.data?.container && ctx.containers.get(block.data.container); + if (!container) return; + for (let slot = 0; slot < container.size; slot++) { + const item = container.get(slot); + if (item) ctx.world.drop_item(block.x, block.y, block.z, item); + } + ctx.containers.delete(container.id); + }, + on_tick(block) { + const data = pot_data(block); + const container = ctx.containers.get(data.container)!; + const heated = is_heated(block); + const recipe = heated ? find_recipe(recipes, container) : undefined; + + if (recipe && can_cook(container, recipe)) { + data.cook_time_total = recipe.cook_time; + data.cook_time += 1; + if (data.cook_time >= recipe.cook_time) { + data.cook_time = 0; + cook(data, container, recipe); + } + } else { + // cools off, losing progress slowly + data.cook_time = Math.max(0, data.cook_time - 2); + } + serve(data, container); + + for (const screen of viewers.get(key(block)) ?? []) show(screen, data, heated); + }, + }); +} diff --git a/mods/farmersdelight/textures/cabbage_rolls.png b/mods/farmersdelight/textures/cabbage_rolls.png new file mode 100644 index 0000000000000000000000000000000000000000..441c19e1533217a7879514e829e09871d5976bd2 GIT binary patch literal 418 zcmV;T0bTxyP)Px$TuDShR5*>zkUvWTVI0Rlml6aOT@n(PlM*xtN>h}9I0YRIE-t+QU32OMI0bFK zffmQ&8C(*>l&0X&K@e+EhYC4~LO76Xu)FU3Lt}lXXZU?S&-eF(zmD|VfO@fST5pl9 zP0i00SYUX2iO5a_t*Oyy4W}ei0w<`d2|DdQS2qvnJrA-nvga(3cM?23*#jUD@*zZt zO4&eGKvqU}o9~z+Ta&y1x%8pwe;e@fzJ}J+P}KxNlxVbu$jZ+efsl_*yN}k?(0d;2 z23_4G84qII-6D!n1Y_9wqtytY(Ha6{!GhJN`uN0WIBXA`pB&(oCt+8EeBoZo7w)C5ZgQ|2B==lrxo99ni9pCV6LtxlvDQh( zeFST-blUxyuxkZpGO3uEUe^$2l#ioDDrI9PJXhenNqtkA3;&ON0d*mqPblUPHvj+t M07*qoM6N<$f@)o{761SM literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/cooked_rice.png b/mods/farmersdelight/textures/cooked_rice.png new file mode 100644 index 0000000000000000000000000000000000000000..df688f22d11a838806856753d356ef5ded99941e GIT binary patch literal 361 zcmV-v0ha!WP)Px$BS}O-R5*>@kiSa;aTtdmO$=!`2@F$F1BD`pxPIJr;ZWnb-+cZ7LVroCQ*fJq zfRI~*AVfkS6*OE&SC>I+B-Goa_@%=dqtE#AJ`eBbh5wySyCt1=OXlsw=fS#RlFgTy zCy5jcdR@^Clg9^Nnf)ke)-@UQx{@mt(X=$VLXj}=$mYw0fk&s^l4f0#NWsD8l2nZb zVc?-@X|9J?0Mw2w0J8Zq09B(wDHESc607GdP3F00E609@R?bN})gQv?9pYbmL1B_m+~e>7HLMc}%w9GZLV?`#0D zTUn&Il2kxIfxpGEEt$xk{abNtOG=rz%s%Z`acoN_vcI1%2iJ4X#2Vfy00000NkvXX Hu0mjfGIX4D literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/cooking_pot.png b/mods/farmersdelight/textures/cooking_pot.png new file mode 100644 index 0000000000000000000000000000000000000000..20429ef00d1f221801893d61666da27e0285caf2 GIT binary patch literal 427 zcmV;c0aX5pP)Px$Wl2OqR5*>zlFv)RU>L{03v;+dt=W_$C3Z;&!D5I6)u@x#4&6KSKLz~<9Xpq# zrw)<_3$%ljr8F1Y8@6|B9o9h{E`N~Fq38DSyx-6JeZD-vzo|k_@(MZ0n^iYA+^Ab3 zW`!`rO*+MUYBmZ0IJ;~yV-?c?1IS5X4L4N-;nf|)QtJSKZtDre?4eXHG7|xr%(f@X zNi?cgP_t1yzu9=Tlm1+mlV~&*5;5FAJmTx4;S1-NHhcgv zdr%k?>9~l~i)$tX0Gr|>>Y4$IQgk|9tDQr}|W Vi^Gr1B+>u?002ovPDHLkV1k(lv)=#! literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/cooking_pot_bottom.png b/mods/farmersdelight/textures/cooking_pot_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..2facbc768809a1b9a98cad980d21c45fe1d2e4e2 GIT binary patch literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`%RF5iLo9mF23_PjY{0Q++QJEw z;%_C$+uf*JX_64PP5o%pbi2HL6^8eY$}sKk^E~*rs{Z)twWbUQf=)I5sIgUJ*ioa* z*x$F4=TN=A=n1KF z%M66~8b%rmN`I?cDwk1wCTmgsn+@z+!#YX?HVPVjzswnOQ&_2ThsVA|&D0%@|ApnV XQhcJ8GS2x4bTNactDnm{r-UW|{_ZD+FU(R50s;aIe4LyNCSM;hXbbT%fWXyvpBT70`qUYe8=!iQk~)Uod;n4nKLI)4af~Q z`~TwI4~EsdFM%ce{r&$tFn(a*VPgSn`10!y!-4+-3>!CYM9~O$0n7_91MKab{+lqq zM|LH{ng4@pv8HcQ a3Px#zez+vR5*?8kg*QJFbqT=2qm(SP~pe=t^FYu7AA%cv62NAV%&nn$igj&6dXF?<(SrL%0LXW&o7uIZe|BVAl!f^To+ICje?~i#on_xWMT+p!y<~(%7qd zz3#mUs3ua*s0hW3l=IuZz4y_Wgl~8NsIX(38~@l100000 LNkvXXu0mjfTAFgp literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/cooking_pot_top.png b/mods/farmersdelight/textures/cooking_pot_top.png new file mode 100644 index 0000000000000000000000000000000000000000..d911e18a8831bde546f35e9c0095b9c2391191ba GIT binary patch literal 244 zcmVOy^oLu}v{#O5xOQBHQ3PyBkht}iHk3;CtK1<#sxtEXxeoeH9rfHr4 zVhjNJCjvai(Q5tZwrwMTi|f{PSJE^g6X6C7sx~)Gv(Qm`(Bsapn^T>JG`jHE^*8?y5ozs$OlpPM$&c4D@6NYrH#{rkSEB u$wU}bZFKYQL2V4`y7E@EOndK?|A!YJl|O3*n9%J20000Px%U`a$lR5*=olV4BMU=+rGjIu!n-Rlbb!)n~nk&Fujm6>pX3W<1OqE~(`KY-uC z#48goi1C8Nffsl&FpJ`_YXR-{x^@}qHt}L@r_qx%ZF2gY_v!CB9eeR?>k_|Y<_5~i z5z|ox0N3mDXKCdP?8>{a4-g3+T(3_$lfv$FL*aB(39q2+PWP{&O1r>6C2c)w2V4Jhk za{yN2NvgFvZQG#gi@l2uZQJ1P{U?0de@(K}gwiVMOp2H)7<>No-enNkPGk-#B|k}{ z=d!$i`-)t#3_#m9xT;M6@NjbEAQI&KvOPid@Gt~e{kTW2Sf){{(6$X!O~gb-9F zvmrMn$n-WKN+ovp4jB0MZL>ynGLEY0LmobZe4#*n|I26(f*lw*eRlT_P&FMO1Q<9N z_kNHs6!?04O#aRm$xf58;9uB@%nehJl5ch|9MZN8mX_Br8Wsu85JIr&??G&3ok+dq zP;WV0w}+NY%R<$3^jwxkt%9oQ7!8ZIZD3j!Qc401KtzjA0q|iwiIg(T`hO6m>mh{T zv$lX1pCYCT6s^2L|MZ+qKNi!nLP4We!Mo_-G|e!!Td9P<18V^M1{_c{iJ|XR^Z)<= M07*qoM6N<$f^h&uC;$Ke literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/stove_front.png b/mods/farmersdelight/textures/stove_front.png new file mode 100644 index 0000000000000000000000000000000000000000..ae462608377f1be9d34e65f58041423df31f77c0 GIT binary patch literal 540 zcmV+%0^|LOP)Px$)=5M`R5*=|kx!4(P!z>~#5ZkPm{MT^b#!5(FtSjD#96o)6E`Nt#1G-;aO<~l z7 zJ_kTb1%P{XS96AGVp|sD@fax;Gbs@>DOUoY1h#Ep+XjFZ1B^#g#-k|!iB4=52`<+E zgP70NrH8i~Jof~ViZx*wI{-u~#;YIF|NJqgD2R-%l-=9Jgt8 zPH6Xr05q-@Xx_d_zSht)Wv_(kxQKk`6M4W7CFcEye1HFz*B@Fb!**{-yEo(o@buPo z0Dg74%Mkrg>bp&#)j8Q7_o`RSTI39&Ig#8QshHwFrE3gk5wH$b$b4&U)9T*biK*snotfDDy34{3C8wh)RX{{4=Ay}7 zNOOff2+!Ee%ye8t{mCUm@uJ;Kto1e;N&H ey8_d30r(3)-qR_~*;FV100008_ literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/stove_front_on.png b/mods/farmersdelight/textures/stove_front_on.png new file mode 100644 index 0000000000000000000000000000000000000000..7502046fc8ceb69a7369efb1e47ef5e519ce68ec GIT binary patch literal 585 zcmV-P0=E5$P)gZ8Q4a0(1bp^vPke-J>n*kuD4}g)+ zM3|zg=$gi8G(t+Bsg#JRlnX+iuykEP*A;+>3@{pw84bq(ggg;{g!Sk9UnOQU|G%66 zD)7V>czzH8nz9Oj=LgvJ4V>0t0uR3d*!7LMg{oCZs80M#T)?tTejKk-OlirnDGhh( zVcF(fVB%krRs<)DfWj%)k6+R9O?rNSrYwcrsTXar@_P5#)w$D83^1H7`(L{ZTn~U! zQDf^ynUP(NdMw*S%^HYY_Y*mwKar^S9#B60%!?QqVBmV}(`5^|UC7R{?%6!V{zOK; zRp8h3kbxUSlS6@l>rt(B_~4XDD`I(t(6{FY6k|3*@><>k&ZCXosRt}W6}j4dEZYP? z%^Do!o0N+0BXYz3#>=6gRMa@gKc-SMiDxDZr%P^f76F^VN8Se4*fwpRHafIhnZ*{c zIebUQsZvSnQD!23I)H)-R#st<2Q~=@mLE`>Z8}8gJ zvJ>>?g3SwdIpuk~20@Q_W@^?z)Emu&r;d|h@8}CVcb8kWTN(C_zO#0#O0HIp{sDmB XDJ<}nCeY>i00000NkvXXu0mjfZP65w literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/stove_side.png b/mods/farmersdelight/textures/stove_side.png new file mode 100644 index 0000000000000000000000000000000000000000..616c1f662f3d9287d06111ea6792ef25ed89afc8 GIT binary patch literal 489 zcmVPx$qe(Xkl4*^|w5|pc>hOIB-**6-VSseKC0%a;sOLmGsiU7i7b4H?e>V>< z_!tX}Et-Po906c#K|DKW@#D5ruQh;pc3vX9iC%TKD!XF^L~+Q!Uq_rAd)>3g9;?g{ z#bLQX*&Sm?a90^rUvUG8u>}vdz;h0ZR+(vDG5Yr9^Zw5w=^TjS5CAujQ)u>~g;-zuZS+xDc)52lX3UVqy6nfttL=DsfEV$MW8HieDSOvgTn(xmYzZ*9WT z?x13B>+adb0in;V?2af7xw-xQtS7?Qf}thG7Q7B559>|m7q)dbkcipk)gbe<@?~~; f1$6&G?FYaUEZgu)0e(=Z00000NkvXXu0mjfWYOXR literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/stove_top.png b/mods/farmersdelight/textures/stove_top.png new file mode 100644 index 0000000000000000000000000000000000000000..05e3dcaa97f715df6eb1378ef552e6382db4b296 GIT binary patch literal 453 zcmV;$0XqJPP)Px$e@R3^R5*>Dlf7#jK@i1%=bU!AITThPsqm>zWkU!iWk`|2srDasVN|MetvYdG z3EzUynms4E6vwVtiX2ED91J&KZ{N%m*4iGR3xNowH2_jo0QjdTjuCz3akBRv-gf}F zc87>M@BxS@x)3nN3j2RDrI?7qIX4s#QEax3+0x4rp!n9Hw{iP zaP5xb>-BZN*}62kQ(cekI5F?LL4%0(YWb@2rx=*YnBwyCLmwC9zcg4hbK(>JWe@(C zLd0Y1ID0b!U{n@7|L7T&MgG#X=4LYHOseYOU>41sUq7EQZ)<9ilw6CXFGmSrj6vz) vWTmRoId>r-qEK4Xg}}G(4=kENml*RKUU=kKqxH1A00000NkvXXu0mjf5t7a8 literal 0 HcmV?d00001 diff --git a/mods/farmersdelight/textures/stove_top_on.png b/mods/farmersdelight/textures/stove_top_on.png new file mode 100644 index 0000000000000000000000000000000000000000..bf1bb3e630ef45f9e936904c0620ef3da24ea826 GIT binary patch literal 555 zcmV+`0@VG9P)35EV%>q%1SaGINQ2DG_Nhc3JyfNfbr&yOOj05m6Lzwm(|B?{_5= zV^GRR1p)Q2({ep{H_XvmbCC(YCv~*eoSxU{wQtb6;vy5=1RWZU;17aqUV`m`{psYe z;^p&%T_t$`_M5X0wm0Z^Y7GDyb&qm7qfz&kf~?HLP79%eU}<2sHoN?)O2T%Nrcy4rsg&DmItarMU(PkI tg20V)k>@Do<4Z}A=Uo37VoSDfegk2C?Px$9!W$&R5*?8kikmAa2$ZY=`cneLQxok8&cpHbQ*aHf-YS>cIg3ng`S}I*bDRk zVeT4(U@!(E@>ddRu9JAshU*YpPNfHkzSHmU|2}^IAN=z>9TGYuJM#w8KJU^z%pSg6 zuK_sKn|NIx9`la8PrP|Q#?WN~5#tOeoL!lCT_2^XaBdb7$6sU-X;V(chTa5VEQSOk z2H@^uLhnr@5HSzZl+kQ0?QCFIW*Cu$CHepux|{`jLdK5jSd4Pt%>~*mg>m?b@mb@3 zK7~2lepCrWAG { + const item = EverythingRegistry.get("items", id); + if (!item) throw new Error(`unknown item ${id}`); + return item.tool_type; + }, }, recipes: { furnace_result: (input) => { @@ -482,6 +487,7 @@ export class ModRuntime { ); return recipe && { result: recipe.result, material_count: recipe.material.count }; }, + list: (type) => structuredClone(game().recipes.by_type.get(type) ?? []), }, containers: { create: (size) => { diff --git a/tests/commands_test.ts b/tests/commands_test.ts index 701731f..2813da4 100644 --- a/tests/commands_test.ts +++ b/tests/commands_test.ts @@ -135,6 +135,7 @@ Deno.test("/give suggests item ids as they're typed", async () => { assert(!all.includes("bworld:air")); assertEquals(suggest("/give farmersdelight:tom").suggestions.map((s: { text: string }) => s.text), [ "farmersdelight:tomato", + "farmersdelight:tomato_sauce", "farmersdelight:tomato_seeds", ]); diff --git a/tests/cooking_test.ts b/tests/cooking_test.ts new file mode 100644 index 0000000..72fb272 --- /dev/null +++ b/tests/cooking_test.ts @@ -0,0 +1,184 @@ +// farmer's delight's cooking pot: cooks its recipes over a lit furnace, and serves meals into bowls +import { assert, assertEquals } from "@std/assert"; +import { ItemStack } from "$/common/inventory.ts"; +import { bake_model } from "$/common/block_models.ts"; +import { validate_recipe } from "$/common/mod_data.ts"; +import { get_state_value, set_state_value } from "$/common/utils.ts"; +import { test_game } from "./helpers.ts"; + +const POT = [0, 101, 0] as const; +const FURNACE = [0, 100, 0] as const; + +async function setup() { + const t = await test_game("mods"); + t.join(1, "alice"); + for (let x = -3; x <= 3; x++) { + for (let z = -3; z <= 3; z++) t.game.set_block(x, 99, z, "bworld:stone"); + } + t.send(1, { type: "move", x: 2.5, y: 100, z: 2.5, yaw: 0, pitch: 0 }); + t.game.set_block(...FURNACE, "bworld:furnace"); + t.game.set_block(...POT, "farmersdelight:cooking_pot"); + + const container = (at: readonly [number, number, number]) => { + const id = (t.game.world.get_tile(...at)?.mod_data as { container: string }).container; + return t.game.containers.get(id)!; + }; + const pot = container(POT); + const put = (slot: number, id: string, count = 1) => pot.set_item(slot, new ItemStack(id, count)); + const slot = (slot: number) => { + const item = pot.get_item(slot); + return item ? `${item.type_id} ${item.amount}` : ""; + }; + // something to smelt and coal, so the furnace burns + const light_furnace = () => { + container(FURNACE).set_item(0, new ItemStack("bworld:log", 64)); + container(FURNACE).set_item(1, new ItemStack("bworld:coal", 64)); + }; + const ticks = (n: number) => { + for (let i = 0; i < n; i++) t.game.tick(); + }; + return { ...t, pot, put, slot, light_furnace, ticks }; +} + +Deno.test("the pot only cooks over a lit furnace, then serves the meal into bowls", async () => { + const t = await setup(); + t.put(0, "farmersdelight:tomato", 2); + t.put(3, "farmersdelight:tomato", 2); + + // cold: nothing happens + t.ticks(150); + assertEquals(t.slot(0), "farmersdelight:tomato 2"); + assertEquals(t.slot(6), ""); + + t.light_furnace(); + t.ticks(1); + assertEquals(t.game.world.get_block_id(...FURNACE), "bworld:furnace"); + t.ticks(100); + // one sauce, one tomato from each slot, waiting in the pot for a bowl + assertEquals(t.slot(6), "farmersdelight:tomato_sauce 1"); + assertEquals(t.slot(0), "farmersdelight:tomato 1"); + assertEquals(t.slot(3), "farmersdelight:tomato 1"); + assertEquals(t.slot(8), ""); + + t.ticks(100); + assertEquals(t.slot(6), "farmersdelight:tomato_sauce 2"); + assertEquals(t.slot(0), ""); + + // bowls take it out + t.put(7, "bworld:bowl", 5); + t.ticks(1); + assertEquals(t.slot(6), ""); + assertEquals(t.slot(7), "bworld:bowl 3"); + assertEquals(t.slot(8), "farmersdelight:tomato_sauce 2"); +}); + +Deno.test("ingredients go in any slots, lists take any of their items, and meals without a container come right out", async () => { + const t = await setup(); + t.light_furnace(); + t.put(5, "bworld:potato"); + t.put(1, "farmersdelight:cabbage"); + t.ticks(101); + assertEquals(t.slot(8), "farmersdelight:cabbage_rolls 1"); + assertEquals(t.slot(6), ""); + + // something extra matches nothing + t.put(0, "farmersdelight:cabbage"); + t.put(1, "farmersdelight:onion"); + t.put(2, "farmersdelight:rice"); + t.ticks(300); + assertEquals(t.slot(8), "farmersdelight:cabbage_rolls 1"); + assertEquals(t.slot(0), "farmersdelight:cabbage 1"); + + // a different meal waits until the pot's empty of the other + t.pot.set_item(0, undefined); + t.pot.set_item(1, undefined); + t.ticks(100); + assertEquals(t.slot(6), "farmersdelight:cooked_rice 1"); + t.put(0, "farmersdelight:tomato", 2); + t.put(1, "farmersdelight:tomato", 2); + t.ticks(300); + assertEquals(t.slot(6), "farmersdelight:cooked_rice 1"); + assertEquals(t.slot(0), "farmersdelight:tomato 2"); +}); + +Deno.test("holding a bowl serves the meal straight into your hand, and breaking the pot drops everything", async () => { + const t = await setup(); + t.light_furnace(); + t.put(0, "farmersdelight:rice", 3); + t.ticks(301); + assertEquals(t.slot(6), "farmersdelight:cooked_rice 3"); + + t.send(1, { type: "chat", text: "/give bworld:bowl 2" }); + const inventory = () => t.game.players()[0].inventory.to_data().filter((i) => i); + t.send(1, { type: "select_slot", slot: 0 }); + t.send(1, { type: "use_block", x: POT[0], y: POT[1], z: POT[2], face: "top" }); + assertEquals(t.slot(6), "farmersdelight:cooked_rice 2"); + assertEquals(inventory().map((i) => `${i!.id} ${i!.count}`), ["bworld:bowl 1", "farmersdelight:cooked_rice 1"]); + + t.game.destroy_block(...POT); + const dropped = t.game.item_entities().map((e) => `${e.item.type_id} ${e.item.amount}`); + assert(dropped.includes("farmersdelight:cooked_rice 2"), String(dropped)); +}); + +Deno.test("mods' own recipe types are accepted, and model faces can turn their texture", () => { + assertEquals(validate_recipe({ type: "farmersdelight:cooking", anything: 1 }), []); + assertEquals(validate_recipe({ type: "cooking" }).length, 1); + + const face = (rotation?: number) => + bake_model({ + id: "test:m", + elements: [{ + from: [0, 0, 0], + to: [16, 16, 16], + faces: { top: { texture: "test:t", uv: [0, 0, 8, 4], rotation } }, + }], + }, undefined)[0].uvs; + assertEquals(face(), [0, 4, 8, 4, 8, 0, 0, 0]); + // each corner gets the next corner's uv + assertEquals(face(90), [8, 4, 8, 0, 0, 0, 0, 4]); + assertEquals(face(180), [8, 0, 0, 0, 0, 4, 8, 4]); +}); + +Deno.test("a stove is placed lit and heats the pot, coal relights it, and standing on it burns", async () => { + const t = await setup(); + const info = () => t.game.world.get_block_info(...FURNACE)!; + const lit = () => get_state_value(t.game.world.get_block_value(...FURNACE), info(), "lit"); + t.game.set_block(...FURNACE, "farmersdelight:stove"); + assertEquals(lit(), 1); + + t.put(0, "farmersdelight:rice"); + t.ticks(101); + assertEquals(t.slot(6), "farmersdelight:cooked_rice 1"); + + // out, it doesn't cook + t.game.set_block_state( + ...FURNACE, + set_state_value(t.game.world.get_block_value(...FURNACE), info(), "lit", 0)! >>> 16, + ); + t.put(0, "farmersdelight:rice"); + t.ticks(150); + assertEquals(t.slot(6), "farmersdelight:cooked_rice 1"); + + // coal lights it again, used up + t.send(1, { type: "chat", text: "/give bworld:coal 2" }); + t.send(1, { type: "select_slot", slot: 0 }); + t.send(1, { type: "use_block", x: FURNACE[0], y: FURNACE[1], z: FURNACE[2], face: "north" }); + assertEquals(lit(), 1); + assertEquals(t.game.players()[0].inventory.get_item(0)?.amount, 1); + // already lit, coal does nothing + t.send(1, { type: "use_block", x: FURNACE[0], y: FURNACE[1], z: FURNACE[2], face: "north" }); + assertEquals(t.game.players()[0].inventory.get_item(0)?.amount, 1); + + // standing on it: 1 every 10 ticks + t.game.destroy_block(...POT); + t.send(1, { type: "move", x: 0.5, y: 101, z: 0.5, yaw: 0, pitch: 0 }); + const health = () => t.game.players()[0].vitals.health; + // (full hunger heals some of it back meanwhile, like minecraft) + const before = health(); + t.ticks(40); + assert(health() < before, `${health()} of ${before}`); + t.send(1, { type: "move", x: 2.5, y: 100, z: 2.5, yaw: 0, pitch: 0 }); + const off = health(); + t.ticks(40); + assert(health() >= off); +}); diff --git a/tests/mod_loading_test.ts b/tests/mod_loading_test.ts index 87fd08b..9492789 100644 --- a/tests/mod_loading_test.ts +++ b/tests/mod_loading_test.ts @@ -25,9 +25,10 @@ Deno.test("the base game loads from mods/bworld", async () => { const { game } = await test_game("mods"); const bworld = (entries: [string, unknown][]) => entries.filter(([id]) => id.startsWith("bworld:")).length; assertEquals(bworld(EverythingRegistry.entries("blocks")), 23); - // 17 items plus the item forms of the 18 blocks that have one - assertEquals(bworld(EverythingRegistry.entries("items")), 35); - assertEquals(game.recipes.shaped.length, 5); + // 18 items plus the item forms of the 18 blocks that have one + assertEquals(bworld(EverythingRegistry.entries("items")), 36); + // the bowl is bworld's 6th, the cooking pot and stove are farmersdelight's + assertEquals(game.recipes.shaped.length, 8); assertEquals(game.recipes.furnace.size, 6); assertEquals(game.recipes.fuel.size, 2); assertEquals(EverythingRegistry.get("blocks", "bworld:water")?.replaceable, true);