Skip to content

Commit 576831f

Browse files
committed
πŸ› Fix cube rotations in 1.21.6+ allowing rotation values outside the -45..45 degree range
1 parent b968422 commit 576831f

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

β€Žsrc/formats/blueprint/index.tsβ€Ž

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,23 @@ export interface IBlueprintFormatJSON {
146146
collections?: ICollectionJSON[]
147147
}
148148

149+
export function fixCubeRotation(cube: Cube) {
150+
const maxRotation = Math.max(...cube.rotation)
151+
const minRotation = Math.min(...cube.rotation)
152+
if (maxRotation <= 45 && minRotation >= -45) {
153+
console.log('Cube rotation is fine, no need to fix', cube.rotation)
154+
return
155+
}
156+
// Use the rotation with the largest absolute value
157+
const rotation = Math.abs(maxRotation) >= Math.abs(minRotation) ? maxRotation : minRotation
158+
const axis = cube.rotation.indexOf(rotation)
159+
160+
const previousSelected = Project!.selected_elements
161+
Project!.selected_elements = [cube]
162+
rotateOnAxis(() => rotation, axis, true)
163+
Project!.selected_elements = previousSelected
164+
}
165+
149166
//region > Convert
150167
export function convertToBlueprint() {
151168
// Convert the current project to a Blueprint
@@ -278,6 +295,13 @@ export const BLUEPRINT_FORMAT = registerModelFormat(
278295
component: ProjectTitleSvelte,
279296
props: { pluginMode: project.pluginMode },
280297
})
298+
299+
for (const cube of Cube.all) {
300+
cube.setUVMode(false)
301+
fixCubeRotation(cube)
302+
}
303+
304+
Canvas.updateAll()
281305
})
282306
},
283307

β€Žsrc/interface/dialog/blueprintSettings.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { updateAllCubeOutlines } from 'src/mods/cube'
33
import { SUPPORTED_MINECRAFT_VERSIONS } from 'src/systems/global'
44
import BlueprintSettingsDialogSvelteComponent from '../../components/blueprintSettingsDialog.svelte'
55
import { PACKAGE } from '../../constants'
6-
import { updateRotationLock } from '../../formats/blueprint'
6+
import { updateRotationConstraints } from '../../formats/blueprint'
77
import { defaultValues, type ExportMode } from '../../formats/blueprint/settings'
88
import { sanitizeStorageKey } from '../../util/minecraftUtil'
99
import { Valuable } from '../../util/stores'
@@ -134,7 +134,7 @@ export function openBlueprintSettingsDialog() {
134134
preventKeybinds: true,
135135
onConfirm() {
136136
setSettings(settings)
137-
updateRotationLock()
137+
updateRotationConstraints()
138138
updateAllCubeOutlines()
139139
Canvas.updateAll()
140140
},

β€Žsrc/systems/util.tsβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ export function isCubeValid(cube: Cube): '1.21.6+' | 'valid' | 'invalid' {
102102
totalRotation === cube.rotation[1] ||
103103
totalRotation === cube.rotation[2]
104104

105-
if (isSingleAxisRotation && projectTargetVersionIsAtLeast('1.21.6')) return '1.21.6+'
105+
if (isSingleAxisRotation && projectTargetVersionIsAtLeast('1.21.6')) {
106+
// Rotation values still need to be within -45 and 45 degrees
107+
if (totalRotation <= 45 && totalRotation >= -45) return '1.21.6+'
108+
else return 'invalid'
109+
}
106110

107111
const isRotationInAllowedSteps =
108112
totalRotation === -45 ||

0 commit comments

Comments
Β (0)