Skip to content

Commit 23b9bc4

Browse files
committed
🛠️ Fix #233
1 parent 13b8983 commit 23b9bc4

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

src/systems/animationRenderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface IRenderedFrame {
9898

9999
export interface IRenderedAnimation {
100100
name: string
101-
storageSafeName: string
101+
safeName: string
102102
loopDelay: number
103103
frames: IRenderedFrame[]
104104
/**
@@ -285,8 +285,8 @@ export function updatePreview(animation: _Animation, time: number) {
285285

286286
export function renderAnimation(animation: _Animation, rig: IRenderedRig) {
287287
const rendered = {
288-
name: toSafeFuntionName(animation.name),
289-
storageSafeName: toSafeFuntionName(animation.name).replaceAll('.', '_'),
288+
name: animation.name,
289+
safeName: toSafeFuntionName(animation.name).replaceAll('.', '_'),
290290
loopDelay: Number(animation.loop_delay) || 0,
291291
frames: [],
292292
duration: 0,

src/systems/datapackCompiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ async function createAnimationStorage(animations: IRenderedAnimation[]) {
438438
const addFrameDataCommand = () => {
439439
const str = `data modify storage aj.${
440440
Project!.animated_java.export_namespace
441-
}:animations ${animation.storageSafeName} merge value ${frames.toString()}`
441+
}:animations ${animation.safeName} merge value ${frames.toString()}`
442442
dataCommands.push(str)
443443
frames = new NbtCompound()
444444
}

src/systems/datapackCompiler/animation.mcb

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ dir <%export_namespace%> {
116116
function on_load {
117117
<%%
118118
animations.forEach(animation => {
119-
emit(`scoreboard objectives add ${OBJECTIVES.FRAME(animation.name)} dummy`)
119+
emit(`scoreboard objectives add ${OBJECTIVES.FRAME(animation.safeName)} dummy`)
120120
})
121121
%%>
122122

@@ -157,8 +157,8 @@ dir <%export_namespace%> {
157157
function #*<%export_namespace%>/as_root/pre_tick
158158
# Animations
159159
REPEAT (animations) as animation {
160-
execute if entity @s[tag=<%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>] run \
161-
function *<%export_namespace%>/animations/<%animation.name%>/zzz/on_tick
160+
execute if entity @s[tag=<%TAGS.ANIMATION_PLAYING(export_namespace, animation.safeName)%>] run \
161+
function *<%export_namespace%>/animations/<%animation.safeName%>/zzz/on_tick
162162
}
163163
execute on passengers if entity @s[tag=<%TAGS.PROJECT_DATA(export_namespace)%>] run {
164164
REPEAT (Object.values(rig.nodeMap).filter(v => v.type === 'locator')) as node {
@@ -218,77 +218,77 @@ dir <%export_namespace%> {
218218

219219
dir animations {
220220
REPEAT (animations) as animation {
221-
dir <%animation.name%> {
221+
dir <%animation.safeName%> {
222222
# TODO: Maybe add an exclusive argument to the play function that will pause all other animations before playing this one.
223223
function play {
224224
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
225225
function *global/errors/function_not_executed_as_root_entity \
226-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/play'}
227-
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
228-
scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> 0
226+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/play'}
227+
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.safeName)%>
228+
scoreboard players set @s <%OBJECTIVES.FRAME(animation.safeName)%> 0
229229
tag @s add <%TAGS.TRANSFORMS_ONLY()%>
230230
execute at @s run function ./zzz/set_frame {frame: 0}
231231
tag @s remove <%TAGS.TRANSFORMS_ONLY()%>
232232
}
233233
function stop {
234234
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
235235
function *global/errors/function_not_executed_as_root_entity \
236-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/stop'}
237-
tag @s remove <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
238-
scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> 0
236+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/stop'}
237+
tag @s remove <%TAGS.ANIMATION_PLAYING(export_namespace, animation.safeName)%>
238+
scoreboard players set @s <%OBJECTIVES.FRAME(animation.safeName)%> 0
239239
tag @s add <%TAGS.TRANSFORMS_ONLY()%>
240240
execute at @s run function ./zzz/set_frame {frame: 0}
241241
tag @s remove <%TAGS.TRANSFORMS_ONLY()%>
242242
}
243243
function pause {
244244
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
245245
function *global/errors/function_not_executed_as_root_entity \
246-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/pause'}
247-
tag @s remove <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
246+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/pause'}
247+
tag @s remove <%TAGS.ANIMATION_PLAYING(export_namespace, animation.safeName)%>
248248
}
249249
function resume {
250250
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
251251
function *global/errors/function_not_executed_as_root_entity \
252-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/resume'}
253-
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
252+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/resume'}
253+
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.safeName)%>
254254
}
255255
function next_frame {
256256
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
257257
function *global/errors/function_not_executed_as_root_entity \
258-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/next_frame'}
259-
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration%>.. run scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> 1
260-
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME(animation.name)%>
258+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/next_frame'}
259+
execute if score @s <%OBJECTIVES.FRAME(animation.safeName)%> matches <%animation.duration%>.. run scoreboard players set @s <%OBJECTIVES.FRAME(animation.safeName)%> 1
260+
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME(animation.safeName)%>
261261
execute at @s run function ./zzz/apply_frame with storage aj:temp
262-
scoreboard players add @s <%OBJECTIVES.FRAME(animation.name)%> 1
262+
scoreboard players add @s <%OBJECTIVES.FRAME(animation.safeName)%> 1
263263
}
264264
function set_frame {
265265
# Sets the frame without interpolation
266266
#ARGS: {frame: int}
267267
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
268268
function *global/errors/function_not_executed_as_root_entity \
269-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/set_frame'}
270-
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> $(frame)
269+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/set_frame'}
270+
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME(animation.safeName)%> $(frame)
271271
execute at @s run function ./zzz/set_frame with storage aj:temp
272272
}
273273
function apply_frame {
274274
# ARGS: {frame: int}
275275
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
276276
function *global/errors/function_not_executed_as_root_entity \
277-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/apply_frame'}
278-
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> $(frame)
277+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/apply_frame'}
278+
$execute store result storage aj:temp frame int 1 run scoreboard players set @s <%OBJECTIVES.FRAME(animation.safeName)%> $(frame)
279279
execute at @s run function ./zzz/apply_frame with storage aj:temp
280280
}
281281
function tween {
282282
# Attempts to smoothly transition from the currently playing animation into this one.
283283
#ARGS: {duration: int, to_frame: int}
284284
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
285285
function *global/errors/function_not_executed_as_root_entity \
286-
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.name%>/tween_play'}
286+
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/<%animation.safeName%>/tween_play'}
287287
function *<%export_namespace%>/animations/pause_all
288288

289-
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
289+
tag @s add <%TAGS.ANIMATION_PLAYING(export_namespace, animation.safeName)%>
290290
$scoreboard players set @s <%OBJECTIVES.TWEEN_DURATION()%> $(duration)
291-
$scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> $(to_frame)
291+
$scoreboard players set @s <%OBJECTIVES.FRAME(animation.safeName)%> $(to_frame)
292292

293293
scoreboard players operation #this <%OBJECTIVES.I()%> = @s <%OBJECTIVES.TWEEN_DURATION()%>
294294
scoreboard players add @s <%OBJECTIVES.TWEEN_DURATION()%> 1
@@ -305,25 +305,25 @@ dir <%export_namespace%> {
305305
execute if score @s <%OBJECTIVES.TWEEN_DURATION()%> matches 1.. run return 1
306306
execute if score @s <%OBJECTIVES.TWEEN_DURATION()%> matches 0 on passengers run data modify entity @s interpolation_duration set value <%interpolation_duration%>
307307
# Animation logic
308-
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME(animation.name)%>
308+
execute store result storage aj:temp frame int 1 run scoreboard players get @s <%OBJECTIVES.FRAME(animation.safeName)%>
309309
IF (animation.loopMode === 'loop' && animation.loopDelay === 0) {
310310
# Makes sure commands in the last frame of the animation is run.
311-
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches -1 run {
311+
execute if score @s <%OBJECTIVES.FRAME(animation.safeName)%> matches -1 run {
312312
function ./apply_frame {frame: <%animation.duration-1%>}
313-
scoreboard players add @s <%OBJECTIVES.FRAME(animation.name)%> 1
313+
scoreboard players add @s <%OBJECTIVES.FRAME(animation.safeName)%> 1
314314
}
315315
}
316316
function ./apply_frame with storage aj:temp
317317
IF (animation.loopMode === 'loop') {
318-
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration-2 + animation.loopDelay%>.. run return run {
319-
scoreboard players set @s <%OBJECTIVES.FRAME(animation.name)%> <%animation.loopDelay === 0 ? -1 : 0%>
318+
execute if score @s <%OBJECTIVES.FRAME(animation.safeName)%> matches <%animation.duration-2 + animation.loopDelay%>.. run return run {
319+
scoreboard players set @s <%OBJECTIVES.FRAME(animation.safeName)%> <%animation.loopDelay === 0 ? -1 : 0%>
320320
}
321321
} ELSE IF (animation.loopMode === 'hold') {
322-
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration-1%>.. run return run function ../pause
322+
execute if score @s <%OBJECTIVES.FRAME(animation.safeName)%> matches <%animation.duration-1%>.. run return run function ../pause
323323
} ELSE IF (animation.loopMode === 'once') {
324-
execute if score @s <%OBJECTIVES.FRAME(animation.name)%> matches <%animation.duration-1%> run return run function ../stop
324+
execute if score @s <%OBJECTIVES.FRAME(animation.safeName)%> matches <%animation.duration-1%> run return run function ../stop
325325
}
326-
scoreboard players add @s <%OBJECTIVES.FRAME(animation.name)%> 1
326+
scoreboard players add @s <%OBJECTIVES.FRAME(animation.safeName)%> 1
327327
}
328328
IF (use_storage_for_animation) {
329329
function set_frame {
@@ -460,7 +460,7 @@ dir <%export_namespace%> {
460460
function *global/errors/function_not_executed_as_root_entity \
461461
{'export_namespace': '<%export_namespace%>', 'function_path': 'animated_java:<%export_namespace%>/animations/pause_all'}
462462
REPEAT (animations) as animation {
463-
tag @s remove <%TAGS.ANIMATION_PLAYING(export_namespace, animation.name)%>
463+
tag @s remove <%TAGS.ANIMATION_PLAYING(export_namespace, animation.safeName)%>
464464
}
465465
}
466466
}

src/systems/jsonCompiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function serailizeNodeTransform(node: INodeTransform): ExportedNodetransform {
270270
function serializeAnimation(animation: IRenderedAnimation): ExportedBakedAnimation {
271271
const json: ExportedBakedAnimation = {
272272
name: animation.name,
273-
storageSafeName: animation.storageSafeName,
273+
safeName: animation.safeName,
274274
duration: animation.duration,
275275
loopDelay: animation.loopDelay,
276276
loopMode: animation.loopMode,

test_blueprints/armor_stand.ajblueprint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
"display_item": "minecraft:white_dye",
1818
"custom_model_data_offset": 0,
1919
"enable_advanced_resource_pack_settings": false,
20-
"resource_pack": "../dist/resourcepack",
20+
"resource_pack": "C:\\Users\\SnaveSutit\\AppData\\Roaming\\com.modrinth.theseus\\profiles\\Animated Java Dev\\resourcepacks\\resourcepack",
2121
"display_item_path": "",
2222
"model_folder": "",
2323
"texture_folder": "",
2424
"enable_advanced_data_pack_settings": false,
25-
"data_pack": "../dist/datapack",
25+
"data_pack": "C:\\Users\\SnaveSutit\\AppData\\Roaming\\com.modrinth.theseus\\profiles\\Animated Java Dev\\saves\\Animated Java Dev\\datapacks\\datapack",
2626
"summon_commands": "",
2727
"interpolation_duration": 1,
2828
"teleportation_duration": 1,

0 commit comments

Comments
 (0)