Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Animated Java",
"icon": "icon.svg",
"description": "Effortlessly craft complex animations for Minecraft: Java Edition",
"version": "1.8.0-beta.4",
"version": "1.8.0-beta.5",
"min_blockbench_version": "4.12.0",
"max_blockbench_version": "4.12.6",
"variant": "desktop",
Expand Down
64 changes: 42 additions & 22 deletions src/formats/blueprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ export interface IBlueprintFormatJSON {
collections?: ICollectionJSON[]
}

export function fixCubeRotation(cube: Cube) {
const maxRotation = Math.max(...cube.rotation)
const minRotation = Math.min(...cube.rotation)
if (maxRotation <= 45 && minRotation >= -45) return
// Use the rotation with the largest absolute value
const rotation = Math.abs(maxRotation) >= Math.abs(minRotation) ? maxRotation : minRotation
const axis = cube.rotation.indexOf(rotation)

const previousSelected = Project!.selected_elements
Project!.selected_elements = [cube]
rotateOnAxis(() => rotation, axis, true)
Project!.selected_elements = previousSelected
}

//region > Convert
export function convertToBlueprint() {
// Convert the current project to a Blueprint
Expand All @@ -156,13 +170,19 @@ export function convertToBlueprint() {
group.createUniqueName(Group.all.filter(g => g !== group))
group.sanitizeName()
}

for (const animation of Blockbench.Animation.all) {
animation.createUniqueName(Blockbench.Animation.all.filter(a => a !== animation))
animation.name = sanitizeStorageKey(animation.name)
}

for (const cube of Cube.all) {
cube.setUVMode(false)

fixCubeRotation(cube)
}

Canvas.updateAll()
}

export function getDefaultProjectSettings() {
Expand Down Expand Up @@ -278,6 +298,13 @@ export const BLUEPRINT_FORMAT = registerModelFormat(
component: ProjectTitleSvelte,
props: { pluginMode: project.pluginMode },
})

for (const cube of Cube.all) {
cube.setUVMode(false)
fixCubeRotation(cube)
}

Canvas.updateAll()
})
},

Expand Down Expand Up @@ -353,14 +380,8 @@ export function projectTargetVersionIsAtLeast(version: string): boolean {
return !compareVersions(version, Project!.animated_java.target_minecraft_version)
}

export function shouldEnableRotationLock(): boolean {
if (!activeProjectIsBlueprintFormat()) return false

if (projectTargetVersionIsAtLeast('1.21.6')) {
return false
}

return !(
export function hasNonElementSelection(): boolean {
return (
!!Group.first_selected ||
!!AnimatedJava.TextDisplay.selected.length ||
!!AnimatedJava.VanillaItemDisplay.selected.length ||
Expand All @@ -376,20 +397,20 @@ export function shouldEnableRotationLock(): boolean {
)
}

export function updateRotationLock() {
if (!activeProjectIsBlueprintFormat()) return
const format = BLUEPRINT_FORMAT.get()!
// If any of these node types are selected, we disable rotation lock.
format.rotation_limit = shouldEnableRotationLock()
format.rotation_snap = format.rotation_limit
}

export function disableRotationLock() {
export function updateRotationConstraints() {
if (!activeProjectIsBlueprintFormat()) return
const format = BLUEPRINT_FORMAT.get()!
if (!format) {
console.error('Animated Java Blueprint format is not registered!')
return
}

format.rotation_limit = false
format.rotation_snap = false
// Rotation is always limited when selecting an element
format.rotation_limit = !hasNonElementSelection()
if (!projectTargetVersionIsAtLeast('1.21.6') /* < 1.21.6 */) {
// But only snaps to 22.5 degree increments on versions before 1.21.6
format.rotation_snap = format.rotation_limit
}
}

EVENTS.SELECT_PROJECT.subscribe(project => {
Expand All @@ -402,13 +423,12 @@ EVENTS.UNSELECT_PROJECT.subscribe(project => {
EVENTS.UNSELECT_AJ_PROJECT.publish(project)
}
})
EVENTS.UPDATE_SELECTION.subscribe(updateRotationLock)
EVENTS.UPDATE_SELECTION.subscribe(updateRotationConstraints)
EVENTS.SELECT_AJ_PROJECT.subscribe(() => {
requestAnimationFrame(() => {
updateRotationLock()
updateRotationConstraints()
})
})
EVENTS.UNSELECT_AJ_PROJECT.subscribe(project => {
if (project.visualBoundingBox) scene.remove(project.visualBoundingBox)
disableRotationLock()
})
4 changes: 2 additions & 2 deletions src/interface/dialog/blueprintSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { updateAllCubeOutlines } from 'src/mods/cube'
import { SUPPORTED_MINECRAFT_VERSIONS } from 'src/systems/global'
import BlueprintSettingsDialogSvelteComponent from '../../components/blueprintSettingsDialog.svelte'
import { PACKAGE } from '../../constants'
import { updateRotationLock } from '../../formats/blueprint'
import { updateRotationConstraints } from '../../formats/blueprint'
import { defaultValues, type ExportMode } from '../../formats/blueprint/settings'
import { sanitizeStorageKey } from '../../util/minecraftUtil'
import { Valuable } from '../../util/stores'
Expand Down Expand Up @@ -134,7 +134,7 @@ export function openBlueprintSettingsDialog() {
preventKeybinds: true,
onConfirm() {
setSettings(settings)
updateRotationLock()
updateRotationConstraints()
updateAllCubeOutlines()
Canvas.updateAll()
},
Expand Down
13 changes: 13 additions & 0 deletions src/mods/eventHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ registerPropertyOverrideMod({
}
},
})

registerPropertyOverrideMod({
id: `animated-java:event-hook/pre-select-project-event`,
object: ModelProject.prototype,
key: 'select',

get: original => {
return function (this: ModelProject) {
EVENTS.PRE_SELECT_PROJECT.publish(this)
return original.call(this)
}
},
})
21 changes: 0 additions & 21 deletions src/mods/modelFormatSelectMod.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/pluginPackage/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,5 +404,21 @@
]
}
]
},
"1.8.0-beta.5": {
"title": "v1.8.0-beta.5",
"author": "Titus Evans (SnaveSutit)",
"date": "2025-10-19",
"categories": [
{
"title": "Fixes",
"list": [
"Fixed cube rotations in 1.21.6+ allowing rotation values outside the -45..45 degree range",
"Fixed rotation limits not being enforced when converting to a Blueprint.",
"Fixed rotation limit not being enforced when rotating cubes.",
"Fixed export crash due to invalid tag reference."
]
}
]
}
}
3 changes: 0 additions & 3 deletions src/systems/datapackCompiler/1.20.4/global.mcb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ dir global {

# Removes locators and cameras owned by the rig, even if they're not included in the currently loaded export.
function outdated_rig {
# Assert that the function is being executed as a root entity.
debug assert executed_as_root_entity <%TAGS.GLOBAL_ROOT()%>

execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run block as_data {
data remove storage <%temp_storage%> args
data remove storage <%temp_storage%> uuids
Expand Down
4 changes: 2 additions & 2 deletions src/systems/datapackCompiler/1.20.4/global.mcbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
template debug {
with assert:literal executed_as_root_entity:literal root_tag:literal {
with assert:literal executed_as_root_entity:literal root_tag:js {
IF (debug_mode) {
execute unless entity @s[type=minecraft:item_display,tag=<%root_tag%>] run return run \
tellraw @a <%TELLRAW.FUNCTION_NOT_EXECUTED_AS_ROOT_ERROR(context.functions.at(-1))%>
tellraw @a <%TELLRAW.FUNCTION_NOT_EXECUTED_AS_ROOT_ERROR(context.functions.at(-1), root_tag)%>
}
}
}
3 changes: 0 additions & 3 deletions src/systems/datapackCompiler/1.21.2/global.mcb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ dir global {

# Removes locators and cameras owned by the rig, even if they're not included in the currently loaded export.
function outdated_rig {
# Assert that the function is being executed as a root entity.
debug assert executed_as_root_entity <%TAGS.GLOBAL_ROOT()%>

execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run block as_data {
data remove storage <%temp_storage%> args
data remove storage <%temp_storage%> uuids
Expand Down
3 changes: 0 additions & 3 deletions src/systems/datapackCompiler/1.21.5/global.mcb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ dir global {

# Removes locators and cameras owned by the rig, even if they're not included in the currently loaded export.
function outdated_rig {
# Assert that the function is being executed as a root entity.
debug assert executed_as_root_entity <%TAGS.GLOBAL_ROOT()%>

execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run block as_data {
data remove storage <%temp_storage%> args
data remove storage <%temp_storage%> uuids
Expand Down
7 changes: 2 additions & 5 deletions src/systems/datapackCompiler/tellraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { toSmallCaps } from 'src/util/minecraftUtil'
import { type IRenderedAnimation } from '../animationRenderer'
import { JsonText, TextElement } from '../jsonText'
import { type IRenderedVariant } from '../rigRenderer'
import { TAGS } from './tags'

const TELLRAW_PREFIX = () =>
new JsonText([
Expand Down Expand Up @@ -120,12 +119,10 @@ namespace TELLRAW {
.toString()
.replaceAll('\\n', '\\\\n')

export const FUNCTION_NOT_EXECUTED_AS_ROOT_ERROR = (functionPath: string) => {
export const FUNCTION_NOT_EXECUTED_AS_ROOT_ERROR = (functionPath: string, tag: string) => {
const hoverText = new JsonText([{ text: functionPath, color: 'yellow' }, '']).flatten()

const exampleCommand = `/execute as @e[tag=${TAGS.PROJECT_ROOT(
Project!.animated_java.export_namespace
)}] run function ${functionPath}`
const exampleCommand = `/execute as @e[tag=${tag}] run function ${functionPath}`

return TELLRAW_ERROR('Function Not Executed as Root Entity', [
!compareVersions('1.21.5', Project!.animated_java.target_minecraft_version)
Expand Down
6 changes: 5 additions & 1 deletion src/systems/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ export function isCubeValid(cube: Cube): '1.21.6+' | 'valid' | 'invalid' {
totalRotation === cube.rotation[1] ||
totalRotation === cube.rotation[2]

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

const isRotationInAllowedSteps =
totalRotation === -45 ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"meta": {
"format": "animated-java:format/blueprint",
"format_version": "1.8.0-beta.3",
"format_version": "1.8.0-beta.4",
"uuid": "167b27cd-b559-3f13-a97c-0841fe21f1d1",
"save_location": "D:\\github-repos\\animated-java\\old-animated-java\\test-packs\\latest\\blueprints\\armor_stand_latest.ajblueprint",
"last_used_export_namespace": "armor_stand"
Expand Down