Skip to content

Commit 5d3cb3d

Browse files
committed
🛠️ Fix Storage Based Animations
- Fixed animations with `.` in them causing invalid storage paths. - Fixed storage-based animations not animating text, item, and block displays.
1 parent 1a7af06 commit 5d3cb3d

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/systems/animated_java.mcb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ dir <%export_namespace%> {
324324
#ARGS: {frame: int}
325325
REPEAT (animation.includedNodes) as node {
326326
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
327-
$execute on passengers run data modify entity @s[tag=<%TAGS.LOCAL_BONE(export_namespace, node.name)%>] {} merge from storage aj.<%export_namespace%>:animations list.<%animation.name%>.frames[$(frame)].<%node.name%>
327+
$execute on passengers run data modify entity @s[tag=<%TAGS.LOCAL_BONE(export_namespace, node.name)%>] {} merge from storage aj.<%export_namespace%>:animations list.<%animation.storageSafeName%>.frames[$(frame)].<%node.name%>
328328
}
329329
}
330330
execute on passengers run data modify entity @s[type=!marker] start_interpolation set value -1
@@ -333,7 +333,7 @@ dir <%export_namespace%> {
333333
#ARGS: {frame: int}
334334
REPEAT (animation.includedNodes) as node {
335335
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
336-
$execute on passengers run data modify entity @s[tag=<%TAGS.LOCAL_BONE(export_namespace, node.name)%>] {} merge from storage aj.<%export_namespace%>:animations list.<%animation.name%>.frames[$(frame)].<%node.name%>
336+
$execute on passengers run data modify entity @s[tag=<%TAGS.LOCAL_BONE(export_namespace, node.name)%>] {} merge from storage aj.<%export_namespace%>:animations list.<%animation.storageSafeName%>.frames[$(frame)].<%node.name%>
337337
}
338338
}
339339
}

src/systems/animationRenderer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { TextDisplay } from '../outliner/textDisplay'
99
import { VanillaBlockDisplay } from '../outliner/vanillaBlockDisplay'
1010
import { VanillaItemDisplay } from '../outliner/vanillaItemDisplay'
11+
import { toSafeFuntionName } from '../util/minecraftUtil'
1112
import { roundToNth } from '../util/misc'
1213
import { AnyRenderedNode, IRenderedRig } from './rigRenderer'
1314
import * as crypto from 'crypto'
@@ -74,6 +75,7 @@ export interface IRenderedFrame {
7475

7576
export interface IRenderedAnimation {
7677
name: string
78+
storageSafeName: string
7779
loopDelay: number
7880
frames: IRenderedFrame[]
7981
/**
@@ -250,6 +252,7 @@ export function updatePreview(animation: _Animation, time: number) {
250252
export function renderAnimation(animation: _Animation, rig: IRenderedRig) {
251253
const rendered = {
252254
name: animation.name,
255+
storageSafeName: toSafeFuntionName(animation.name).replaceAll('.', '_'),
253256
loopDelay: Number(animation.loop_delay) || 0,
254257
frames: [],
255258
duration: 0,

src/systems/datapackCompiler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../interface/expor
1919
import { roundTo } from '../util/misc'
2020
import { setTimeout } from 'timers'
2121

22+
const BONE_TYPES = ['bone', 'text_display', 'item_display', 'block_display']
23+
2224
namespace TAGS {
2325
export const NEW = () => 'aj.new'
2426
export const GLOBAL_RIG = () => 'aj.rig_entity'
@@ -421,14 +423,14 @@ function createAnimationStorage(animations: IRenderedAnimation[]) {
421423
new NbtCompound(), // This compound is just to make the list 1-indexed
422424
])
423425
const animStorage = new NbtCompound().set('frames', frames)
424-
storage.set(animation.name, animStorage)
426+
storage.set(animation.storageSafeName, animStorage)
425427
for (const frame of animation.frames) {
426428
const frameStorage = new NbtCompound()
427429
frames.add(frameStorage)
428430
for (const node of frame.nodes) {
429-
if (node.type !== 'bone') continue
431+
if (!BONE_TYPES.includes(node.type)) continue
430432
frameStorage.set(
431-
node.name,
433+
node.type + '_' + node.name,
432434
new NbtCompound()
433435
.set('transformation', matrixToNbtFloatArray(node.matrix))
434436
.set('start_interpolation', new NbtInt(0))

0 commit comments

Comments
 (0)