overdrive_that_matters/shapenator.js

231 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const models = [
'android_station',
'battery_bank',
['matter_scanner', 'matter_scanner_working'],
'pattern_storage',
['matter_replicator', 'matter_replicator_working'],
// 'matter_panel',
['matter_decomposer', 'matter_decomposer_working'],
];
const fs = require('fs')
const _root = './src/main/resources/assets/overdrive_that_matters/'
const root_data = './src/main/resources/data/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) {
let model, path
if (Array.isArray(_model)) {
model = _model[0]
path = _model[1]
} else {
model = _model
path = _model
}
fs.writeSync(handle, '\tpublic static final BlockShape ' + model.toUpperCase() + ' = new BlockShape(\n')
const obj = JSON.parse(fs.readFileSync(root + path + '.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', 'matter_decomposer']
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'))
}
}
// дропы с машин
{
const drops = {
android_station: ['energy_cap', 'battery_container'],
battery_bank: ['battery_bank'],
matter_capacitor_bank: ['matter_container'],
matter_panel: ['tasks'],
pattern_storage: ['patterns'],
}
const drops_workers = {
matter_decomposer: ['work_slots', 'matter_capability'],
matter_replicator: ['regular_slots', 'reserved_slots', 'matter_capability'],
matter_scanner: ['work_slots'],
}
const combined = {}
for (const name in drops) {
combined[name] = drops[name]
}
for (const name in drops_workers) {
drops_workers[name].push('work_ticks', 'current_job', 'energy_cap', 'battery_container')
combined[name] = drops_workers[name]
}
for (const name in combined) {
const values = combined[name]
const state = {
type: 'minecraft:block',
pools: [
{
rolls: 1,
bonus_rolls: 0,
entries: [
{
type: 'minecraft:item',
name: "overdrive_that_matters:" + name,
functions: [
{
"function": "minecraft:copy_name",
"source": "block_entity"
},
{
"function": "minecraft:copy_nbt",
"source": "block_entity",
"ops": [
{
"source": "Name",
"target": "BlockEntityTag.Name",
"op": "replace"
}
]
}
]
}
]
}
]
}
for (const type of values) {
state.pools[0].entries[0].functions[1].ops.push({
"source": type,
"target": "BlockEntityTag." + type,
"op": "replace"
})
}
fs.writeFileSync(root_data + 'loot_tables/blocks/' + name + '.json', JSON.stringify(state, null, '\t'))
}
}
process.stdout.write(`Generated data files in ${Date.now() - time}ms\n`)