From f3600b1f8f5f40664421088a7c1134edc6da0c07 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 9 Jan 2022 14:15:22 +0700 Subject: [PATCH] Bring back shapegen, this time as command line tool, update blackhole model --- .gitignore | 2 + shapegen.js | 60 +++++++++++++++++++ .../mc/otm/shapes/BlockShapes.java | 45 +++----------- .../models/block/black_hole.json | 2 +- 4 files changed, 71 insertions(+), 38 deletions(-) create mode 100644 shapegen.js diff --git a/.gitignore b/.gitignore index d478a737d..a154f79d1 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ logs/ # Files from Forge MDK forge*changelog.txt + +shapegen_output.java diff --git a/shapegen.js b/shapegen.js new file mode 100644 index 000000000..3aab97d5d --- /dev/null +++ b/shapegen.js @@ -0,0 +1,60 @@ + +// генерирует код для форм блоков из json моделей + +const fs = require('fs') +const root_main = './src/main/resources/assets/overdrive_that_matters/models/block/' +const root_datagen = './src/data/resources/assets/overdrive_that_matters/models/block/' + +const handle = fs.openSync('./shapegen_output.java', 'w') +const args = process.argv.slice(2) + +if (args.length == 0) { + console.error('No model(s) names specified.') + process.exit(2) +} + +for (const model of args) { + fs.writeSync(handle, 'public static final BlockShape ' + model.toUpperCase() + ' = new BlockShape(\n') + + let readData + + try { + readData = fs.readFileSync(root_main + model + '.json', {encoding: 'utf-8'}) + } catch(err1) { + try { + readData = fs.readFileSync(root_datagen + model + '.json', {encoding: 'utf-8'}) + } catch(err2) { + console.error('Unable to read model file in either of locations') + console.error(err1) + console.error(err2) + process.exit(1) + } + } + + const obj = JSON.parse(readData) + 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, `\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)`) + } + + console.log(`Parsed and generated shape of ${model}.json`) + + fs.writeSync(handle, '\n);\n\n') +} + +fs.closeSync(handle) diff --git a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java index a126b0911..7f52bf43c 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java +++ b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java @@ -1,7 +1,5 @@ package ru.dbotthepony.mc.otm.shapes; - -// This file is regenerated on each gradle run. Do not edit it! public class BlockShapes { public static final BlockShape ANDROID_STATION = new BlockShape( new SimpleCuboid(0d, 0.4375d, 0d, 1d, 0.5625d, 1d), @@ -30,39 +28,13 @@ public class BlockShapes { ); public static final BlockShape BLACK_HOLE = new BlockShape( - new SimpleCuboid(0.5d, 0.46875d, 0.5d, 0.515625d, 0.484375d, 0.515625d), - new SimpleCuboid(0.484375d, 0.484375d, 0.484375d, 0.5d, 0.5d, 0.5d), - new SimpleCuboid(0.484375d, 0.484375d, 0.5d, 0.5d, 0.5d, 0.515625d), - new SimpleCuboid(0.484375d, 0.484375d, 0.515625d, 0.5d, 0.5d, 0.53125d), - new SimpleCuboid(0.5d, 0.484375d, 0.484375d, 0.515625d, 0.5d, 0.5d), - new SimpleCuboid(0.5d, 0.484375d, 0.5d, 0.515625d, 0.5d, 0.515625d), - new SimpleCuboid(0.5d, 0.484375d, 0.515625d, 0.515625d, 0.5d, 0.53125d), - new SimpleCuboid(0.515625d, 0.484375d, 0.484375d, 0.53125d, 0.5d, 0.5d), - new SimpleCuboid(0.515625d, 0.484375d, 0.5d, 0.53125d, 0.5d, 0.515625d), - new SimpleCuboid(0.515625d, 0.484375d, 0.515625d, 0.53125d, 0.5d, 0.53125d), - new SimpleCuboid(0.46875d, 0.5d, 0.5d, 0.484375d, 0.515625d, 0.515625d), - new SimpleCuboid(0.484375d, 0.5d, 0.484375d, 0.5d, 0.515625d, 0.5d), - new SimpleCuboid(0.484375d, 0.5d, 0.5d, 0.5d, 0.515625d, 0.515625d), - new SimpleCuboid(0.484375d, 0.5d, 0.515625d, 0.5d, 0.515625d, 0.53125d), - new SimpleCuboid(0.5d, 0.5d, 0.46875d, 0.515625d, 0.515625d, 0.484375d), - new SimpleCuboid(0.5d, 0.5d, 0.484375d, 0.515625d, 0.515625d, 0.5d), - new SimpleCuboid(0.5d, 0.5d, 0.5d, 0.515625d, 0.515625d, 0.515625d), - new SimpleCuboid(0.5d, 0.5d, 0.515625d, 0.515625d, 0.515625d, 0.53125d), - new SimpleCuboid(0.5d, 0.5d, 0.53125d, 0.515625d, 0.515625d, 0.546875d), - new SimpleCuboid(0.515625d, 0.5d, 0.484375d, 0.53125d, 0.515625d, 0.5d), - new SimpleCuboid(0.515625d, 0.5d, 0.5d, 0.53125d, 0.515625d, 0.515625d), - new SimpleCuboid(0.515625d, 0.5d, 0.515625d, 0.53125d, 0.515625d, 0.53125d), - new SimpleCuboid(0.53125d, 0.5d, 0.5d, 0.546875d, 0.515625d, 0.515625d), - new SimpleCuboid(0.484375d, 0.515625d, 0.484375d, 0.5d, 0.53125d, 0.5d), - new SimpleCuboid(0.484375d, 0.515625d, 0.5d, 0.5d, 0.53125d, 0.515625d), - new SimpleCuboid(0.484375d, 0.515625d, 0.515625d, 0.5d, 0.53125d, 0.53125d), - new SimpleCuboid(0.5d, 0.515625d, 0.484375d, 0.515625d, 0.53125d, 0.5d), - new SimpleCuboid(0.5d, 0.515625d, 0.5d, 0.515625d, 0.53125d, 0.515625d), - new SimpleCuboid(0.5d, 0.515625d, 0.515625d, 0.515625d, 0.53125d, 0.53125d), - new SimpleCuboid(0.515625d, 0.515625d, 0.484375d, 0.53125d, 0.53125d, 0.5d), - new SimpleCuboid(0.515625d, 0.515625d, 0.5d, 0.53125d, 0.53125d, 0.515625d), - new SimpleCuboid(0.515625d, 0.515625d, 0.515625d, 0.53125d, 0.53125d, 0.53125d), - new SimpleCuboid(0.5d, 0.53125d, 0.5d, 0.515625d, 0.546875d, 0.515625d) + new SimpleCuboid(0.4375d, 0.4375d, 0.375d, 0.625d, 0.625d, 0.5625d), + new SimpleCuboid(0.5d, 0.5d, 0.3125d, 0.5625d, 0.5625d, 0.375d), + new SimpleCuboid(0.625d, 0.5d, 0.4375d, 0.6875d, 0.5625d, 0.5d), + new SimpleCuboid(0.5d, 0.5d, 0.5625d, 0.5625d, 0.5625d, 0.625d), + new SimpleCuboid(0.375d, 0.5d, 0.4375d, 0.4375d, 0.5625d, 0.5d), + new SimpleCuboid(0.5d, 0.625d, 0.4375d, 0.5625d, 0.6875d, 0.5d), + new SimpleCuboid(0.5d, 0.375d, 0.4375d, 0.5625d, 0.4375d, 0.5d) ); public static final BlockShape MATTER_SCANNER = new BlockShape( @@ -197,5 +169,4 @@ public class BlockShapes { new SimpleCuboid(0.875d, 0.125d, 0.8125d, 0.9375d, 0.875d, 0.9375d), new SimpleCuboid(0.875d, 0.125d, 0.5d, 0.9375d, 0.875d, 0.625d) ); - -} \ No newline at end of file +} diff --git a/src/main/resources/assets/overdrive_that_matters/models/block/black_hole.json b/src/main/resources/assets/overdrive_that_matters/models/block/black_hole.json index 3d2ccffc0..91e7029ab 100644 --- a/src/main/resources/assets/overdrive_that_matters/models/block/black_hole.json +++ b/src/main/resources/assets/overdrive_that_matters/models/block/black_hole.json @@ -95,5 +95,5 @@ "down": {"uv": [3, 1, 2, 2], "texture": "#black_hole"} } } - ], + ] } \ No newline at end of file