From 91365ac09d7a7553a98d587bd0f4880a29c1d526 Mon Sep 17 00:00:00 2001 From: Patrick 'Quezler' Mounier Date: Sat, 14 May 2022 12:42:56 +0200 Subject: [PATCH] Stash patchouli book for masterful machinery --- automation/nodejs/export-mm-to-patchouli.js | 69 +++++++++++++++++++ patchouli_books/masterful_machinery/book.json | 6 ++ .../en_us/categories/structures.json | 5 ++ .../en_us/entries/structures/.gitignore | 2 + 4 files changed, 82 insertions(+) create mode 100644 automation/nodejs/export-mm-to-patchouli.js create mode 100644 patchouli_books/masterful_machinery/book.json create mode 100644 patchouli_books/masterful_machinery/en_us/categories/structures.json create mode 100644 patchouli_books/masterful_machinery/en_us/entries/structures/.gitignore diff --git a/automation/nodejs/export-mm-to-patchouli.js b/automation/nodejs/export-mm-to-patchouli.js new file mode 100644 index 0000000000..32bffa31bf --- /dev/null +++ b/automation/nodejs/export-mm-to-patchouli.js @@ -0,0 +1,69 @@ +const fs = require('fs') + +const structures_path = 'kubejs/data/masterful_machinery/recipes'; + +const unused_char = '}' // to free up the 0 with + +fs.readdir(structures_path, function (err, files) { + files.forEach(file => { + console.log(`${structures_path}/${file}`) + fs.readFile(`${structures_path}/${file}`, (err, data) => { + const recipe = JSON.parse(data); + + let mapping = { + 'C': `masterfulmachinery:${recipe.controllerId}_controller` + } + + // `"B": { "block": "astralsorcery:marble_pillar" },` -> `"B": astralsorcery:marble_pillar,` + for (const [char, required] of Object.entries(recipe.legend)) { + mapping[char] = required.block; + } + + // patchouli reserves the 0 char for the placement anchor + if(mapping['0'] != undefined) { + mapping[unused_char] = mapping['0']; delete mapping[unused_char]; + recipe.layout = JSON.parse(JSON.stringify(recipe.layout).replaceAll('0', unused_char)) + } + + { // use the controller as the placement anchor + recipe.layout = JSON.parse(JSON.stringify(recipe.layout).replaceAll('C', '0')) + mapping['0'] = mapping['C']; delete mapping['C']; + } + + { // patchouli consideres " " as air and "_" as any other block + recipe.layout = JSON.parse(JSON.stringify(recipe.layout).replaceAll(' ', '_')) + } + + { // reverse so it isn't upside down .. + recipe.layout = recipe.layout.reverse(); + recipe.layout.forEach((layer, i) => { + // .. and flip so it isn't mirrored + recipe.layout[i] = layer.reverse(); + }) + } + + let entry = { + "name": recipe.name, + "icon": `masterfulmachinery:${recipe.controllerId}_controller`, + "category": "structures", + "pages": [ + { + "type": "text", + "text": recipe.name + }, + { + "type": "multiblock", + "name": recipe.name, + "multiblock": { + "pattern": recipe.layout, + "mapping": mapping, + } + } + ] + } + + + fs.writeFile(`patchouli_books/masterful_machinery/en_us/entries/structures/${file}`, JSON.stringify(entry), () => {}) + }) + }); +}); diff --git a/patchouli_books/masterful_machinery/book.json b/patchouli_books/masterful_machinery/book.json new file mode 100644 index 0000000000..ad31988482 --- /dev/null +++ b/patchouli_books/masterful_machinery/book.json @@ -0,0 +1,6 @@ +{ + "name": "Masterful Machinery", + "landing_text": "Problems forming your multiblock? look no further.", + "version": 1, + "model": "patchouli:book_blue" +} diff --git a/patchouli_books/masterful_machinery/en_us/categories/structures.json b/patchouli_books/masterful_machinery/en_us/categories/structures.json new file mode 100644 index 0000000000..c198fb9e53 --- /dev/null +++ b/patchouli_books/masterful_machinery/en_us/categories/structures.json @@ -0,0 +1,5 @@ +{ + "name": "Structures", + "description": "Abandon all hope ye who enter here!", + "icon": "masterfulmachinery:blueprint" +} diff --git a/patchouli_books/masterful_machinery/en_us/entries/structures/.gitignore b/patchouli_books/masterful_machinery/en_us/entries/structures/.gitignore new file mode 100644 index 0000000000..d6b7ef32c8 --- /dev/null +++ b/patchouli_books/masterful_machinery/en_us/entries/structures/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore