import { existsSync, readdirSync, readFileSync } from 'node:fs'; const source = new URL('../data/cookbook/crafting/', import.meta.url); const smoker = new URL('../data/cookbook/survival-food-recipes.json', import.meta.url); const repairParts = new URL('../data/cookbook/starter-repair-parts.json', import.meta.url); const duneChest = new URL('../data/cookbook/dunechest-recipes.json', import.meta.url); const spiceCrafting = new URL('../data/cookbook/spice-crafting.json', import.meta.url); const itemGrades = new URL('../data/cookbook/item-grades.json', import.meta.url); const arrakisItems = new URL('../data/cookbook/items/', import.meta.url); const vanillaFoodSaturation = { beef: 1.8, enchanted_golden_apple: 9.6 }; const itemSummaries = { bio_paste: 'A concentrated blend of Spice Paste and Rehydrated Steak. Process it in a smoker to make Spice Bread.', chukka_cooked_meat: 'Cooked meat from an Arrakis Chukka. Eat it to restore hunger and saturation.', contaminated_spice_block: 'A block made by packing nine portions of contaminated spice together.', dunesponge: 'A spice-treated sponge that can pick up one water source and place it elsewhere on Arrakis.', jerboa_cooked_meat: 'Cooked meat from an Arrakis Jerboa. Eat it to restore hunger and saturation, or use it in Jerboa Stew.', jerboa_hide_paste: 'Prepared Jerboa hide. Smoke it to make Jerboa Leather, or combine it with Melange to make a Weirding Module.', jerboa_stew: 'A prepared meal made with Jerboa meat. Eat it to restore hunger and saturation.', farmers_bucket: 'A one-use bucket for placing water on Arrakis.', rehydrated_steak: 'Meat rehydrated with water. Eat it or combine it with Spice Paste to make Bio Paste.', spice_cake: 'A finished spice food. Eat it to restore hunger and saturation.', spice_dough: 'A prepared spice mixture used to make Spice Cake.', spice_paste: 'A concentrated mix of Melange Spice and acacia. Use it to prepare Bio Paste.', jerboa_egg: 'A throwable Weirding Module. It produces a harmful splash and smoke when it strikes a target.', jerboa_leather: 'Leather made by processing Jerboa Hide Paste in a smoker.', spice_bread: 'Food made by smoking Bio Paste. Eat it to restore hunger and saturation.', 'starter-repair-plate-v1': 'A starter equipment repair part used to restore protective plates.', 'starter-binding-patch-v1': 'A leather repair part used to patch worn stillsuit fabric.', 'starter-tool-fitting-v1': 'A copper repair part used to replace worn equipment fittings.', 'starter-calibration-piece-v1': 'A quartz repair part used to calibrate repaired suit systems.', spice_block: 'Nine portions of Melange compressed into one block for storage and transport.', smuggled_spice_block: 'Nine portions of Smuggled Spice compressed into one block. The block retains its smuggled origin.', crafted_elytra: 'A pair of wings worn in the chest slot. Use them to glide.', jerboa_water_vial: 'A portable supply of water. Use it in recipes or to fill a cauldron on Arrakis.', water_of_life: 'A rare result of brewing a Blood Vial with spice. Drinking it can grant temporary combat effects, with a 1% chance of death.', spice_boosted_potion: 'An imported potion enhanced with spice on Arrakis. Drink it for stronger effects where the rounded effect level increases.', }; const foodIds = new Set(['chukka_cooked_meat', 'jerboa_cooked_meat', 'jerboa_stew', 'rehydrated_steak', 'spice_bread', 'spice_cake']); const ecologyIcons = new URL('../data/cookbook/icons/', import.meta.url); function entry(id, name, material = id, custom = false) { return { id, name, material, custom }; } export function withRecipeGrade(output, definition) { if (!definition || definition.material !== output.material) throw Error('Missing or mismatched Cookbook grade for ' + output.id); if (definition.mode === 'input') { if (output.quality !== undefined || output.equipmentMark !== undefined || definition.quality !== undefined || definition.equipmentMark !== undefined) throw Error('Input-dependent item has a fixed grade: ' + output.id); return { ...output, metadataMode: 'input' }; } const { quality, equipmentMark } = definition; if (!['common', 'uncommon', 'rare', 'very_rare', 'legendary', 'mythic', 'relic'].includes(quality) || (quality === 'relic' ? equipmentMark !== 'infinite' : !Number.isInteger(equipmentMark) || equipmentMark < 0 || equipmentMark > 14)) throw Error('Invalid Cookbook grade for ' + output.id); if (output.quality !== undefined && output.quality !== quality || output.equipmentMark !== undefined && output.equipmentMark !== equipmentMark) throw Error('Cookbook grade conflicts with its item definition: ' + output.id); return { ...output, quality, equipmentMark }; } function item(command) { const material = command.match(/^minecraft:([a-z0-9_]+)/)?.[1]; if (!material) throw Error('Unrecognised recipe item ' + command); const custom = command.match(/"executableitems:ei-id":"([^"]+)"/)?.[1]; const name = command.match(/minecraft:custom_name=\{"text":"([^"]+)"/)?.[1] ?? material.replaceAll('_', ' ').replace(/\b\w/g, letter => letter.toUpperCase()); const result = entry(custom ?? material, name, material, Boolean(custom)); const quality = command.match(/"dunerealms:quality":"([a-z_]+)"/)?.[1]; const mark = command.match(/"dunerealms:equipment_mark":"(\d+)"/)?.[1]; const lore = command.match(/minecraft:lore=(\[[^\]]*\])/); if (quality) result.quality = quality; if (mark) result.equipmentMark = Number(mark); if (lore) result.lore = JSON.parse(lore[1]).map(line => line.text).filter(line => !/ \| MK /.test(line)); return result; } export function recipeCatalogue() { const recipes = []; const metadata = JSON.parse(readFileSync(itemGrades, 'utf8')); if (metadata.schema !== 1 || metadata.policy !== 's1-item-metadata-v1') throw Error('Unsupported Cookbook item metadata'); const spice = entry('spice', 'Melange Spice', 'orange_dye', true); const requiresSpice = new Set(['dunesponge.yml', 'spice_paste.yml', 'spice_dough.yml', 'weirding_module.yml']); for (const file of readdirSync(source).filter(name => name.endsWith('.yml')).sort()) { const recipe = JSON.parse(readFileSync(new URL(file, source), 'utf8')); const station = recipe.recipeType === 'FURNACE' ? 'Furnace' : 'Crafting table'; if (recipe.recipeType !== 'FURNACE' && recipe.typeOfCraftingTableRecipe !== 'SHAPELESS') { throw Error('Unsupported recipe layout in ' + file); } const inputs = Object.entries(recipe) .filter(([key]) => /^input\d+$/.test(key)) .sort(([a], [b]) => Number(a.slice(5)) - Number(b.slice(5))) .map(([, command]) => command === 'minecraft:orange_dye' && requiresSpice.has(file) ? spice : item(command)); recipes.push({ id: file.slice(0, -4), station, inputs, output: item(recipe.result), amount: recipe.resultAmount ?? 1 }); } for (const recipe of JSON.parse(readFileSync(smoker, 'utf8')).smoker) { const output = recipes.find(entry => entry.output.id === recipe.result)?.output ?? entry(recipe.result, recipe.result.replaceAll('_', ' ').replace(/\b\w/g, letter => letter.toUpperCase()), recipe.result === 'spice_bread' ? 'bread' : 'leather', true); recipes.push({ id: recipe.id + '-smoker', station: 'Smoker', inputs: [item(recipe.inputCommand)], output, amount: recipe.amount }); } const smuggled = entry('smuggled_spice', 'Smuggled Spice', 'orange_dye', true); const crafting = 'Crafting table'; for (const part of JSON.parse(readFileSync(repairParts, 'utf8'))) { const ingredient = item(part.material.toLowerCase()); recipes.push({ id: part.id, station: crafting, inputs: [ingredient, spice], output: { ...entry(part.id, part.name, ingredient.material, true), quality: "uncommon", equipmentMark: 1, lore: [part.purpose] }, amount: 1, notes: part.purpose + ' Genuine Melange or Smuggled Spice works.' }); } for (const [id, name, ingredient] of [['spice_block', 'Spice Block', spice], ['smuggled_spice_block', 'Smuggled Spice Block', smuggled]]) { recipes.push({ id, station: crafting, inputs: Array(9).fill(ingredient), output: entry(id, name, 'dried_kelp_block', true), amount: 1, shaped: true, notes: 'Fill all nine slots with the same kind of genuine spice.' }); } const flight = ['netherite_ingot', 'phantom_membrane', 'netherite_ingot', 'iron_ingot', 'diamond', 'iron_ingot', 'copper_ingot', 'phantom_membrane', 'copper_ingot'].map(material => item('minecraft:' + material)); recipes.push({ id: 'crafted_elytra', station: crafting, inputs: flight, output: entry('crafted_elytra', 'Elytra', 'elytra', true), amount: 1, shaped: true }); const water = entry('jerboa_water_vial', 'Vial of Water', 'potion', true); const blood = entry('blood_vial', 'Blood Vial', 'potion', true); const life = entry('water_of_life', 'Water of Life', 'potion', true); recipes.push({ id: 'imported_water_vials', station: crafting, inputs: [entry('imported_water_bucket', 'Imported Water Bucket', 'water_bucket')], output: water, amount: 6, notes: 'Craft on Arrakis using a water bucket sourced from another world.' }); const brew = 'On Arrakis, brew genuine spice with a Blood Vial. Per vial: 50% Vial of Water, 5% Water of Life, 45% no output.'; recipes.push({ id: 'brew_water_vial', station: 'Brewing stand', inputs: [blood, spice], output: water, amount: 1, possible: true, notes: brew }); recipes.push({ id: 'brew_water_of_life', station: 'Brewing stand', inputs: [blood, spice], output: life, amount: 1, possible: true, notes: brew + ' Drinking Water of Life has a 1% fatal chance.' }); recipes.push({ id: 'spice_boosted_potion', station: 'Brewing stand', inputs: [entry('imported_potion', 'Imported Potion', 'potion'), spice], output: entry('spice_boosted_potion', 'Spice-Boosted Potion', 'potion', true), amount: 1, notes: 'Brew once on Arrakis. Effect levels are multiplied by 1.25 and rounded to the nearest whole level; duration stays the same.' }); const storage = JSON.parse(readFileSync(duneChest, 'utf8')); for (const recipe of storage.recipes) { if (recipe.shapeless) { if (!Array.isArray(recipe.shapeless) || !recipe.shapeless.length || recipe.shapeless.length > 9) throw Error('Invalid shapeless DuneChest recipe'); const inputs = recipe.shapeless.map(ingredient => item(ingredient)); recipes.push({id: 'dunechest_' + recipe.id, station: crafting, inputs, grid: Array.from({length: 9}, (_, index) => inputs[index] ?? null), output: storage.items[recipe.id], amount: 1, shaped: false, notes: recipe.notes}); continue; } if (recipe.pattern.length !== 3 || recipe.pattern.some(row => row.length !== 3)) throw Error('Invalid DuneChest crafting grid'); const grid = recipe.pattern.flatMap(row => [...row].map(symbol => { if (symbol === ' ') return null; const ingredient = recipe.ingredients[symbol]; const value = ingredient?.startsWith('minecraft:') ? item(ingredient) : storage.items[ingredient]; if (!value) throw Error('Missing DuneChest ingredient ' + symbol); return value; })); recipes.push({id: 'dunechest_' + recipe.id, station: crafting, inputs: grid.filter(Boolean), grid, output: storage.items[recipe.id], amount: 1, shaped: true, notes: 'Available on all six servers, including Lobby.'}); } for (const spec of JSON.parse(readFileSync(spiceCrafting, 'utf8'))) { const output = {...entry(spec.id, spec.name, spec.material.toLowerCase(), true), summary: spec.details}; let inputs, grid, shaped; if (spec.id === 'spice_coal') { inputs = [spice, entry('coal', 'Coal or Charcoal', 'coal')]; shaped = false; } else if (spec.id === 'spice_tender') { inputs = [entry('minecart', 'Minecart', 'minecart'), entry('spice_coal', 'Spice Coal', 'coal', true)]; shaped = false; } else { const iron = entry('iron_ingot', 'Iron Ingot', 'iron_ingot'); const cooker = entry(output.material, output.material.replaceAll('_', ' ').replace(/\b\w/g, c => c.toUpperCase()), output.material); grid = [iron, spice, iron, spice, cooker, spice, iron, spice, iron]; inputs = grid.filter(Boolean); shaped = true; } grid ??= Array.from({length: 9}, (_, index) => inputs[index] ?? null); recipes.push({id: spec.id, station: crafting, inputs, grid, output, amount: 1, shaped, notes: spec.details + (spec.id === 'spice_coal' ? ' Requires genuine raw Melange; ordinary orange dye will not work. One Spice Coal smelts 50 items.' : spec.id === 'spice_tender' ? ' Requires genuine Spice Coal; ordinary coal will not work.' : ' Requires genuine raw Melange and the matching vanilla cooker.')}); } for (const recipe of recipes) { if (foodIds.has(recipe.output.id)) { const definition = JSON.parse(readFileSync(new URL(recipe.output.id + '.yml', arrakisItems), 'utf8')); const material = definition.material.toLowerCase(); const saturation = definition.foodFeatures?.saturation ?? vanillaFoodSaturation[material]; if (!Number.isFinite(saturation)) throw Error('Missing saturation for ' + recipe.output.id); recipe.output = { ...recipe.output, material, stats: [{ label: 'Saturation per serving', value: '+' + saturation + ' points' }] }; } recipe.output = withRecipeGrade(recipe.output, metadata.items[recipe.output.id]); const summary = itemSummaries[recipe.output.id] ?? recipe.output.summary; if (!summary) throw Error('Missing item summary for ' + recipe.output.id); recipe.output = { ...recipe.output, summary }; for (const ingredient of [...recipe.inputs, recipe.output]) { if (ingredient.custom && existsSync(new URL(ingredient.id + '.png', ecologyIcons))) ingredient.icon = '/recipe-icons/' + ingredient.id + '.png'; } } return recipes; } export function recipeIcons(recipes) { const icons = new Set(recipes.flatMap(recipe => [...recipe.inputs, recipe.output]).map(item => item.icon).filter(Boolean)); return [...icons].map(path => [path, readFileSync(new URL(path.split('/').at(-1), ecologyIcons))]); }