diff --git a/website/data/cookbook/dunechest-recipes.json b/website/data/cookbook/dunechest-recipes.json index 1f53b0eb..207470f4 100644 --- a/website/data/cookbook/dunechest-recipes.json +++ b/website/data/cookbook/dunechest-recipes.json @@ -3,7 +3,7 @@ "ender_chest": { "id": "dunechest_ender_chest", "name": "Ender Chest", - "material": "barrel", + "material": "ender_chest", "custom": true, "icon": "/recipe-icons/dunechest_ender_chest.png", "summary": "A custom chest with three colour pads. Matching frequencies share storage on the same planet; diamond toggles the supplied private mode." diff --git a/website/data/cookbook/item-grades.json b/website/data/cookbook/item-grades.json new file mode 100644 index 00000000..22917862 --- /dev/null +++ b/website/data/cookbook/item-grades.json @@ -0,0 +1,222 @@ +{ + "schema": 1, + "policy": "s1-item-metadata-v1", + "sourceRepository": "unimatrix/plugins", + "sourceCommit": "c7c390972d74557347503b98aaf5400e21d0069c", + "files": { + "JarvisConnector/src/main/resources/item-templates.json": "2c0512376fe8036d03baeb7f240a4d411d4e77cf87001261d943fc1d730fff73", + "JarvisConnector/src/main/java/com/dunerealms/jarvis/ItemMetadataPolicy.java": "48694030cf6fa42ce277b11f56c43f47811e06ac97008b2e553c374e93c3a6fe", + "JarvisConnector/src/main/java/com/dunerealms/jarvis/ItemMetadataOverlay.java": "0d559ca87139659acdceaa615650be4eb3982c14079fe5e1439b9a786c1153f4", + "JarvisConnector/src/main/java/com/dunerealms/jarvis/CraftingGrades.java": "e0ff3547e747f150a760a6a98ade395744a1ba949b7d2b776de4d9a4729c5e56", + "JarvisConnector/src/main/java/com/dunerealms/jarvis/StarterKitFlow.java": "0488703761f22a84557289edfe3b95ceaf7e4f421dce15ef2cd811117f8f60ca", + "JarvisConnector/src/main/java/com/dunerealms/jarvis/CraftedFlight.java": "10d400400ba1c3aeba5f047df7ec94780758b9b5a1521952b6b9789cc6317ce2", + "JarvisConnector/src/main/java/com/dunerealms/jarvis/ArrakisBrewing.java": "454c9931b0c649e50d60dce8953053c2220edab785e234251da4edfcb6feab54", + "JarvisConnector/src/main/java/com/dunerealms/jarvis/SpiceBlocks.java": "5abae8692ae52e3f2bf928a2266c38b847ed2d696c21b38b604045fe69cda90f", + "DuneChest/src/main/java/com/example/dunechest/StorageItems.java": "3027dbad35245027f924db0307c35d280afcb613a1bb8259c19fec1de7c9620d" + }, + "nativeBaseline": { + "version": "26.2", + "clientSha256": "40896ee9f1e2bec3c934daac7e93d41e9e3d9c2f8ae0ca366d52ffbfd1afa290", + "files": { + "data/minecraft/recipe/crafting_table.json": "a400eb22cbca14596197f27a537392103857edd3271bd21771f78c416abc18b9", + "data/minecraft/recipe/ender_chest.json": "6d113f9e8381f20c30477d3a460aeb58d98845e180ab4abc5421663f63f0ca85", + "data/minecraft/tags/item/planks.json": "41c794fb511416dcd3ab6a4da76921b1c9a29e644fd846be92387fa840ea8848", + "net/minecraft/world/item/Items.class": "85e6a9852ce230b7d593ac1ce194b5229b4b60cc2ac53935834eb053649b85aa" + }, + "knowledgeBookRarity": "EPIC" + }, + "scope": "Default issued item grades from JARVIS, independent of the MK device tier in display names. Input-dependent brewing retains the input item metadata. No gameplay grading policy changes.", + "items": { + "bio_paste": { + "material": "magma_cream", + "quality": "very_rare", + "equipmentMark": 8, + "source": "item template:bio_paste" + }, + "chukka_cooked_meat": { + "material": "cooked_chicken", + "quality": "common", + "equipmentMark": 2, + "source": "item template:chukka_cooked_meat" + }, + "contaminated_spice_block": { + "material": "dried_kelp_block", + "quality": "rare", + "equipmentMark": 4, + "source": "item template:contaminated_spice_block" + }, + "dunesponge": { + "material": "sponge", + "quality": "common", + "equipmentMark": 2, + "source": "item template:dunesponge" + }, + "jerboa_cooked_meat": { + "material": "cooked_rabbit", + "quality": "rare", + "equipmentMark": 6, + "source": "item template:jerboa_cooked_meat" + }, + "jerboa_hide_paste": { + "material": "clay_ball", + "quality": "common", + "equipmentMark": 2, + "source": "item template:jerboa_hide_paste" + }, + "jerboa_stew": { + "material": "rabbit_stew", + "quality": "very_rare", + "equipmentMark": 9, + "source": "item template:jerboa_stew" + }, + "farmers_bucket": { + "material": "water_bucket", + "quality": "rare", + "equipmentMark": 7, + "source": "item template:farmers_bucket" + }, + "rehydrated_steak": { + "material": "beef", + "quality": "rare", + "equipmentMark": 7, + "source": "item template:rehydrated_steak" + }, + "spice_cake": { + "material": "pumpkin_pie", + "quality": "rare", + "equipmentMark": 7, + "source": "item template:spice_cake" + }, + "spice_dough": { + "material": "wheat", + "quality": "common", + "equipmentMark": 2, + "source": "item template:spice_dough" + }, + "spice_paste": { + "material": "slime_ball", + "quality": "common", + "equipmentMark": 2, + "source": "item template:spice_paste" + }, + "jerboa_egg": { + "material": "egg", + "quality": "uncommon", + "equipmentMark": 3, + "source": "item template:jerboa_egg" + }, + "jerboa_leather": { + "material": "leather", + "quality": "uncommon", + "equipmentMark": 3, + "source": "item template:jerboa_leather" + }, + "spice_bread": { + "material": "enchanted_golden_apple", + "quality": "very_rare", + "equipmentMark": 9, + "source": "item template:spice_bread" + }, + "starter-repair-plate-v1": { + "material": "iron_ingot", + "quality": "uncommon", + "equipmentMark": 1, + "source": "StarterKitFlow.part factory" + }, + "starter-binding-patch-v1": { + "material": "leather", + "quality": "uncommon", + "equipmentMark": 1, + "source": "StarterKitFlow.part factory" + }, + "starter-tool-fitting-v1": { + "material": "copper_ingot", + "quality": "uncommon", + "equipmentMark": 1, + "source": "StarterKitFlow.part factory" + }, + "starter-calibration-piece-v1": { + "material": "quartz", + "quality": "uncommon", + "equipmentMark": 1, + "source": "StarterKitFlow.part factory" + }, + "spice_block": { + "material": "dried_kelp_block", + "quality": "uncommon", + "equipmentMark": 2, + "source": "item template:spice_block" + }, + "smuggled_spice_block": { + "material": "dried_kelp_block", + "quality": "uncommon", + "equipmentMark": 3, + "source": "item template:smuggled_spice_block" + }, + "crafted_elytra": { + "material": "elytra", + "quality": "very_rare", + "equipmentMark": 11, + "source": "item template:dr_s1_elytra_crafted_v2" + }, + "jerboa_water_vial": { + "material": "potion", + "quality": "rare", + "equipmentMark": 6, + "source": "item template:jerboa_water_vial" + }, + "water_of_life": { + "material": "potion", + "quality": "very_rare", + "equipmentMark": 7, + "source": "item template:water_of_life" + }, + "spice_boosted_potion": { + "material": "potion", + "mode": "input", + "source": "ArrakisBrewing.boost clones the imported potion and preserves its item metadata" + }, + "dunechest_ender_chest": { + "material": "ender_chest", + "quality": "very_rare", + "equipmentMark": 9, + "source": "vanilla recipe:ender_chest; fixed ender_eye MK8 +1" + }, + "dunechest_speed_hopper_1": { + "material": "hopper", + "quality": "uncommon", + "equipmentMark": 3, + "source": "material grade:HOPPER" + }, + "dunechest_speed_hopper_2": { + "material": "hopper", + "quality": "uncommon", + "equipmentMark": 3, + "source": "material grade:HOPPER" + }, + "dunechest_speed_hopper_3": { + "material": "hopper", + "quality": "uncommon", + "equipmentMark": 3, + "source": "material grade:HOPPER" + }, + "dunechest_auto_crafter": { + "material": "crafting_table", + "quality": "uncommon", + "equipmentMark": 3, + "source": "vanilla recipe:crafting_table; minimum planks MK2 +1" + }, + "dunechest_wrench": { + "material": "knowledge_book", + "quality": "very_rare", + "equipmentMark": 10, + "source": "native rarity:EPIC" + }, + "dunechest_dune_beacon": { + "material": "sea_lantern", + "quality": "rare", + "equipmentMark": 8, + "source": "material grade:SEA_LANTERN" + } + } +} diff --git a/website/scripts/recipe-catalogue.mjs b/website/scripts/recipe-catalogue.mjs index 02e65e23..41e9fef4 100644 --- a/website/scripts/recipe-catalogue.mjs +++ b/website/scripts/recipe-catalogue.mjs @@ -5,6 +5,7 @@ const smoker = new URL('../data/cookbook/survival-food-recipes.json', import.met 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 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 = { @@ -41,6 +42,20 @@ 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); @@ -59,6 +74,8 @@ function item(command) { 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()) { @@ -127,6 +144,7 @@ export function recipeCatalogue() { 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 }; diff --git a/website/tests/cookbook-item-grades.test.mjs b/website/tests/cookbook-item-grades.test.mjs new file mode 100644 index 00000000..9c2a7eb8 --- /dev/null +++ b/website/tests/cookbook-item-grades.test.mjs @@ -0,0 +1,50 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {readFileSync} from 'node:fs'; +import {recipeCatalogue,withRecipeGrade} from '../scripts/recipe-catalogue.mjs'; +import {itemLoreModel} from '../control-panel/public/item-lore-model.mjs'; + +test('all Cookbook outputs have source-bound grades or explicitly preserve input metadata',()=>{ + const recipes=recipeCatalogue(),metadata=JSON.parse(readFileSync(new URL('../data/cookbook/item-grades.json',import.meta.url))); + assert.equal(recipes.length,39);assert.equal(new Set(recipes.map(r=>r.output.id)).size,32); + assert.equal(metadata.sourceRepository,'unimatrix/plugins');assert.match(metadata.sourceCommit,/^[a-f0-9]{40}$/); + for(const hash of Object.values(metadata.files))assert.match(hash,/^[a-f0-9]{64}$/); + for(const recipe of recipes){ + const definition=metadata.items[recipe.output.id];assert.ok(definition,recipe.id);assert.equal(recipe.output.material,definition.material); + if(definition.mode==='input'){ + assert.equal(recipe.id,'spice_boosted_potion');assert.equal(recipe.output.metadataMode,'input'); + assert.equal(recipe.output.quality,undefined);assert.equal(recipe.output.equipmentMark,undefined);continue; + } + const card=itemLoreModel({...recipe.output,nativeMetadata:true}); + assert.equal(card.quality,definition.quality);assert.equal(card.mark,definition.equipmentMark); + assert.doesNotMatch(card.qualityLabel,/not registered/);assert.doesNotMatch(card.markLabel,/not registered/); + } +}); + +test('previously missing output grades reach the shared item card without deriving them from device names',()=>{ + const recipes=recipeCatalogue(),get=id=>recipes.find(r=>r.output.id===id).output; + for(const [id,quality,mark] of [ + ['jerboa_leather','uncommon',3],['spice_bread','very_rare',9], + ['spice_block','uncommon',2],['smuggled_spice_block','uncommon',3], + ['crafted_elytra','very_rare',11],['jerboa_water_vial','rare',6],['water_of_life','very_rare',7], + ['dunechest_ender_chest','very_rare',9],['dunechest_auto_crafter','uncommon',3], + ['dunechest_wrench','very_rare',10],['dunechest_dune_beacon','rare',8], + ...[1,2,3].map(t=>['dunechest_speed_hopper_'+t,'uncommon',3]), + ]){assert.equal(get(id).quality,quality,id);assert.equal(get(id).equipmentMark,mark,id);} + const powercore=itemLoreModel(get('dunechest_dune_beacon')); + assert.match(powercore.title,/MK XIV/);assert.equal(powercore.markLabel,'MK VIII');assert.equal(powercore.qualityLabel,'Rare'); + assert.equal(get('dunechest_ender_chest').material,'ender_chest'); + const ingredient=recipes.find(r=>r.id==='dunechest_speed_hopper_2').grid[4]; + assert.equal(ingredient.id,'dunechest_speed_hopper_1'); +}); + +test('missing, conflicting or material-mismatched metadata cannot silently produce unknown item grades',()=>{ + const output={id:'fixture',material:'hopper'}; + const grade={material:'hopper',quality:'uncommon',equipmentMark:3}; + assert.throws(()=>withRecipeGrade(output,undefined),/Missing/); + assert.throws(()=>withRecipeGrade(output,{...grade,material:'barrel'}),/mismatched/); + assert.throws(()=>withRecipeGrade(output,{...grade,equipmentMark:15}),/Invalid/); + assert.throws(()=>withRecipeGrade({...output,quality:'legendary'},grade),/conflicts/); + assert.throws(()=>withRecipeGrade(output,{...grade,mode:'input'}),/fixed grade/); + assert.equal(withRecipeGrade({...output,name:'Anything MK XIV'},grade).equipmentMark,3); +}); diff --git a/website/tests/dunechest-cookbook.test.mjs b/website/tests/dunechest-cookbook.test.mjs index 319a8ba5..6a577a60 100644 --- a/website/tests/dunechest-cookbook.test.mjs +++ b/website/tests/dunechest-cookbook.test.mjs @@ -13,7 +13,7 @@ test('DuneChest cookbook preserves shaped gaps, exact custom upgrade ingredients const upgrade=by('speed_hopper_'+tier),core=upgrade.grid[4];assert.equal(core.id,'dunechest_speed_hopper_'+previous);assert.equal(core.custom,true);assert.ok(all.some(r=>r.output.id===core.id)); } assert.equal(by('ender_chest').inputs.filter(i=>i.material==='obsidian').length,7); - for(const r of recipes.filter(r=>r.shaped)){assert.equal(r.grid.length,9);assert.equal(r.amount,1);assert.equal(r.shaped,true);assert.match(r.notes,/all six servers, including Lobby/);assert.equal(r.output.quality,undefined);assert.equal(r.output.equipmentMark,undefined);} + for(const r of recipes.filter(r=>r.shaped)){assert.equal(r.grid.length,9);assert.equal(r.amount,1);assert.equal(r.shaped,true);assert.match(r.notes,/all six servers, including Lobby/);assert.ok(r.output.quality);assert.ok(Number.isInteger(r.output.equipmentMark));} const icons=new Map(recipeIcons(recipes));assert.equal(icons.size,6);for(const bytes of icons.values())assert.equal(bytes.subarray(0,8).toString('hex'),'89504e470d0a1a0a'); const provenance=JSON.parse(readFileSync(new URL('../data/cookbook/dunechest-source.json',import.meta.url)));assert.equal(provenance.sourceCommit,'56346a273d1b014fa256d26d34b4a4e33cc1d6b5');assert.equal(Object.keys(provenance.files).length,2); for(const [path,source] of Object.entries(provenance.icons))assert.equal(createHash('sha256').update(readFileSync(new URL('../data/cookbook/'+path,import.meta.url))).digest('hex'),source.sha256); @@ -27,7 +27,7 @@ test('Ixian names and the beamless powercore recipe use stable custom identities const beacon=by('dune_beacon');assert.equal(beacon.output.name,'Ixian Powercore MK XIV');assert.equal(beacon.output.id,'dunechest_dune_beacon'); assert.deepEqual(beacon.inputs.map(i=>[i.material,i.custom]),[['beacon',false],['ender_eye',false]]); assert.equal(beacon.shaped,false);assert.equal(beacon.grid.length,9);assert.equal(beacon.grid.filter(Boolean).length,2);assert.match(beacon.notes,/all six servers, including Lobby/); - assert.equal(beacon.output.equipmentMark,undefined);assert.equal(beacon.output.quality,undefined); + assert.equal(beacon.output.equipmentMark,8);assert.equal(beacon.output.quality,'rare'); const provenance=JSON.parse(readFileSync(new URL('../data/cookbook/dunechest-source.json',import.meta.url))); assert.equal(createHash('sha256').update(readFileSync(new URL('../data/cookbook/'+provenance.beacon.icon.path,import.meta.url))).digest('hex'),provenance.beacon.icon.sha256); }); diff --git a/website/tests/web-repository-scope.test.mjs b/website/tests/web-repository-scope.test.mjs index f391fd55..7c0dfd16 100644 --- a/website/tests/web-repository-scope.test.mjs +++ b/website/tests/web-repository-scope.test.mjs @@ -7,11 +7,17 @@ import {MAIN_MENU_GROUPS} from '../scripts/main-menu.mjs'; import {PORTAL_NAV} from '../scripts/portal-navigation.mjs'; import {SHARED_FOOTER} from '../scripts/site-chrome.mjs'; -test('website-only inputs preserve all 32 published recipes and their exact icon bytes',()=>{ +test('website-only inputs preserve all 32 published recipes and icons apart from verified grade enrichment',()=>{ const baseline=JSON.parse(readFileSync(new URL('./fixtures/cookbook-before-repository-split.json',import.meta.url))); const hash=bytes=>createHash('sha256').update(bytes).digest('hex'),recipes=recipeCatalogue(); const original=recipes.filter(recipe=>!recipe.id.startsWith('dunechest_')); - assert.equal(original.length,baseline.recipes);assert.equal(hash(JSON.stringify(original)),baseline.catalogueSha256); + const enriched=new Set(['jerboa_leather','spice_bread','spice_block','smuggled_spice_block','crafted_elytra','jerboa_water_vial','water_of_life','spice_boosted_potion']); + const previous=original.map(recipe=>{ + if(!enriched.has(recipe.output.id))return recipe; + const output={...recipe.output};delete output.quality;delete output.equipmentMark;delete output.metadataMode; + return {...recipe,output}; + }); + assert.equal(original.length,baseline.recipes);assert.equal(hash(JSON.stringify(previous)),baseline.catalogueSha256); assert.deepEqual(Object.fromEntries(recipeIcons(original).map(([name,bytes])=>[name,hash(bytes)])),baseline.icons); }); diff --git a/website/web/imperial-recipe-book.js b/website/web/imperial-recipe-book.js index 07f801f4..37af08ae 100644 --- a/website/web/imperial-recipe-book.js +++ b/website/web/imperial-recipe-book.js @@ -69,6 +69,9 @@ try { get('recipe-result').replaceChildren(icon(selected.output)); get('recipe-result').setAttribute('aria-label', selected.output.name); const card = itemLoreCard({ ...selected.output, nativeMetadata: true }); + if (selected.output.metadataMode === 'input') { + card.querySelector('.item-lore-identity').replaceChildren(node('strong', 'Quality follows input'), node('em', 'MK follows input')); + } if (selected.output.icon) card.querySelector('.item-lore-name img').src = selected.output.icon; get('recipe-item-summary').textContent = selected.output.summary; get('recipe-item-card').replaceChildren(card);