Skip to content

Commit 9328366

Browse files
committed
🛠️ Reduce complexity of storage-based variant functions
3 commands to 1 command :)
1 parent b4ab4e6 commit 9328366

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

src/systems/datapackCompiler/1.21.4/animation.mcb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,13 @@ dir <%export_namespace%> {
366366
}
367367
}
368368
IF (animation.frames.some(v => v.variant)) {
369-
$execute if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] run data modify storage aj:temp variant set from storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant
370-
$execute if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] run function *<%export_namespace%>/animations/<%animation.safe_name%>/zzz/apply_variant with storage aj:temp variant
371-
$execute if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] run data remove storage aj:temp variant
369+
$execute \
370+
if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant \
371+
unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] \
372+
run { with storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant
373+
#ARGS: {name: string, condition: string}
374+
$execute $(condition)run function *<%export_namespace%>/variants/$(name)/apply
375+
}
372376
}
373377
execute on passengers run data modify entity @s[type=!marker] start_interpolation set value -1
374378
}
@@ -384,15 +388,13 @@ dir <%export_namespace%> {
384388
}
385389
}
386390
IF (animation.frames.some(v => v.variant)) {
387-
$execute if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] run data modify storage aj:temp variant set from storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant
388-
$execute if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] run function *<%export_namespace%>/animations/<%animation.safe_name%>/zzz/apply_variant with storage aj:temp variant
389-
$execute if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] run data remove storage aj:temp variant
390-
}
391-
}
392-
IF (animation.frames.some(v => v.variant)) {
393-
function apply_variant {
394-
#ARGS: {name: string, condition: string}
395-
$execute $(condition)run function *<%export_namespace%>/variants/$(name)/apply
391+
$execute \
392+
if data storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant \
393+
unless entity @s[tag=<%TAGS.TRANSFORMS_ONLY()%>] \
394+
run { with storage aj.<%export_namespace%>:animations <%animation.safe_name%>.$(frame).variant
395+
#ARGS: {name: string, condition: string}
396+
$execute $(condition)run function *<%export_namespace%>/variants/$(name)/apply
397+
}
396398
}
397399
}
398400
} ELSE {

src/systems/datapackCompiler/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,14 @@ async function createAnimationStorage(rig: IRenderedRig, animations: IRenderedAn
559559
'variant',
560560
new NbtCompound()
561561
.set('name', new NbtString(rig.variants[frame.variant.uuid].name))
562-
.set('condition', new NbtString(frame.variant.execute_condition ? `${frame.variant.execute_condition} ` : ''))
562+
.set(
563+
'condition',
564+
new NbtString(
565+
frame.variant.execute_condition
566+
? `${frame.variant.execute_condition} `
567+
: ''
568+
)
569+
)
563570
)
564571
}
565572
if (frames.toString().length > 1000000) {

test_blueprints/armor_stand.ajblueprint

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"meta": {
33
"format": "animated_java_blueprint",
4-
"format_version": "1.5.2",
4+
"format_version": "1.6.0",
55
"uuid": "167b27cd-b559-3f13-a97c-0841fe21f1d1",
66
"save_location": "D:\\github-repos\\animated-java\\animated-java\\test_blueprints\\armor_stand.ajblueprint",
77
"last_used_export_namespace": "armor_stand"
@@ -29,7 +29,7 @@
2929
"ticking_commands": "",
3030
"interpolation_duration": 1,
3131
"teleportation_duration": 1,
32-
"use_storage_for_animation": false,
32+
"use_storage_for_animation": true,
3333
"show_function_errors": true,
3434
"show_outdated_warning": true,
3535
"baked_animations": false,
@@ -1502,7 +1502,7 @@
15021502
"default": {
15031503
"name": "default",
15041504
"display_name": "Default",
1505-
"uuid": "d08528a6-bb3d-0203-485d-1727f5ff2ff7",
1505+
"uuid": "8b21ef0e-2651-7284-337b-7e5fddc16bb7",
15061506
"texture_map": {},
15071507
"excluded_nodes": [],
15081508
"is_default": true

0 commit comments

Comments
 (0)