From 3b859e477d92845bd5b612edaf568bce47fb3125 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Mon, 10 Jul 2023 21:18:12 +0200 Subject: [PATCH] Re-center java block/item models when converting Fix rotation issue when converting model with rotation axis restriction Fix actions cannot be added to a menu without path --- js/interface/menu.js | 5 ++--- js/io/format.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/js/interface/menu.js b/js/interface/menu.js index cc9d3fac..0974a717 100644 --- a/js/interface/menu.js +++ b/js/interface/menu.js @@ -545,14 +545,13 @@ class Menu { conditionMet() { return Condition(this.condition); } - addAction(action, path) { + addAction(action, path = '') { if (this.structure instanceof Array == false) return; - if (path === undefined) path = ''; if (typeof path !== 'string') path = path.toString(); let track = path.split('.') function traverse(arr, layer) { - if (track.length === layer || !track[layer] === '' || !isNaN(parseInt(track[layer])) || (track[layer][0] == '#')) { + if (track.length === layer || track[layer] === '' || !isNaN(parseInt(track[layer])) || (track[layer][0] == '#')) { let index = arr.length; if (track[layer] !== '' && track.length !== layer) { if (track[layer].startsWith('#')) { diff --git a/js/io/format.js b/js/io/format.js index 9f799c57..2ebf3b8d 100644 --- a/js/io/format.js +++ b/js/io/format.js @@ -145,6 +145,20 @@ class ModelFormat { group.createUniqueName(); }) } + if (Format.centered_grid != old_format.centered_grid) { + let offset = Format.centered_grid ? -8 : 8; + Cube.all.forEach(cube => { + for (let axis of [0, 2]) { + cube.from[axis] += offset; + cube.to[axis] += offset; + cube.origin[axis] += offset; + } + }) + Group.all.forEach(group => { + group.origin[0] += offset; + group.origin[2] += offset; + }) + } if (!Format.single_texture && old_format.single_texture && Texture.all.length) { let texture = Texture.getDefault(); @@ -195,7 +209,7 @@ class ModelFormat { if (Format.rotation_limit && !old_format.rotation_limit && Format.rotate_cubes) { Cube.all.forEach(cube => { if (!cube.rotation.allEqual(0)) { - var axis = (cube.rotation_axis && getAxisNumber(cube.rotation_axis)) || 0; + var axis = (getAxisNumber(cube.rotationAxis())) || 0; var cube_rotation = Format.rotation_snap ? Math.round(cube.rotation[axis]/22.5)*22.5 : cube.rotation[axis]; var angle = limitNumber( cube_rotation, -45, 45 ); cube.rotation.V3_set(0, 0, 0)