Recipe types from shared scripts and stuff
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "fuel",
|
||||
"type": "bworld:fuel",
|
||||
"item": "bworld:coal",
|
||||
"burn_time": 1000
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "fuel",
|
||||
"type": "bworld:fuel",
|
||||
"item": "#bworld:logs",
|
||||
"burn_time": 100
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:coal_ore",
|
||||
"output": {
|
||||
"id": "bworld:coal",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:cod",
|
||||
"output": {
|
||||
"id": "bworld:cooked_cod",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:copper_ore",
|
||||
"output": {
|
||||
"id": "bworld:copper_ingot",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:sand",
|
||||
"output": {
|
||||
"id": "bworld:glass",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:gold_ore",
|
||||
"output": {
|
||||
"id": "bworld:gold_ingot",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:iron_ore",
|
||||
"output": {
|
||||
"id": "bworld:iron_ingot",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "#bworld:logs",
|
||||
"output": {
|
||||
"id": "bworld:coal",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:salmon",
|
||||
"output": {
|
||||
"id": "bworld:cooked_salmon",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:stone",
|
||||
"output": {
|
||||
"id": "bworld:smooth_stone",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:cobblestone",
|
||||
"output": {
|
||||
"id": "bworld:stone",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:tin_ore",
|
||||
"output": {
|
||||
"id": "bworld:tin_ingot",
|
||||
|
||||
@@ -8,6 +8,7 @@ import { register_effects } from "./effects.ts";
|
||||
import { register_fishing } from "./fishing.ts";
|
||||
import { stonecutting_options, stonecutting_recipes } from "./stonecutting.ts";
|
||||
import { SMITHING, type SmithingRecipe } from "./smithing.ts";
|
||||
import { FUEL, type FuelRecipe, SMELTING, type SmeltingRecipe } from "./smelting.ts";
|
||||
import { register_verdigris } from "./verdigris/server.ts";
|
||||
import { type JuiceableParams, JUICER_CAPACITY, JUICER_PRESSES } from "./shared.ts";
|
||||
import { juicing_for, juicing_recipes } from "./juicing.ts";
|
||||
@@ -219,7 +220,7 @@ function register_furnace(ctx: ServerContext) {
|
||||
const container = ctx.containers.get(furnace_data(block).container)!;
|
||||
menu.title = "Furnace";
|
||||
menu.add_slot(container, 0, { x: 55, y: 16 });
|
||||
menu.add_slot(container, 1, { x: 55, y: 52, filter: "fuel" });
|
||||
menu.add_slot(container, 1, { x: 55, y: 52, filter: (item) => ctx.recipes.find(FUEL, item.id) !== undefined });
|
||||
menu.add_slot(container, 2, { x: 115, y: 34, output_only: true });
|
||||
menu.add_player_inventory(7, INVENTORY_Y);
|
||||
for (const field of ["progress", "progress_max", "fuel", "fuel_max"] as const) {
|
||||
@@ -250,7 +251,7 @@ function register_furnace(ctx: ServerContext) {
|
||||
const data = furnace_data(block);
|
||||
const container = ctx.containers.get(data.container)!;
|
||||
const input = container.get(0);
|
||||
const recipe = input && ctx.recipes.furnace_result(input.id);
|
||||
const recipe = input && ctx.recipes.find<SmeltingRecipe>(SMELTING, input.id);
|
||||
|
||||
if (data.fuel > 0) {
|
||||
data.fuel -= 1;
|
||||
@@ -261,8 +262,9 @@ function register_furnace(ctx: ServerContext) {
|
||||
} else {
|
||||
// refuel
|
||||
const fuel = container.get(1);
|
||||
if (data.fuel === 0 && fuel && ctx.recipes.is_fuel(fuel.id)) {
|
||||
data.fuel = ctx.recipes.fuel_value(fuel.id);
|
||||
const burns = fuel && ctx.recipes.find<FuelRecipe>(FUEL, fuel.id);
|
||||
if (data.fuel === 0 && fuel && burns) {
|
||||
data.fuel = burns.burn_time;
|
||||
data.fuel_max = data.fuel;
|
||||
fuel.count -= 1;
|
||||
}
|
||||
@@ -277,7 +279,7 @@ function register_furnace(ctx: ServerContext) {
|
||||
if (result) {
|
||||
result.count += recipe.output.count;
|
||||
} else {
|
||||
container.set(2, recipe.output);
|
||||
container.set(2, { ...recipe.output });
|
||||
}
|
||||
input.count -= 1;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import type { SharedBlock, SharedContext } from "bworld/shared";
|
||||
import { register_fermenting } from "./fermenting.ts";
|
||||
import { register_juicing } from "./juicing.ts";
|
||||
import { register_smelting } from "./smelting.ts";
|
||||
import { register_smithing } from "./smithing.ts";
|
||||
import { register_verdigris_rules } from "./verdigris/shared.ts";
|
||||
|
||||
@@ -20,6 +21,7 @@ export function setup(ctx: SharedContext) {
|
||||
register_juicing(ctx);
|
||||
register_fermenting(ctx);
|
||||
register_smithing(ctx);
|
||||
register_smelting(ctx);
|
||||
}
|
||||
|
||||
// the sides a fence connects on, and the face of the block there it connects to
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// smelting and fuel recipes: the furnace cooks one item into another, burning fuel to do it. both are found by an item
|
||||
// id, and registered by the shared script like smithing.ts
|
||||
import type { SharedContext } from "bworld/shared";
|
||||
|
||||
export const SMELTING = "bworld:smelting";
|
||||
export const FUEL = "bworld:fuel";
|
||||
|
||||
export interface SmeltingRecipe {
|
||||
// the items it smelts
|
||||
input: string[];
|
||||
output: { id: string; count: number };
|
||||
// ticks
|
||||
cook_time: number;
|
||||
}
|
||||
|
||||
export interface FuelRecipe {
|
||||
items: string[];
|
||||
// ticks
|
||||
burn_time: number;
|
||||
}
|
||||
|
||||
export function register_smelting(ctx: SharedContext) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const ticks = (json: any, field: string): number => {
|
||||
if (!Number.isInteger(json[field]) || json[field] < 1) throw new Error(`${field} must be at least 1 tick`);
|
||||
return json[field];
|
||||
};
|
||||
|
||||
// two recipes for one item would leave one that can never be made
|
||||
const smelted = new Set<string>();
|
||||
ctx.recipes.register_type<SmeltingRecipe, string>(SMELTING, {
|
||||
parse(json, read) {
|
||||
const recipe = {
|
||||
input: read.ingredient(json, "input"),
|
||||
output: read.stack(json, "output"),
|
||||
cook_time: ticks(json, "cook_time"),
|
||||
};
|
||||
for (const id of recipe.input) {
|
||||
if (smelted.has(id)) throw new Error(`there's already one for ${id}`);
|
||||
smelted.add(id);
|
||||
}
|
||||
return recipe;
|
||||
},
|
||||
matches: (recipe, id) => recipe.input.includes(id),
|
||||
});
|
||||
|
||||
// a later recipe for an item takes it out of the earlier one's items, so a mod can change how long something
|
||||
// burns and find gives its recipe
|
||||
const burning = new Map<string, FuelRecipe>();
|
||||
ctx.recipes.register_type<FuelRecipe, string>(FUEL, {
|
||||
parse(json, read) {
|
||||
const recipe = { items: read.ingredient(json, "item"), burn_time: ticks(json, "burn_time") };
|
||||
for (const id of recipe.items) {
|
||||
const earlier = burning.get(id);
|
||||
if (earlier) earlier.items = earlier.items.filter((other) => other !== id);
|
||||
burning.set(id, recipe);
|
||||
}
|
||||
return recipe;
|
||||
},
|
||||
matches: (recipe, id) => recipe.items.includes(id),
|
||||
});
|
||||
}
|
||||
@@ -66,7 +66,7 @@ function base_categories(tags: TagApi): RecipeCategory[] {
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "furnace",
|
||||
type: "bworld:smelting",
|
||||
title: "Smelting",
|
||||
width: 82,
|
||||
height: 54,
|
||||
@@ -80,7 +80,7 @@ function base_categories(tags: TagApi): RecipeCategory[] {
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "fuel",
|
||||
type: "bworld:fuel",
|
||||
title: "Fuel",
|
||||
width: 98,
|
||||
height: 36,
|
||||
@@ -323,8 +323,6 @@ export function make_categories(ctx: ClientContext, recipes: Recipe[]): RecipeCa
|
||||
export function category_name(type: string): string {
|
||||
const base: Record<string, string> = {
|
||||
shaped: "Crafting",
|
||||
furnace: "Smelting",
|
||||
fuel: "Fuel",
|
||||
[FISHING]: "Fishing",
|
||||
[CRABPOT]: "Crab Pot",
|
||||
[JUICING]: "Juicing",
|
||||
|
||||
@@ -17,9 +17,9 @@ export function outputs(recipe: Recipe): Ingredient[] {
|
||||
switch (recipe.type) {
|
||||
case "shaped":
|
||||
return [stack(recipe.result)];
|
||||
case "furnace":
|
||||
case "bworld:smelting":
|
||||
return [stack(recipe.output)];
|
||||
case "fuel":
|
||||
case "bworld:fuel":
|
||||
return [];
|
||||
case "bworld:smithing":
|
||||
return [{ ids: [recipe.result], count: 1 }];
|
||||
@@ -46,7 +46,7 @@ export function fluid_inputs(recipe: Recipe): FluidAmount[] {
|
||||
return recipe.fluid_ingredients ?? [];
|
||||
}
|
||||
|
||||
// what a recipe takes. shaped keys, furnace inputs and fuels can be an item or #tag, or a list any of which fits
|
||||
// what a recipe takes. shaped keys, smelting inputs and fuels can be an item or #tag, or a list any of which fits
|
||||
export function inputs(recipe: Recipe, tags: TagApi): Ingredient[] {
|
||||
switch (recipe.type) {
|
||||
case "shaped":
|
||||
@@ -54,9 +54,9 @@ export function inputs(recipe: Recipe, tags: TagApi): Ingredient[] {
|
||||
ids: tags.expand(choice),
|
||||
count: 1,
|
||||
}));
|
||||
case "furnace":
|
||||
case "bworld:smelting":
|
||||
return [{ ids: tags.expand(recipe.input), count: 1 }];
|
||||
case "fuel":
|
||||
case "bworld:fuel":
|
||||
return [{ ids: tags.expand(recipe.item), count: 1 }];
|
||||
case "bworld:smithing":
|
||||
return [{ ids: [recipe.tool], count: 1 }, stack(recipe.material)].concat(
|
||||
|
||||
Reference in New Issue
Block a user