This commit is contained in:
Roni Lehto 2021-08-21 16:36:07 +03:00
commit 48f1b43d28
3 changed files with 92 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules/
out/
schematics/
.git/
package-lock.json

73
index.js Normal file
View File

@ -0,0 +1,73 @@
/* _ _ ____ ___ _ _ ____ _ _
( \/ )/ ___) / __)/ )( \( __)( \/ )
) ( \___ \( (__ ) __ ( ) _) / \/ \
(_/\_)(____/ \___)\_)(_/(____)\_)(_/ */
const fs = require('fs');
const path = require('path');
if (!fs.existsSync('out')) fs.mkdirSync('out');
if (!fs.existsSync('schematics')) fs.mkdirSync('schematics');
const { Schematic } = require('prismarine-schematic');
const { Vec3 } = require('vec3');
const fileList = fs.readdirSync('schematics');
if (fileList.length == 0) {
console.error('No files to be converted found in ./schematics/');
process.exit(1);
}
const f = () => {
if (fileList.length == 0) {
console.log('All done!');
return;
}
const schemFile = fileList[0];
const schemFilePath = path.join('schematics', schemFile);
const blockMap = new Map();
console.log(`Converting ${schemFile}`);
Schematic.read(fs.readFileSync(schemFilePath)).then((schem) => {
schem.makeWithCommands(new Vec3(-3, 0, 0)).then((commands) => {
for (const cmd of commands) {
const pts = cmd.split(' ');
const x = parseInt(pts[1]);
const y = parseInt(pts[2]);
const z = parseInt(pts[3]);
const blockData = pts.slice(4).join(' ');
//.replace('persistent="true"', 'persistent="false"')
//.replace('distance="7"', 'distance="1"')
if (blockData == 'air') continue;
if (!blockMap.has(blockData)) blockMap.set(blockData, []);
blockMap.get(blockData).push(...[x, y, z]);
}
fs.writeFileSync(path.join('out', schemFile.replace('.schem', '.json')), JSON.stringify([...blockMap]), 'utf8');
console.log(`${schemFile} done`);
fileList.splice(0, 1);
setTimeout(f, 0);
}).catch(console.error);
}).catch((err) => {
console.error(err);
process.exit(1);
});
}
f();

14
package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "xschem",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"prismarine-schematic": "^1.2.1"
}
}