144 lines
3.4 KiB
JavaScript
144 lines
3.4 KiB
JavaScript
|
|
const models = [
|
|
'android_station',
|
|
'battery_bank',
|
|
'matter_scanner',
|
|
'pattern_storage',
|
|
'matter_replicator',
|
|
// 'matter_panel',
|
|
'matter_decomposer',
|
|
];
|
|
|
|
const fs = require('fs')
|
|
const _root = './src/main/resources/assets/overdrive_that_matters/'
|
|
const root = _root + 'models/block/'
|
|
|
|
const time = Date.now()
|
|
process.stdout.write('Generating data files\n')
|
|
const handle = fs.openSync('./src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java', 'w')
|
|
|
|
fs.writeSync(handle, 'package ru.dbotthepony.mc.otm.shapes;\n\n\n')
|
|
fs.writeSync(handle, `// This file is regenerated on each gradle run. Do not edit it!\n`)
|
|
fs.writeSync(handle, 'public class BlockShapes {\n')
|
|
|
|
for (const model of models) {
|
|
fs.writeSync(handle, '\tpublic static final BlockShape ' + model.toUpperCase() + ' = new BlockShape(\n')
|
|
|
|
const obj = JSON.parse(fs.readFileSync(root + model + '.json', {encoding: 'utf-8'}))
|
|
let first = true
|
|
|
|
for (const elementID in obj.elements) {
|
|
const element = obj.elements[elementID]
|
|
|
|
if (element.rotation)
|
|
continue;
|
|
|
|
const from = element.from
|
|
const to = element.to
|
|
|
|
if (first) {
|
|
first = false
|
|
} else {
|
|
fs.writeSync(handle, ',\n')
|
|
}
|
|
|
|
fs.writeSync(handle, `\t\tnew SimpleCuboid(${from[0] / 16}d, ${from[1] / 16}d, ${from[2] / 16}d, ${to[0] / 16}d, ${to[1] / 16}d, ${to[2] / 16}d)`)
|
|
}
|
|
|
|
fs.writeSync(handle, '\n\t);\n\n')
|
|
}
|
|
|
|
fs.writeSync(handle, '}')
|
|
fs.closeSync(handle)
|
|
|
|
const facings = [
|
|
{facing: "north", y: 0},
|
|
{facing: "south", y: 180},
|
|
{facing: "west", y: 270},
|
|
{facing: "east", y: 90},
|
|
]
|
|
|
|
// генерируем 6 моделей паттернов
|
|
{
|
|
const pattern_storage_pattern = JSON.parse(fs.readFileSync(root + 'pattern/pattern_storage_pattern.json'))
|
|
|
|
const pattern_list = ['overdrive_that_matters:block/pattern/pattern_storage_pattern'];
|
|
|
|
for (let i = 0; i < 7; i++) {
|
|
pattern_storage_pattern.elements[0].from[0] -= 2
|
|
pattern_storage_pattern.elements[0].to[0] -= 2
|
|
|
|
fs.writeFileSync(root + 'pattern/pattern_storage_pattern' + i + '.json', JSON.stringify(pattern_storage_pattern, null, '\t'))
|
|
pattern_list.push('overdrive_that_matters:block/pattern/pattern_storage_pattern' + i)
|
|
}
|
|
|
|
const base_model = 'overdrive_that_matters:block/pattern_storage'
|
|
|
|
const blockstate = {
|
|
multipart: []
|
|
}
|
|
|
|
for (const face of facings) {
|
|
blockstate.multipart.push({
|
|
when: {
|
|
facing: face.facing
|
|
},
|
|
|
|
apply: {
|
|
model: base_model,
|
|
y: face.y ? face.y : undefined
|
|
}
|
|
});
|
|
}
|
|
|
|
for (let i = 0; i < 8; i++) {
|
|
for (const face of facings) {
|
|
blockstate.multipart.push({
|
|
when: {
|
|
facing: face.facing,
|
|
["disk_" + i]: true
|
|
},
|
|
|
|
apply: {
|
|
model: pattern_list[i],
|
|
y: face.y ? face.y : undefined
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
fs.writeFileSync(_root + 'blockstates/pattern_storage.json', JSON.stringify(blockstate, null, '\t'))
|
|
}
|
|
|
|
// Matter scanner
|
|
{
|
|
const to_generate = ['matter_scanner', 'matter_replicator']
|
|
const states = ['idle', 'working', 'error']
|
|
|
|
for (const machine of to_generate) {
|
|
const blockstate = {
|
|
multipart: []
|
|
}
|
|
|
|
for (const face of facings) {
|
|
for (const state of states) {
|
|
blockstate.multipart.push({
|
|
when: {
|
|
facing: face.facing,
|
|
worker: state
|
|
},
|
|
|
|
apply: {
|
|
model: 'overdrive_that_matters:block/' + machine + '_' + state,
|
|
y: face.y ? face.y : undefined
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
fs.writeFileSync(_root + 'blockstates/' + machine + '.json', JSON.stringify(blockstate, null, '\t'))
|
|
}
|
|
}
|
|
|
|
process.stdout.write(`Generated data files in ${Date.now() - time}ms\n`)
|