Skip to content

Commit 16c1d95

Browse files
committed
✨ Reduce filesize of export data packs by ~50%
Reduced transform precision to 4 decimals, and reduced storage-based animation key length.
1 parent 995dda2 commit 16c1d95

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

src/systems/datapackCompiler/1.20.4/animation.mcb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ dir <%export_namespace%> {
244244
REPEAT (Object.values(animation.modified_nodes).sort(nodeSorter)) as node {
245245
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
246246
$execute on passengers run data modify entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] {} merge from \
247-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
247+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
248248
} ELSE IF (['locator', 'camera'].includes(node.type)) {
249249
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
250-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
250+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
251251
}
252252
}
253253
IF (animation.frames.some(v => v.variant)) {
@@ -266,10 +266,10 @@ dir <%export_namespace%> {
266266
REPEAT (Object.values(animation.modified_nodes).sort(nodeSorter)) as node {
267267
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
268268
$execute on passengers if entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] run data modify entity @s {} merge from \
269-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
269+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
270270
} ELSE IF (['locator', 'camera'].includes(node.type)) {
271271
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
272-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
272+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
273273
}
274274
}
275275
IF (animation.frames.some(v => v.variant)) {

src/systems/datapackCompiler/1.20.5/animation.mcb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ dir <%export_namespace%> {
244244
REPEAT (Object.values(animation.modified_nodes).sort(nodeSorter)) as node {
245245
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
246246
$execute on passengers run data modify entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] {} merge from \
247-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
247+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
248248
} ELSE IF (['locator', 'camera'].includes(node.type)) {
249249
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
250-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
250+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
251251
}
252252
}
253253
IF (animation.frames.some(v => v.variant)) {
@@ -266,10 +266,10 @@ dir <%export_namespace%> {
266266
REPEAT (Object.values(animation.modified_nodes).sort(nodeSorter)) as node {
267267
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
268268
$execute on passengers if entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] run data modify entity @s {} merge from \
269-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
269+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
270270
} ELSE IF (['locator', 'camera'].includes(node.type)) {
271271
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
272-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
272+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
273273
}
274274
}
275275
IF (animation.frames.some(v => v.variant)) {

src/systems/datapackCompiler/1.21.2/animation.mcb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ dir <%export_namespace%> {
244244
REPEAT (Object.values(animation.modified_nodes).sort(nodeSorter)) as node {
245245
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
246246
$execute on passengers run data modify entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] {} merge from \
247-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
247+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
248248
} ELSE IF (['locator', 'camera'].includes(node.type)) {
249249
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
250-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
250+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
251251
}
252252
}
253253
IF (animation.frames.some(v => v.variant)) {
@@ -266,10 +266,10 @@ dir <%export_namespace%> {
266266
REPEAT (Object.values(animation.modified_nodes).sort(nodeSorter)) as node {
267267
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
268268
$execute on passengers if entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] run data modify entity @s {} merge from \
269-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
269+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
270270
} ELSE IF (['locator', 'camera'].includes(node.type)) {
271271
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
272-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
272+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
273273
}
274274
}
275275
IF (animation.frames.some(v => v.variant)) {

src/systems/datapackCompiler/1.21.4/animation.mcb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ dir <%export_namespace%> {
314314
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
315315
$execute on passengers run \
316316
data modify entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] {} merge from \
317-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
317+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
318318
} ELSE IF (['locator', 'camera'].includes(node.type)) {
319319
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run \
320320
data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
321-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
321+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
322322
}
323323
}
324324
IF (animation.frames.some(v => v.variant)) {
@@ -339,11 +339,11 @@ dir <%export_namespace%> {
339339
IF (['bone', 'text_display', 'item_display', 'block_display'].includes(node.type)) {
340340
$execute on passengers if entity @s[tag=<%TAGS.PROJECT_NODE_NAMED(export_namespace, node.path_name)%>] run \
341341
data modify entity @s {} merge from \
342-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
342+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
343343
} ELSE IF (['locator', 'camera'].includes(node.type)) {
344344
$execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run \
345345
data modify entity @s data.<%node.type + 's.' + node.storage_name%> merge from \
346-
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type + '_' + node.storage_name%>
346+
storage aj.<%export_namespace%>:animations <%animation.storage_name%>.$(frame).<%node.type.charAt(0) + '_' + node.storage_name%>
347347
}
348348
}
349349
IF (animation.frames.some(v => v.variant)) {

src/systems/datapackCompiler/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -822,20 +822,20 @@ async function createAnimationStorage(rig: IRenderedRig, animations: IRenderedAn
822822
}
823823
if (BONE_TYPES.includes(node.type)) {
824824
thisFrame.set(
825-
node.type + '_' + node.storage_name,
825+
node.type.charAt(0) + '_' + node.storage_name,
826826
new NbtCompound()
827827
.set('transformation', matrixToNbtFloatArray(transform.matrix))
828828
.set('start_interpolation', new NbtInt(0))
829829
)
830830
} else {
831831
thisFrame.set(
832-
node.type + '_' + node.storage_name,
832+
node.type.charAt(0) + '_' + node.storage_name,
833833
new NbtCompound()
834-
.set('posx', new NbtFloat(transform.pos[0]))
835-
.set('posy', new NbtFloat(transform.pos[1]))
836-
.set('posz', new NbtFloat(transform.pos[2]))
837-
.set('rotx', new NbtFloat(transform.rot[0]))
838-
.set('roty', new NbtFloat(transform.rot[1]))
834+
.set('posx', new NbtFloat(roundTo(transform.pos[0], 4)))
835+
.set('posy', new NbtFloat(roundTo(transform.pos[1], 4)))
836+
.set('posz', new NbtFloat(roundTo(transform.pos[2], 4)))
837+
.set('rotx', new NbtFloat(roundTo(transform.rot[0], 4)))
838+
.set('roty', new NbtFloat(roundTo(transform.rot[1], 4)))
839839
)
840840
}
841841
}

src/systems/util.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export function arrayToNbtFloatArray(array: number[]) {
2121
}
2222

2323
export function matrixToNbtFloatArray(matrix: THREE.Matrix4) {
24-
const matrixArray = new THREE.Matrix4().copy(matrix).transpose().toArray()
24+
const matrixArray = new THREE.Matrix4()
25+
.copy(matrix)
26+
.transpose()
27+
.toArray()
28+
.map(v => roundTo(v, 4))
2529
return arrayToNbtFloatArray(matrixArray)
2630
}
2731

0 commit comments

Comments
 (0)