Skip to content

Commit ea4cf39

Browse files
committed
🐛 Fix references to old commands keyframes
1 parent d4cdb30 commit ea4cf39

File tree

3 files changed

+46
-69
lines changed

3 files changed

+46
-69
lines changed

src/systems/animationRenderer.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export interface IRenderedFrame {
7575
/** The condition to check before applying variants */
7676
variants_execute_condition?: string
7777
/** A mcfunction to run as the root on this frame. (Supports MCB syntax) */
78-
commands?: string
79-
/** The condition to check before running commands */
80-
commands_execute_condition?: string
78+
function?: string
79+
/** The condition to check before running the function */
80+
function_execute_condition?: string
8181
}
8282

8383
export interface IRenderedAnimation {
@@ -119,7 +119,7 @@ export function getFrame(
119119
time,
120120
node_transforms: {},
121121
...getVariantKeyframe(animation, time),
122-
...getCommandsKeyframe(animation, time),
122+
...getFunctionKeyframe(animation, time),
123123
}
124124

125125
if (lastAnimation !== animation) {
@@ -264,17 +264,17 @@ function getVariantKeyframe(
264264
return {}
265265
}
266266

267-
function getCommandsKeyframe(
267+
function getFunctionKeyframe(
268268
animation: _Animation,
269269
time: number
270-
): Pick<IRenderedFrame, 'commands' | 'commands_execute_condition'> {
271-
const commandsKeyframes = animation.animators.effects?.commands as _Keyframe[]
272-
if (commandsKeyframes) {
273-
const kf = commandsKeyframes.find(kf => kf.time === time)
270+
): Pick<IRenderedFrame, 'function' | 'function_execute_condition'> {
271+
const functionKeyframes = animation.animators.effects?.function as _Keyframe[]
272+
if (functionKeyframes) {
273+
const kf = functionKeyframes.find(kf => kf.time === time)
274274
if (kf) {
275275
return scrubUndefined({
276-
commands: kf.function?.trim(),
277-
commands_execute_condition: kf.execute_condition?.trim(),
276+
function: kf.function?.trim(),
277+
function_execute_condition: kf.execute_condition?.trim(),
278278
})
279279
}
280280
}
@@ -360,9 +360,9 @@ export function hashAnimations(animations: IRenderedAnimation[]) {
360360
if (frame.variants_execute_condition)
361361
hash.update(';' + frame.variants_execute_condition)
362362
}
363-
if (frame.commands) hash.update(';' + frame.commands)
364-
if (frame.commands_execute_condition)
365-
hash.update(';' + frame.commands_execute_condition)
363+
if (frame.function) hash.update(';' + frame.function)
364+
if (frame.function_execute_condition)
365+
hash.update(';' + frame.function_execute_condition)
366366
}
367367
}
368368
return hash.digest('hex')

src/systems/datapackCompiler/1.20.4/animation.mcb

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dir root {
3434
function on_tick {
3535
execute unless entity @s[tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return 0
3636

37-
# Custom pre-tick commands
37+
# Custom pre-tick function
3838
IF (on_pre_tick_function) {
3939
<%%
4040
emit.mcb(on_pre_tick_function)
@@ -70,7 +70,7 @@ dir root {
7070
execute on passengers run tp @s ~ ~ ~ ~ ~
7171
}
7272

73-
# Custom post-tick commands
73+
# Custom post-tick function
7474
IF (on_post_tick_function) {
7575
<%%
7676
emit.mcb(on_post_tick_function)
@@ -95,19 +95,19 @@ dir root {
9595
execute on passengers run tp @s ~ ~ ~ ~ ~
9696
}
9797

98-
IF (locator.config?.ticking_commands) {
98+
IF (locator.config?.on_tick_function) {
9999
<%%
100-
emit.mcb(locator.config.ticking_commands)
100+
emit.mcb(locator.config.on_tick_function)
101101
%%>
102102
}
103103
}
104-
} ELSE IF (locator.config?.ticking_commands) {
104+
} ELSE IF (locator.config?.on_tick_function) {
105105
$execute \
106106
positioned ^$(px) ^$(py) ^$(pz) \
107107
rotated ~$(ry) ~$(rx) \
108108
run block at_locator_<%locator.storage_name%> {
109109
<%%
110-
emit.mcb(locator.config.ticking_commands)
110+
emit.mcb(locator.config.on_tick_function)
111111
%%>
112112
}
113113
}
@@ -242,9 +242,9 @@ dir animations {
242242
data modify entity @s interpolation_duration set value <%interpolation_duration%>
243243
# Animation logic
244244
IF (animation.loop_mode === 'loop' && animation.loop_delay === 0) {
245-
# Makes sure commands keyframes in the last frame of the animation are activated.
245+
# Makes sure function keyframes in the last frame of the animation are activated.
246246
execute if score @s <%OBJECTIVES.FRAME(animation.storage_name)%> matches -1 run \
247-
block commands_keyframe_loop_patch {
247+
block function_keyframe_loop_patch {
248248
function ./apply_frame {frame: <%animation.duration-1%>}
249249
scoreboard players add @s <%OBJECTIVES.FRAME(animation.storage_name)%> 1
250250
}
@@ -311,13 +311,6 @@ dir animations {
311311
}
312312
}
313313

314-
# IF (!auto_update_rig_orientation && (has_locators || has_cameras)) {
315-
# execute \
316-
# on passengers \
317-
# if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] \
318-
# run function ./on_tick/transform_floating_entities
319-
# }
320-
321314
return 1
322315
}
323316
} ELSE {
@@ -330,13 +323,6 @@ dir animations {
330323
execute on passengers if entity @s[tag=!<%TAGS.GLOBAL_DATA()%>] run \
331324
data modify entity @s start_interpolation set value -1
332325

333-
# IF (!auto_update_rig_orientation && (has_locators || has_cameras)) {
334-
# execute \
335-
# on passengers \
336-
# if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] \
337-
# run function ./on_tick/transform_floating_entities
338-
# }
339-
340326
return 1
341327
}
342328

@@ -345,13 +331,6 @@ dir animations {
345331
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run \
346332
function ./frames/$(frame) with entity @s data.uuids_by_name
347333

348-
# IF (!auto_update_rig_orientation && (has_locators || has_cameras)) {
349-
# execute \
350-
# on passengers \
351-
# if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] \
352-
# run function ./on_tick/transform_floating_entities
353-
# }
354-
355334
return 1
356335
}
357336

@@ -361,7 +340,7 @@ dir animations {
361340
// A record of node uuid to INodeTransform.
362341
// Keeps track of the last time a bone was updated.
363342
// Only used for step keyframe interpolation.
364-
let hasCommands = false
343+
let hasFunction = false
365344
const lastActiveFrame = {}
366345
const modifiedNodes = Object.values(animation.modified_nodes).filter(n => n.type !== 'struct').sort(nodeSorter);
367346
for (const [frameIndex, frame] of animation.frames.entries()) {
@@ -395,7 +374,7 @@ dir animations {
395374
+ `interpolation_duration: ${interpolation_duration}`
396375
+ `}`
397376
}
398-
;hasCommands = true
377+
;hasFunction = true
399378
break
400379
}
401380
case 'locator': {
@@ -411,25 +390,25 @@ dir animations {
411390
};
412391
}
413392

414-
if (transform.commands) {
393+
if (transform.function) {
415394
if (node.config?.use_entity) {
416395
frameFunc +=
417396
`\n$execute on vehicle unless entity @s[tag=${TAGS.TRANSFORMS_ONLY()}] as $(${node.type + '_' + node.storage_name}) `
418397
+ `positioned ^${roundTo(transform.pos[0], 10)} ^${roundTo(transform.pos[1], 10)} ^${roundTo(transform.pos[2], 10)} `
419398
+ `rotated ~${roundTo(transform.head_rot[1], 10)} ~${roundTo(transform.head_rot[0], 10)} `
420-
+ `${transform.commands_execute_condition ? transform.commands_execute_condition + ' ' : ''}run `
421-
+ `block ${frameIndex}_locator_commands%NEWLINE_PATCH%{\n`
399+
+ `${transform.function_execute_condition ? transform.function_execute_condition + ' ' : ''}run `
400+
+ `block ${frameIndex}_locator_${node.storage_name}%NEWLINE_PATCH%{\n`
422401
+ `tp @s ~ ~ ~ ~ ~\n`
423-
+ `${transform.commands}`
402+
+ `${transform.function}`
424403
+ `\n}`
425404
} else {
426405
frameFunc +=
427406
`\nexecute on vehicle unless entity @s[tag=${TAGS.TRANSFORMS_ONLY()}] `
428407
+ `positioned ^${roundTo(transform.pos[0], 10)} ^${roundTo(transform.pos[1], 10)} ^${roundTo(transform.pos[2], 10)} `
429408
+ `rotated ~${roundTo(transform.head_rot[1], 10)} ~${roundTo(transform.head_rot[0], 10)} `
430-
+ `${transform.commands_execute_condition ? transform.commands_execute_condition + ' ' : ''}run `
431-
+ `block ${frameIndex}_locator_commands%NEWLINE_PATCH%{\n`
432-
+ `${transform.commands}`
409+
+ `${transform.function_execute_condition ? transform.function_execute_condition + ' ' : ''}run `
410+
+ `block ${frameIndex}_locator_${node.storage_name}%NEWLINE_PATCH%{\n`
411+
+ `${transform.function}`
433412
+ `\n}`
434413
}
435414
}
@@ -457,7 +436,7 @@ dir animations {
457436
if (!auto_update_rig_orientation) {
458437
frameFunc += `\nfunction ./on_tick/transform_floating_entities`
459438
}
460-
hasCommands = true
439+
hasFunction = true
461440
}
462441

463442
if (frame.variants?.length) {
@@ -467,14 +446,14 @@ dir animations {
467446
}
468447
const execute_condition = frame.variants_execute_condition ? frame.variants_execute_condition + ' ' : ''
469448
frameFunc += `\nexecute on vehicle unless entity @s[tag=${TAGS.TRANSFORMS_ONLY()}] ${execute_condition}run function *${export_namespace}/variants/${variant.name}/apply`
470-
;hasCommands = true
449+
;hasFunction = true
471450
}
472451

473-
// Root commands keyframes.
474-
if (frame.commands) {
475-
const execute_condition = frame.commands_execute_condition ? frame.commands_execute_condition + ' ' : ''
476-
frameFunc += `\nexecute on vehicle unless entity @s[tag=${TAGS.TRANSFORMS_ONLY()}] at @s ${execute_condition}run block ${frameIndex}_root_commands%NEWLINE_PATCH%{\n${frame.commands}\n}`
477-
;hasCommands = true
452+
// Root function keyframes.
453+
if (frame.function) {
454+
const execute_condition = frame.function_execute_condition ? frame.function_execute_condition + ' ' : ''
455+
frameFunc += `\nexecute on vehicle unless entity @s[tag=${TAGS.TRANSFORMS_ONLY()}] at @s ${execute_condition}run block ${frameIndex}_root_function%NEWLINE_PATCH%{\n${frame.function}\n}`
456+
;hasFunction = true
478457
}
479458
;if (frameFunc.length > 0) {
480459
frameFunc = `function ${frameIndex}%NEWLINE_PATCH%{${frameFunc}\n}`
@@ -602,7 +581,7 @@ function summon {
602581
execute if data storage <%temp_storage%> {args:{variant:''}} run return run block if_empty {
603582
# Tell the user that the variant cannot be empty.
604583
tellraw @a <%TELLRAW.ARGUMENT_CANNOT_BE_EMPTY('variant')%>
605-
function *<%export_namespace%>/remove/this/without_on_remove_commands
584+
function *<%export_namespace%>/remove/this/without_on_remove_function
606585
}
607586
# Attempt to apply the requested variant.
608587
# We get the success of the `try_apply` function in just in case the user's arguments are *very* wrong.
@@ -615,14 +594,14 @@ function summon {
615594
execute unless score #success <%OBJECTIVES.I()%> matches 1 run return run block invalid_variant {
616595
# Tell the user that the provided variant doesn't exist, remove the rig, and list all available variants for this rig.
617596
tellraw @a <%TELLRAW.INVALID_VARIANT(rig.variants)%>
618-
function *<%export_namespace%>/remove/this/without_on_remove_commands
597+
function *<%export_namespace%>/remove/this/without_on_remove_function
619598
}
620599
scoreboard players set #success <%OBJECTIVES.I()%> 1
621600
}
622601
} ELSE {
623602
execute if data storage <%temp_storage%> args.variant run block zzz/variant_arg/no_variants_warning {
624603
tellraw @a <%TELLRAW.NO_VARIANTS()%>
625-
function *<%export_namespace%>/remove/this/without_on_remove_commands
604+
function *<%export_namespace%>/remove/this/without_on_remove_function
626605
scoreboard players set #success <%OBJECTIVES.I()%> 0
627606
}
628607
}
@@ -637,7 +616,7 @@ function summon {
637616
# If the animation argument is *explicitly* set to an empty string, return an error.
638617
execute if data storage <%temp_storage%> {args:{animation:''}} run return run block if_empty {
639618
tellraw @a <%TELLRAW.ARGUMENT_CANNOT_BE_EMPTY('animation')%>
640-
function *<%export_namespace%>/remove/this/without_on_remove_commands
619+
function *<%export_namespace%>/remove/this/without_on_remove_function
641620
}
642621
# Automatically set the frame argument to 0 if the frame argument is not provided.
643622
# Takes advantage of `store result score` setting the score to 0 if the command fails.
@@ -650,7 +629,7 @@ function summon {
650629
execute if score #frame <%OBJECTIVES.I()%> matches ..-1 run return run block no_negative {
651630
# Tell the user that the frame argument cannot be negative.
652631
tellraw @a <%TELLRAW.FRAME_CANNOT_BE_NEGATIVE()%>
653-
function *<%export_namespace%>/remove/this/without_on_remove_commands
632+
function *<%export_namespace%>/remove/this/without_on_remove_function
654633
}
655634
# Attempt to apply the animation frame.
656635
execute store success score #success <%OBJECTIVES.I()%> run block try_set_frame { with storage <%temp_storage%> args
@@ -666,7 +645,7 @@ function summon {
666645
execute unless score #success <%OBJECTIVES.I()%> matches 1 run return run block invalid_animation {
667646
# Tell the user that the provided animation doesn't exist, remove the rig, and list all available animations for this rig.
668647
tellraw @a <%TELLRAW.INVALID_ANIMATION(animations)%>
669-
function *<%export_namespace%>/remove/this/without_on_remove_commands
648+
function *<%export_namespace%>/remove/this/without_on_remove_function
670649
}
671650

672651
# If the animation is successfully applied, and the start_animation argument is set to true, start the animation.
@@ -911,11 +890,11 @@ dir remove {
911890
if (on_remove_function) emit.mcb(on_remove_function)
912891
%%>
913892

914-
function ./this/without_on_remove_commands
893+
function ./this/without_on_remove_function
915894
}
916895

917896
dir this {
918-
function without_on_remove_commands {
897+
function without_on_remove_function {
919898
debug assert executed_as_root_entity
920899

921900
IF (has_entity_locators || has_cameras) {

test-packs/1.20.4/blueprints/armor_stand_1.20.4.ajblueprint

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
"data_pack": "../datapacks/animated_java",
1919
"on_summon_function": "say On-Summon!",
2020
"on_remove_function": "say On-Remove!",
21-
"on_pre_tick_function": "say Pre-Tick!",
22-
"on_post_tick_function": "say Post-Tick!",
2321
"baked_animations": false,
2422
"json_file": "../testPluginExport.json"
2523
},

0 commit comments

Comments
 (0)