Add cooking pot from farmer's delight !
@@ -13,6 +13,13 @@
|
||||
},
|
||||
"drops": "bworld:furnace",
|
||||
"interactive": true,
|
||||
"states": [
|
||||
{
|
||||
"name": "lit",
|
||||
"bits": 1,
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"components": {
|
||||
"bworld:furnace": {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "bworld:bowl",
|
||||
"texture": "bworld:bowl"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "shaped",
|
||||
"pattern": [
|
||||
"P P",
|
||||
" P "
|
||||
],
|
||||
"key": {
|
||||
"P": "bworld:planks"
|
||||
},
|
||||
"result": {
|
||||
"id": "bworld:bowl",
|
||||
"count": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
},
|
||||
});
|
||||
|
||||
|
After Width: | Height: | Size: 178 B |
@@ -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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "farmersdelight:cabbage_rolls",
|
||||
"texture": "farmersdelight:cabbage_rolls",
|
||||
"food": {
|
||||
"nutrition": 5,
|
||||
"saturation_modifier": 0.5
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "farmersdelight:cooking_pot",
|
||||
"texture": "farmersdelight:cooking_pot",
|
||||
"places": "farmersdelight:cooking_pot",
|
||||
"max_stack": 1
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
@@ -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<string, string | undefined> = {
|
||||
"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<number>()): 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<string, Set<ScreenHandle>>();
|
||||
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);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
After Width: | Height: | Size: 418 B |
|
After Width: | Height: | Size: 361 B |
|
After Width: | Height: | Size: 427 B |
|
After Width: | Height: | Size: 223 B |
|
After Width: | Height: | Size: 276 B |
|
After Width: | Height: | Size: 261 B |
|
After Width: | Height: | Size: 244 B |
|
After Width: | Height: | Size: 678 B |
|
After Width: | Height: | Size: 540 B |
|
After Width: | Height: | Size: 585 B |
|
After Width: | Height: | Size: 489 B |
|
After Width: | Height: | Size: 453 B |
|
After Width: | Height: | Size: 555 B |
|
After Width: | Height: | Size: 356 B |