Skip to content

Commit efdc207

Browse files
committed
🚧 Prevent exporting with invalid rotations.
- Added a dialog and exception for exporting a blueprint with invalid cube rotations.
1 parent fac53dc commit efdc207

File tree

5 files changed

+55
-29
lines changed

5 files changed

+55
-29
lines changed

src/lang/en.yml

+6
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ animated_java.misc.failed_to_export.custom_models.message: You have disabled res
583583
animated_java.misc.failed_to_export.blueprint_settings.message: There are errors in your blueprint settings! Please fix them before exporting.
584584
animated_java.misc.failed_to_export.blueprint_settings.error_item: 'Found an issue with {0}:'
585585
animated_java.misc.failed_to_export.button: Ok
586+
misc.failed_to_export.invalid_rotation.message: |-
587+
Some cubes in your model have an invalid rotations.
588+
Cubes must have a rotation of -45, -22.5, 0, 22.5, or 45 degrees, and can only be rotated on a single axis at a time.
589+
If you want to rotate a cube more precisely, or on multiple axes, you must put it into a bone and rotate the bone instead.
590+
All of the invalid cubes are outlined in red in the editor.
591+
Please fix these issues before exporting.
586592
587593
# Format Category
588594
animated_java.format_category.animated_java: Animated Java

src/mods/cubeOutlineMod.ts

+1-29
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,11 @@
11
import { isCurrentFormat } from '../blueprintFormat'
22
import { PACKAGE } from '../constants'
3+
import { isCubeValid } from '../systems/util'
34
import { createBlockbenchMod, createPropertySubscribable } from '../util/moddingTools'
45

56
const ERROR_OUTLINE_MATERIAL = Canvas.outlineMaterial.clone()
67
ERROR_OUTLINE_MATERIAL.color.set('#ff0000')
78

8-
function isCubeValid(cube: Cube) {
9-
// Cube is automatically valid if it has no rotation
10-
if (cube.rotation[0] === 0 && cube.rotation[1] === 0 && cube.rotation[2] === 0) {
11-
return true
12-
}
13-
const rotation = cube.rotation[0] + cube.rotation[1] + cube.rotation[2]
14-
// prettier-ignore
15-
if (
16-
// Make sure the cube is rotated in only one axis by adding all the rotations together, and checking if the sum is equal to one of the rotations.
17-
(
18-
rotation === cube.rotation[0] ||
19-
rotation === cube.rotation[1] ||
20-
rotation === cube.rotation[2]
21-
)
22-
&&
23-
// Make sure the cube is rotated in one of the allowed 22.5 degree increments
24-
(
25-
rotation === -45 ||
26-
rotation === -22.5 ||
27-
rotation === 0 ||
28-
rotation === 22.5 ||
29-
rotation === 45
30-
)
31-
) {
32-
return true
33-
}
34-
return false
35-
}
36-
379
createBlockbenchMod(
3810
`${PACKAGE.name}:cubeOutlineMod`,
3911
{

src/systems/datapackCompiler/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ async function createAnimationStorage(rig: IRenderedRig, animations: IRenderedAn
526526
frames.set(i.toString(), thisFrame)
527527
for (const [uuid, node] of Object.entries(animation.modified_nodes)) {
528528
const transform = frame.node_transforms[uuid]
529+
if (!transform) {
530+
console.warn('No transform found for node:', node)
531+
continue
532+
}
529533
if (BONE_TYPES.includes(node.type)) {
530534
thisFrame.set(
531535
node.type + '_' + node.safe_name,

src/systems/exporter.ts

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import datapackCompiler from './datapackCompiler'
1212
import { exportJSON } from './jsonCompiler'
1313
import resourcepackCompiler from './resourcepackCompiler'
1414
import { renderRig, hashRig } from './rigRenderer'
15+
import { isCubeValid } from './util'
1516

1617
export class IntentionalExportError extends Error {}
1718

@@ -152,6 +153,20 @@ async function actuallyExportProject(forceSave = true) {
152153

153154
export async function exportProject(forceSave = true) {
154155
if (!Project) return // TODO: Handle this error better
156+
157+
if (
158+
// Check if 1.21.3 is newer than the target version
159+
compareVersions('1.21.3', Project.animated_java.target_minecraft_version) &&
160+
!Cube.all.allAre(c => isCubeValid(c))
161+
) {
162+
Blockbench.showMessageBox({
163+
title: translate('misc.failed_to_export.title'),
164+
message: translate('misc.failed_to_export.invalid_rotation.message'),
165+
buttons: [translate('misc.failed_to_export.button')],
166+
})
167+
return
168+
}
169+
155170
blueprintSettingErrors.set({})
156171
const settingsDialog = openBlueprintSettingsDialog()!
157172
// Wait for the dialog to open

src/systems/util.ts

+29
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,32 @@ export const unzip = (data: Uint8Array, options: AsyncUnzipOptions) => {
7979
})
8080
})
8181
}
82+
83+
export function isCubeValid(cube: Cube) {
84+
// Cube is automatically valid if it has no rotation
85+
if (cube.rotation[0] === 0 && cube.rotation[1] === 0 && cube.rotation[2] === 0) {
86+
return true
87+
}
88+
const rotation = cube.rotation[0] + cube.rotation[1] + cube.rotation[2]
89+
// prettier-ignore
90+
if (
91+
// Make sure the cube is rotated in only one axis by adding all the rotations together, and checking if the sum is equal to one of the rotations.
92+
(
93+
rotation === cube.rotation[0] ||
94+
rotation === cube.rotation[1] ||
95+
rotation === cube.rotation[2]
96+
)
97+
&&
98+
// Make sure the cube is rotated in one of the allowed 22.5 degree increments
99+
(
100+
rotation === -45 ||
101+
rotation === -22.5 ||
102+
rotation === 0 ||
103+
rotation === 22.5 ||
104+
rotation === 45
105+
)
106+
) {
107+
return true
108+
}
109+
return false
110+
}

0 commit comments

Comments
 (0)