Skip to content

Commit b8ea678

Browse files
committed
Fix #209
- Also fix each animation using the same frame scoreboard
1 parent 98e679a commit b8ea678

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

src/systems/datapackCompiler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const BONE_TYPES = ['bone', 'text_display', 'item_display', 'block_display']
3333
namespace TAGS {
3434
export const NEW = () => 'aj.new'
3535
export const GLOBAL_RIG = () => 'aj.rig_entity'
36+
// Used to tell the set and apply frame functions to only apply the bone transforms, and ignore command/variant keyframes
37+
export const TRANSFORMS_ONLY = () => 'aj.transforms_only'
3638

3739
export const GLOBAL_ROOT = () => 'aj.rig_root'
3840
export const PROJECT_ROOT = (exportNamespace: string) => `aj.${exportNamespace}.root`
@@ -69,7 +71,7 @@ namespace TAGS {
6971
namespace OBJECTIVES {
7072
export const I = () => 'aj.i'
7173
export const ID = () => 'aj.id'
72-
export const FRAME = () => 'aj.frame'
74+
export const FRAME = (animationName: string) => `aj.${animationName}.frame`
7375
export const IS_RIG_LOADED = () => 'aj.is_rig_loaded'
7476
export const TWEEN_DURATION = () => 'aj.tween_duration'
7577
}

src/systems/datapackCompiler/animation.mcb

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ dir global {
22

33
function on_load minecraft:load {
44
# Initialize Scoreboards
5+
scoreboard objectives add <%OBJECTIVES.I()%> dummy
6+
scoreboard objectives add <%OBJECTIVES.ID()%> dummy
7+
scoreboard objectives add <%OBJECTIVES.IS_RIG_LOADED()%> dummy
8+
scoreboard objectives add <%OBJECTIVES.TWEEN_DURATION()%> dummy
59
<%%
6-
Object.values(OBJECTIVES).forEach(obj => {
7-
emit(`scoreboard objectives add ${obj()} dummy`)
10+
animations.forEach(animation => {
11+
emit(`scoreboard objectives add ${OBJECTIVES.FRAME(animation.name)} dummy`)
812
})
913
%%>
1014

@@ -220,16 +224,20 @@ dir <%export_namespace%> {
220224
function *global/errors/function_not_executed_as_root_entity \
221225
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/play'}
222226
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
223-
scoreboard players set @s <%OBJECTIVES.FRAME()%> 0
227+
scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> 0
228+
tag @s add <%TAGS.TRANSFORMS_ONLY()%>
224229
execute at @s run function ./zzz/set_frame {frame: 0}
230+
tag @s remove <%TAGS.TRANSFORMS_ONLY()%>
225231
}
226232
function stop {
227233
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
228234
function *global/errors/function_not_executed_as_root_entity \
229235
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/stop'}
230236
tag @s remove <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
231-
scoreboard players set @s <%OBJECTIVES.FRAME()%> 0
237+
scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> 0
238+
tag @s add <%TAGS.TRANSFORMS_ONLY()%>
232239
execute at @s run function ./zzz/set_frame {frame: 0}
240+
tag @s remove <%TAGS.TRANSFORMS_ONLY()%>
233241
}
234242
function pause {
235243
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
@@ -247,26 +255,26 @@ dir <%export_namespace%> {
247255
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
248256
function *global/errors/function_not_executed_as_root_entity \
249257
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/next_frame'}
250-
execute if score @s <%OBJECTIVES.FRAME()%> matches <%animation.duration%>.. run scoreboard players set @s <%OBJECTIVES.FRAME()%> 1
251-
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME()%>
258+
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration%>.. run scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> 1
259+
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME(animation.name)%>
252260
execute at @s run function ./zzz/apply_frame with storage aj:temp
253-
scoreboard players add @s <%OBJECTIVES.FRAME()%> 1
261+
scoreboard players add @s <%OBJECTIVES.FRAME(animation.name)%> 1
254262
}
255263
function set_frame {
256264
# Sets the frame without interpolation
257265
#ARGS: {frame: int}
258266
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
259267
function *global/errors/function_not_executed_as_root_entity \
260268
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/set_frame'}
261-
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME()%> $(frame)
269+
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> $(frame)
262270
execute at @s run function ./zzz/set_frame with storage aj:temp
263271
}
264272
function apply_frame {
265273
# ARGS: {frame: int}
266274
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
267275
function *global/errors/function_not_executed_as_root_entity \
268276
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/apply_frame'}
269-
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME()%> $(frame)
277+
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> $(frame)
270278
execute at @s run function ./zzz/apply_frame with storage aj:temp
271279
}
272280
function tween {
@@ -279,12 +287,14 @@ dir <%export_namespace%> {
279287

280288
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
281289
$scoreboard players set @s <%OBJECTIVES.TWEEN_DURATION()%> $(duration)
282-
$scoreboard players set @s <%OBJECTIVES.FRAME()%> $(to_frame)
290+
$scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> $(to_frame)
283291

284292
scoreboard players operation #this <%OBJECTIVES.I()%> = @s <%OBJECTIVES.TWEEN_DURATION()%>
285293
scoreboard players add @s <%OBJECTIVES.TWEEN_DURATION()%> 1
294+
tag @s add <%TAGS.TRANSFORMS_ONLY()%>
286295
execute at @s run function ./zzz/apply_frame {frame: 0}
287296
$execute at @s run function ./zzz/apply_frame {frame: $(to_frame)}
297+
tag @s remove <%TAGS.TRANSFORMS_ONLY()%>
288298
execute on passengers store result entity @s interpolation_duration int 1 run scoreboard players get #this <%OBJECTIVES.I()%>
289299
}
290300
dir zzz {
@@ -294,25 +304,25 @@ dir <%export_namespace%> {
294304
execute if score @s <%OBJECTIVES.TWEEN_DURATION()%> matches 1.. run return 1
295305
execute if score @s <%OBJECTIVES.TWEEN_DURATION()%> matches 0 on passengers run data modify entity @s interpolation_duration set value <%interpolation_duration%>
296306
# Animation logic
297-
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME()%>
307+
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME(animation.name)%>
298308
IF (animation.loopMode === 'loop' && animation.loopDelay === 0) {
299309
# Makes sure commands in the last frame of the animation is run.
300-
execute if score @s <%OBJECTIVES.FRAME()%> matches -1 run {
310+
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches -1 run {
301311
function ./apply_frame {frame: <%animation.duration-1%>}
302-
scoreboard players add @s <%OBJECTIVES.FRAME()%> 1
312+
scoreboard players add @s <%OBJECTIVES.FRAME(animation.name)%> 1
303313
}
304314
}
305315
function ./apply_frame with storage aj:temp
306316
IF (animation.loopMode === 'loop') {
307-
execute if score @s <%OBJECTIVES.FRAME()%> matches <%animation.duration-2 + animation.loopDelay%>.. run return run {
308-
scoreboard players set @s <%OBJECTIVES.FRAME()%> <%animation.loopDelay === 0 ? -1 : 0%>
317+
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration-2 + animation.loopDelay%>.. run return run {
318+
scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> <%animation.loopDelay === 0 ? -1 : 0%>
309319
}
310320
} ELSE IF (animation.loopMode === 'hold') {
311-
execute if score @s <%OBJECTIVES.FRAME()%> matches <%animation.duration-1%>.. run return run function ../pause
321+
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration-1%>.. run return run function ../pause
312322
} ELSE IF (animation.loopMode === 'once') {
313-
execute if score @s <%OBJECTIVES.FRAME()%> matches <%animation.duration-1%> run return run function ../stop
323+
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration-1%> run return run function ../stop
314324
}
315-
scoreboard players add @s <%OBJECTIVES.FRAME()%> 1
325+
scoreboard players add @s <%OBJECTIVES.FRAME(animation.name)%> 1
316326
}
317327
IF (use_storage_for_animation) {
318328
function set_frame {
@@ -366,7 +376,7 @@ dir <%export_namespace%> {
366376
if (frame.variant) {
367377
const variant = variants.find(v => v.uuid === frame.variant.uuid)
368378
if (!variant) return
369-
emit.mcb(`execute on vehicle run function *${export_namespace}/variants/${variant.name}/apply`)
379+
emit.mcb(`execute on vehicle unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] run function *${export_namespace}/variants/${variant.name}/apply`)
370380
}
371381
global.merged = {
372382
locators: {},
@@ -406,7 +416,7 @@ dir <%export_namespace%> {
406416
%%>
407417
}
408418
IF (node.commands) {
409-
execute on vehicle <%node.execute_condition ? node.execute_condition.trim() + ' ' : ''%>positioned \
419+
execute on vehicle unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] <%node.execute_condition ? node.execute_condition.trim() + ' ' : ''%>positioned \
410420
^<%roundTo(node.pos[0], 10)%> \
411421
^<%roundTo(node.pos[1], 10)%> \
412422
^<%roundTo(node.pos[2], 10)%> \

test_blueprints/armor_stand.ajblueprint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4120,7 +4120,7 @@
41204120
"override": false,
41214121
"length": 2,
41224122
"snapping": 20,
4123-
"selected": false,
4123+
"selected": true,
41244124
"saved": false,
41254125
"path": "",
41264126
"anim_time_update": "",

0 commit comments

Comments
 (0)