Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patchouli book for masterful machinery #4839

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions automation/nodejs/export-mm-to-patchouli.js
Original file line number Diff line number Diff line change
@@ -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), () => {})
})
});
});
6 changes: 6 additions & 0 deletions patchouli_books/masterful_machinery/book.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Masterful Machinery",
"landing_text": "Problems forming your multiblock? look no further.",
"version": 1,
"model": "patchouli:book_blue"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Structures",
"description": "Abandon all hope ye who enter here!",
"icon": "masterfulmachinery:blueprint"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore