Skip to content

Commit 0cfb047

Browse files
committed
🐛 Fix rotation limit not being enforced when rotating cubes
1 parent 576831f commit 0cfb047

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/formats/blueprint/index.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,8 @@ export function projectTargetVersionIsAtLeast(version: string): boolean {
377377
return !compareVersions(version, Project!.animated_java.target_minecraft_version)
378378
}
379379

380-
export function shouldEnableRotationLock(): boolean {
381-
if (!activeProjectIsBlueprintFormat()) return false
382-
383-
if (projectTargetVersionIsAtLeast('1.21.6')) {
384-
return false
385-
}
386-
387-
return !(
380+
export function hasNonElementSelection(): boolean {
381+
return (
388382
!!Group.first_selected ||
389383
!!AnimatedJava.TextDisplay.selected.length ||
390384
!!AnimatedJava.VanillaItemDisplay.selected.length ||
@@ -400,20 +394,20 @@ export function shouldEnableRotationLock(): boolean {
400394
)
401395
}
402396

403-
export function updateRotationLock() {
404-
if (!activeProjectIsBlueprintFormat()) return
405-
const format = BLUEPRINT_FORMAT.get()!
406-
// If any of these node types are selected, we disable rotation lock.
407-
format.rotation_limit = shouldEnableRotationLock()
408-
format.rotation_snap = format.rotation_limit
409-
}
410-
411-
export function disableRotationLock() {
397+
export function updateRotationConstraints() {
412398
if (!activeProjectIsBlueprintFormat()) return
413399
const format = BLUEPRINT_FORMAT.get()!
400+
if (!format) {
401+
console.error('Animated Java Blueprint format is not registered!')
402+
return
403+
}
414404

415-
format.rotation_limit = false
416-
format.rotation_snap = false
405+
// Rotation is always limited when selecting an element
406+
format.rotation_limit = !hasNonElementSelection()
407+
if (!projectTargetVersionIsAtLeast('1.21.6') /* < 1.21.6 */) {
408+
// But only snaps to 22.5 degree increments on versions before 1.21.6
409+
format.rotation_snap = format.rotation_limit
410+
}
417411
}
418412

419413
EVENTS.SELECT_PROJECT.subscribe(project => {
@@ -426,13 +420,12 @@ EVENTS.UNSELECT_PROJECT.subscribe(project => {
426420
EVENTS.UNSELECT_AJ_PROJECT.publish(project)
427421
}
428422
})
429-
EVENTS.UPDATE_SELECTION.subscribe(updateRotationLock)
423+
EVENTS.UPDATE_SELECTION.subscribe(updateRotationConstraints)
430424
EVENTS.SELECT_AJ_PROJECT.subscribe(() => {
431425
requestAnimationFrame(() => {
432-
updateRotationLock()
426+
updateRotationConstraints()
433427
})
434428
})
435429
EVENTS.UNSELECT_AJ_PROJECT.subscribe(project => {
436430
if (project.visualBoundingBox) scene.remove(project.visualBoundingBox)
437-
disableRotationLock()
438431
})

0 commit comments

Comments
 (0)