Publish regional food and drink recipes with authored icons and lore
This commit is contained in:
parent
6c525f8a64
commit
28ebc5e043
2 changed files with 3980 additions and 373 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
||||
import {regionalCookbook} from './regional-cookbook.mjs';
|
||||
|
||||
const source = new URL('../data/cookbook/crafting/', import.meta.url);
|
||||
const smoker = new URL('../data/cookbook/survival-food-recipes.json', import.meta.url);
|
||||
|
|
@ -173,7 +174,7 @@ export function recipeCatalogue() {
|
|||
if (ingredient.custom && existsSync(new URL(ingredient.id + '.png', ecologyIcons))) ingredient.icon = '/recipe-icons/' + ingredient.id + '.png';
|
||||
}
|
||||
}
|
||||
return recipes;
|
||||
return [...recipes,...regionalCookbook(recipes)];
|
||||
}
|
||||
|
||||
export function recipeIcons(recipes) {
|
||||
|
|
|
|||
38
website/scripts/regional-cookbook.mjs
Normal file
38
website/scripts/regional-cookbook.mjs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import {readFileSync} from 'node:fs';
|
||||
|
||||
export const cookingWorlds = Object.freeze({sigma_draconis_iv:'Ordos / Sigma Draconis IV',kaitain:'Kaitain',caladan:'Caladan',arrakis:'Arrakis',giedi_prime:'Harkveen / Giedi Prime'});
|
||||
const catalogueUrl = new URL('../data/cookbook/regional-cooking.json',import.meta.url);
|
||||
const stations={craft:'Crafting table',smoker:'Smoker',harvest:'Harvest',milk:'Milking',forage:'Foraging'};
|
||||
|
||||
export function regionalCookbook(legacy, data=JSON.parse(readFileSync(catalogueUrl,'utf8'))) {
|
||||
if(data.schema!==1||data.policy!=='s1-item-metadata-v1'||!Array.isArray(data.items))throw Error('Unsupported regional cooking catalogue');
|
||||
const byId=new Map(),outputs=new Map(legacy.map(r=>[r.output.id,r.output]));
|
||||
for(const row of data.items){
|
||||
if(!/^[a-z][a-z0-9_]*$/.test(row.id)||byId.has(row.id)||outputs.has(row.id))throw Error('Duplicate or invalid regional item '+row.id);
|
||||
if(!cookingWorlds[row.world]||!stations[row.station]||!Number.isInteger(row.mark)||row.mark<3||row.mark>14)throw Error('Invalid regional production '+row.id);
|
||||
if(row.quality!=='uncommon'||!Array.isArray(row.lore)||!row.lore.length||row.lore.some(l=>typeof l!=='string'||!l.trim()))throw Error('Invalid authored metadata '+row.id);
|
||||
if(row.alcohol&&(!(row.alcohol.chance>0&&row.alcohol.chance<=1)||row.alcohol.nauseaSeconds>60||row.hydration!==0))throw Error('Invalid alcohol '+row.id);
|
||||
byId.set(row.id,row);
|
||||
}
|
||||
function item(id){
|
||||
if(id.startsWith('minecraft:')){const material=id.slice(10);return {id:material,name:material==='potion'?'Plain water bottle':material.replaceAll('_',' ').replace(/\b\w/g,c=>c.toUpperCase()),material,custom:false};}
|
||||
const row=byId.get(id);
|
||||
if(!row){const old=outputs.get(id);if(old)return old;if(id==='spice')return {id,name:'Genuine Melange Spice',material:'orange_dye',custom:true};if(id==='jerboa_raw_meat')return {id,name:'Raw Jerboa Meat',material:'rabbit',custom:true};throw Error('Unknown ingredient '+id);}
|
||||
const stats=[];
|
||||
if(row.nutrition)stats.push({label:'Hunger restored',value:'+'+row.nutrition+' points'});
|
||||
if(row.saturation)stats.push({label:'Saturation per serving',value:'+'+row.saturation+' points'});
|
||||
if(row.hydration)stats.push({label:'Hydration restored',value:'+'+row.hydration+' points'});
|
||||
if(row.alcohol)stats.push({label:'Drunkenness chance',value:Math.round(row.alcohol.chance*100)+'% per serving'});
|
||||
return {id:row.id,name:row.name,material:row.material,custom:true,quality:row.quality,equipmentMark:row.mark,lore:row.lore,stats,icon:'/recipe-icons/'+row.id+'.png',summary:row.lore.join(' ')};
|
||||
}
|
||||
return data.items.map(row=>{
|
||||
const inputs=row.inputs.flatMap(ing=>{
|
||||
if(!Number.isInteger(ing.amount)||ing.amount<1||ing.amount>9)throw Error('Invalid ingredient quantity '+row.id);
|
||||
return Array.from({length:ing.amount},()=>item(ing.id));
|
||||
});
|
||||
if(inputs.length>9||row.station==='smoker'&&inputs.length!==1)throw Error('Invalid native recipe '+row.id);
|
||||
const acquisition={harvest:'Harvest the genuine animal in its native region; ordinary vanilla meat cannot replace the species-tagged ingredient.',milk:'Use a bucket on a real red or brown mooshroom on Kaitain.',forage:'Rarely gathered from naturally decaying oak or birch leaves on Caladan.'}[row.station];
|
||||
const notes=[acquisition,'Production: '+cookingWorlds[row.world]+(row.id==='hoglin_cuts'?' Nether.':' overworld only.'),'Products can be carried, consumed and traded on every server.',inputs.some(i=>i.id==='potion')?'Use plain water; other potions are not accepted.':'',row.alcohol?'Each successful serving has a '+Math.round(row.alcohol.chance*100)+'% chance of temporary drunkenness for '+row.alcohol.nauseaSeconds+' seconds. Alcohol does not restore thirst.':''].filter(Boolean).join(' ');
|
||||
return {id:row.id,station:stations[row.station],inputs,output:item(row.id),amount:row.amount,shaped:false,world:row.world,worldName:cookingWorlds[row.world],collection:'Cooking & Baking Beta',acquisition:Boolean(acquisition),notes};
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff