Skip to content

Commit 28ea700

Browse files
committed
🚧 Plugin JSON Improvements
- Fixed #245 - Removed unused settings from JSON export. - Add UUID back to exported nodes and internal data structures. - Added `safe_name` to nodes. - Fixed incorrect JSON Text serialization.
1 parent 424173b commit 28ea700

File tree

7 files changed

+148
-187
lines changed

7 files changed

+148
-187
lines changed

schemas/pluginJson.schema.json

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,16 @@
1010
"type": "object",
1111
"required": [
1212
"export_namespace",
13-
"show_bounding_box",
14-
"auto_bounding_box",
1513
"bounding_box",
16-
"resource_pack_export_mode",
1714
"display_item",
18-
"custom_model_data_offset",
19-
"enable_advanced_resource_pack_settings",
20-
"resource_pack",
21-
"display_item_path",
22-
"model_folder",
23-
"texture_folder",
24-
"baked_animations",
25-
"json_file"
15+
"baked_animations"
2616
],
2717
"properties": {
2818
"export_namespace": {
2919
"type": "string",
3020
"default": "armor_stand",
3121
"description": "The namespace to export the project to. This is the namespace that will be used in the exported Resource Pack and Data Pack."
3222
},
33-
"show_bounding_box": {
34-
"type": "boolean",
35-
"default": false,
36-
"description": "Whether or not to show the bounding box in the editor."
37-
},
38-
"auto_bounding_box": {
39-
"type": "boolean",
40-
"default": true,
41-
"description": "Whether or not to automatically calculate the bounding box based on the model's geometry. \n\nNOTE: The auto bounding box will NOT take bone offsets from animations into account, so the bounding box may be smaller than needed in some cases."
42-
},
4323
"bounding_box": {
4424
"type": "array",
4525
"default": [48, 48],
@@ -51,53 +31,16 @@
5131
"minItems": 2,
5232
"maxItems": 2
5333
},
54-
"resource_pack_export_mode": {
55-
"type": "string",
56-
"default": "raw",
57-
"description": "Determines how the Resource Pack should be exported.\n\nRaw - Exports the Resource Pack as a folder.\n\nZip - Exports the Resource Pack as a .zip file.\n\nNone - Disables Resource Pack exporting.",
58-
"enum": ["raw", "zip", "none"]
59-
},
6034
"display_item": {
6135
"type": "string",
6236
"default": "minecraft:white_dye",
6337
"description": "The item to display the Blueprints models in-game. Multiple Blueprints can be placed on the same item and they will be merged automatically."
6438
},
65-
"custom_model_data_offset": {
66-
"type": "integer",
67-
"default": 0,
68-
"description": "The offset to use for the Custom Model Data of the Display Item. Allows multiple Blueprints on the same item, but in separate, unaffiliated Resource Packs."
69-
},
70-
"enable_advanced_resource_pack_settings": {
71-
"type": "boolean",
72-
"default": false,
73-
"description": "Whether or not to enable the advanced Resource Pack settings. (Individual RP Folder Selection)"
74-
},
75-
"resource_pack": {
76-
"type": "string",
77-
"default": "",
78-
"description": "The root folder of the Resource Pack to export the project into."
79-
},
80-
"display_item_path": {
81-
"type": "string",
82-
"default": "",
83-
"description": "Where to place the Display Item. This should be a path to a .json file in a Resource Pack."
84-
},
85-
"model_folder": {
86-
"type": "string",
87-
"default": "",
88-
"description": "Where to place all of the exported models. This should be a path to a folder in a Resource Pack."
89-
},
90-
"texture_folder": {
91-
"type": "string",
92-
"default": "",
93-
"description": "Where to place all of the exported textures. This should be a path to a folder in a Resource Pack."
94-
},
9539
"baked_animations": {
9640
"type": "boolean",
9741
"default": true,
9842
"description": "Whether or not to bake the exported animations.\n\nBaked animations have their frames pre-calculated and stored in the exported JSON file, reducing the complexity of rendering the model in-game.\n\nSome Plugins may require this to be enabled to function correctly."
99-
},
100-
"json_file": { "type": "string", "default": "", "description": "" }
43+
}
10144
}
10245
},
10346
"nodes": {
@@ -298,7 +241,7 @@
298241
},
299242
"node": {
300243
"type": "object",
301-
"required": ["type", "name", "default_transform"],
244+
"required": ["type", "name", "safe_name", "uuid", "default_transform"],
302245
"properties": {
303246
"type": {
304247
"type": "string",
@@ -313,6 +256,8 @@
313256
]
314257
},
315258
"name": { "type": "string" },
259+
"safe_name": { "type": "string" },
260+
"uuid": { "type": "string" },
316261
"parent": { "type": "string" },
317262
"default_transform": {
318263
"$ref": "#/definitions/nodeTransform",

src/systems/animationRenderer.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ export function getFrame(
208208
}
209209
break
210210
}
211-
case 'camera': {
212-
matrix = getNodeMatrix(outlinerNode, 1)
213-
break
214-
}
211+
case 'camera':
215212
case 'struct': {
216213
matrix = getNodeMatrix(outlinerNode, 1)
217214
break
@@ -340,11 +337,11 @@ export function hashAnimations(animations: IRenderedAnimation[]) {
340337
export function getAnimatableNodes(): OutlinerElement[] {
341338
return [
342339
...Group.all,
343-
...NullObject.all,
344340
...Locator.all,
345341
...TextDisplay.all,
346342
...VanillaBlockDisplay.all,
347343
...VanillaItemDisplay.all,
344+
...(OutlinerElement.types.camera ? OutlinerElement.types.camera.all : []),
348345
]
349346
}
350347

src/systems/datapackCompiler.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ namespace TELLRAW {
211211
' ',
212212
' ',
213213
{ text: ' ● ', color: 'gray' },
214-
{ text: anim.name, color: 'yellow' },
214+
{ text: anim.safe_name, color: 'yellow' },
215215
])
216216
),
217217
])
@@ -257,7 +257,7 @@ async function generateRootEntityPassengers(rig: IRenderedRig, rigHash: string)
257257
passenger.set('id', new NbtString('minecraft:item_display'))
258258
tags.add(new NbtString(TAGS.GLOBAL_BONE()))
259259
tags.add(new NbtString(TAGS.PROJECT_BONE(aj.export_namespace)))
260-
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.name)))
260+
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.safe_name)))
261261
passenger.set(
262262
'transformation',
263263
new NbtCompound()
@@ -266,17 +266,13 @@ async function generateRootEntityPassengers(rig: IRenderedRig, rigHash: string)
266266
.set('right_rotation', arrayToNbtFloatArray([0, 0, 0, 1]))
267267
.set('scale', arrayToNbtFloatArray([0, 0, 0]))
268268
)
269-
// passenger.set(
270-
// 'transformation',
271-
// matrixToNbtFloatArray(rig.defaultPose.find(v => v.name === node.name)!.matrix)
272-
// )
273269
passenger.set('interpolation_duration', new NbtInt(aj.interpolation_duration))
274270
passenger.set('teleport_duration', new NbtInt(0))
275271
passenger.set('item_display', new NbtString('head'))
276272
const item = new NbtCompound()
277273
const variantModel = rig.variants[Variant.getDefault().uuid].models[uuid]
278274
if (!variantModel) {
279-
throw new Error(`Model for bone '${node.name}' not found!`)
275+
throw new Error(`Model for bone '${node.safe_name}' not found!`)
280276
}
281277
passenger.set(
282278
'item',
@@ -304,7 +300,7 @@ async function generateRootEntityPassengers(rig: IRenderedRig, rigHash: string)
304300
passenger.set('id', new NbtString('minecraft:text_display'))
305301
tags.add(new NbtString(TAGS.GLOBAL_BONE()))
306302
tags.add(new NbtString(TAGS.PROJECT_BONE(aj.export_namespace)))
307-
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.name)))
303+
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.safe_name)))
308304
passenger.set(
309305
'transformation',
310306
new NbtCompound()
@@ -341,7 +337,7 @@ async function generateRootEntityPassengers(rig: IRenderedRig, rigHash: string)
341337
passenger.set('id', new NbtString('minecraft:item_display'))
342338
tags.add(new NbtString(TAGS.GLOBAL_BONE()))
343339
tags.add(new NbtString(TAGS.PROJECT_BONE(aj.export_namespace)))
344-
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.name)))
340+
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.safe_name)))
345341
passenger.set(
346342
'item',
347343
new NbtCompound()
@@ -358,11 +354,13 @@ async function generateRootEntityPassengers(rig: IRenderedRig, rigHash: string)
358354
passenger.set('id', new NbtString('minecraft:block_display'))
359355
tags.add(new NbtString(TAGS.GLOBAL_BONE()))
360356
tags.add(new NbtString(TAGS.PROJECT_BONE(aj.export_namespace)))
361-
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.name)))
357+
tags.add(new NbtString(TAGS.LOCAL_BONE(aj.export_namespace, node.safe_name)))
362358

363359
const parsed = await parseBlock(node.block)
364360
if (!parsed) {
365-
throw new Error(`Invalid Blockstate '${node.block}' in node '${node.name}'!`)
361+
throw new Error(
362+
`Invalid Blockstate '${node.block}' in node '${node.safe_name}'!`
363+
)
366364
}
367365

368366
const states = new NbtCompound()
@@ -447,7 +445,7 @@ async function createAnimationStorage(rig: IRenderedRig, animations: IRenderedAn
447445
const limiter = new MSLimiter(16)
448446

449447
for (const animation of animations) {
450-
PROGRESS_DESCRIPTION.set(`Creating Animation Storage for '${animation.name}'`)
448+
PROGRESS_DESCRIPTION.set(`Creating Animation Storage for '${animation.safe_name}'`)
451449
let frames = new NbtCompound()
452450
const addFrameDataCommand = () => {
453451
const str = `data modify storage aj.${
@@ -464,14 +462,14 @@ async function createAnimationStorage(rig: IRenderedRig, animations: IRenderedAn
464462
const transform = frame.node_transforms[uuid]
465463
if (BONE_TYPES.includes(node.type)) {
466464
thisFrame.set(
467-
node.type + '_' + node.name,
465+
node.type + '_' + node.safe_name,
468466
new NbtCompound()
469467
.set('transformation', matrixToNbtFloatArray(transform.matrix))
470468
.set('start_interpolation', new NbtInt(0))
471469
)
472470
} else {
473471
thisFrame.set(
474-
node.type + '_' + node.name,
472+
node.type + '_' + node.safe_name,
475473
new NbtCompound()
476474
.set('posx', new NbtFloat(transform.pos[0]))
477475
.set('posy', new NbtFloat(transform.pos[1]))
@@ -513,14 +511,14 @@ function createPassengerStorage(rig: IRenderedRig) {
513511
.set('roty', new NbtFloat(Math.radToDeg(node.default_transform.rot[1])))
514512
if (node.type === 'locator' && node.config.use_entity)
515513
data.set('uuid', new NbtString(''))
516-
;(node.type === 'camera' ? cameras : locators).set(node.name, data)
514+
;(node.type === 'camera' ? cameras : locators).set(node.safe_name, data)
517515
break
518516
}
519517
case 'bone':
520518
case 'text_display':
521519
case 'item_display':
522520
case 'block_display': {
523-
bones.set(node.type + '_' + node.name, new NbtString(''))
521+
bones.set(node.type + '_' + node.safe_name, new NbtString(''))
524522
break
525523
}
526524
}
@@ -583,7 +581,6 @@ export async function compileDataPack(options: {
583581
) &&
584582
fs.existsSync(file)
585583
) {
586-
// console.log('Moving old function tag:', file)
587584
const newPath = replacePathPart(
588585
file,
589586
Project!.last_used_export_namespace,

0 commit comments

Comments
 (0)