UNPKG

redc

Version:

Compiles RED lang into Minecraft schematics

85 lines (84 loc) 2.56 kB
import { WORD_SIZE, NUM_SEGMENTS } from './meta.js'; var UNUSED = 'minecraft:light_gray_stained_glass'; var HIGH = 'minecraft:stone'; var LOW = 'minecraft:glass'; // the axis along which the output is drawn var DIRECTION = 'x'; var AXDX = DIRECTION === 'x' ? 0 : 2; var AXDZ = DIRECTION === 'x' ? 2 : 0; var ALONGDX = DIRECTION === 'x' ? 1 : 0; var ALONGDZ = DIRECTION === 'x' ? 0 : 1; var CORNER = { x: 40, y: 109, z: -29 }; export function toSchematic(bin) { var lines = []; var direction = 'up'; var pos = CORNER; for (var i = 0; i < NUM_SEGMENTS; i++) { switch (i) { case 0: direction = 'right'; break; case 1: direction = 'up'; break; case NUM_SEGMENTS - 1: direction = 'down'; break; case NUM_SEGMENTS / 2 + 1: direction = 'left'; break; } if (i === 0) direction = 'right'; else if (i === 1) direction = 'up'; else if (i === NUM_SEGMENTS - 1) direction = 'down'; else if (i === NUM_SEGMENTS / 2) direction = 'left'; else if (i < NUM_SEGMENTS / 2) { if (i % 2 === 1) direction = 'up'; else if (i % 4 === 0) direction = 'left'; else direction = 'right'; } else { if (i % 2 === 1) direction = 'down'; else if (i % 4 === 0) direction = 'left'; else direction = 'right'; } for (var j = (i === 0 ? 1 : 0); j < 12; j++) { if (!bin[12 * i + j]) { return lines.join('\n'); } for (var k = 0; k < WORD_SIZE; k++) { var v = bin[12 * i + j][k]; lines.push("setblock ".concat(pos.x + AXDX * k, " ").concat(pos.y, " ").concat(pos.z + AXDZ * k, " ").concat(v === '-' ? UNUSED : v === '0' ? LOW : HIGH)); } if (direction === 'up') { pos.y++; } else if (direction === 'down') { pos.y--; } else if (direction === 'left') { pos.x += ALONGDX; pos.z += ALONGDZ; } else if (direction === 'right') { pos.x -= ALONGDX; pos.z -= ALONGDZ; } } } return lines.join('\n'); }