Skip to content

Commit 589e259

Browse files
committed
🚧 Reference Variants by UUID instead of name
- Changed `variantModels` keys to Variant UUIDs instead of names. - Updated Plugin JSON schema to include the above change. - Fixed Plugin JSON Schema including outdated blueprint setting definitions for `enable_resource_pack` and `enable_data_pack`.
1 parent 8d83285 commit 589e259

File tree

8 files changed

+85
-22
lines changed

8 files changed

+85
-22
lines changed

schemas/jsonExport.schema.json

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"auto_bounding_box",
1515
"bounding_box",
1616
"enable_plugin_mode",
17-
"enable_resource_pack",
18-
"enable_data_pack",
17+
"resource_pack_export_mode",
18+
"data_pack_export_mode",
1919
"display_item",
2020
"custom_model_data_offset",
2121
"enable_advanced_resource_pack_settings",
@@ -48,8 +48,16 @@
4848
"maxItems": 2
4949
},
5050
"enable_plugin_mode": { "type": "boolean", "default": false },
51-
"enable_resource_pack": { "type": "boolean", "default": true },
52-
"enable_data_pack": { "type": "boolean", "default": true },
51+
"resource_pack_export_mode": {
52+
"type": "string",
53+
"default": "raw",
54+
"enum": ["raw", "zip", "none"]
55+
},
56+
"data_pack_export_mode": {
57+
"type": "string",
58+
"default": "raw",
59+
"enum": ["raw", "zip", "none"]
60+
},
5361
"display_item": { "type": "string", "default": "minecraft:white_dye" },
5462
"custom_model_data_offset": { "type": "integer", "default": 0 },
5563
"enable_advanced_resource_pack_settings": {
@@ -102,7 +110,7 @@
102110
"description": "A map of variant names to maps of models to use for each bone when that variant is applied. Note that this map only contains included, and modified bones.",
103111
"additionalProperties": false,
104112
"patternProperties": {
105-
"[a-zA-Z0-9_\\.]+": {
113+
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$": {
106114
"type": "object",
107115
"additionalProperties": false,
108116
"patternProperties": {
@@ -176,6 +184,16 @@
176184
"items": { "$ref": "#/definitions/nodeStructure" }
177185
}
178186
}
187+
},
188+
"variants": {
189+
"type": "object",
190+
"additionalProperties": false,
191+
"description": "A map of variant UUIDs to variant objects.",
192+
"patternProperties": {
193+
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$": {
194+
"$ref": "#/definitions/variant"
195+
}
196+
}
179197
}
180198
}
181199
},
@@ -670,6 +688,37 @@
670688
"repeat": { "type": "boolean" },
671689
"repeat_frequency": { "type": "number", "min": 1 }
672690
}
691+
},
692+
"variant": {
693+
"type": "object",
694+
"description": "A variant of the rig. Variants are used to change the appearance of the rig by swapping out different textures at runtime.",
695+
"required": ["name", "display_name", "uuid", "texture_map", "excluded_nodes"],
696+
"properties": {
697+
"name": {
698+
"type": "string",
699+
"description": "The name of the variant."
700+
},
701+
"display_name": {
702+
"type": "string",
703+
"description": "The display name of the variant. Only used for fancy display purposes such as UI elements."
704+
},
705+
"uuid": { "type": "string" },
706+
"texture_map": {
707+
"type": "object",
708+
"description": "A map of default texture UUID -> variant texture UUID. If a texture is not in this map, it will be assumed to be the same as the default texture.",
709+
"patternProperties": {
710+
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$": {
711+
"type": "string",
712+
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
713+
}
714+
}
715+
},
716+
"excluded_nodes": {
717+
"type": "array",
718+
"description": "A list of node UUIDs that should be excluded / ignored when this variant is applied.",
719+
"items": { "type": "string" }
720+
}
721+
}
673722
}
674723
}
675724
}

src/systems/datapackCompiler/animation.mcb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,10 @@ dir <%export_namespace%> {
656656
function *global/errors/function_not_executed_as_root_entity \
657657
{'function_path': 'animated_java:<%export_namespace%>/variants/<%variant.name%>/apply'}
658658
REPEAT (Object.values(rig.nodeMap)) as node {
659-
IF (node.type === 'bone' && !Object.values(variant.excludedNodes).find(v => v.value === node.node.uuid) && (rig.variantModels[variant.name][node.node.uuid] !== undefined || node.configs.variants[variant.uuid])) {
659+
IF (node.type === 'bone' && !Object.values(variant.excludedNodes).find(v => v.value === node.node.uuid) && (rig.variantModels[variant.uuid][node.node.uuid] !== undefined || node.configs.variants[variant.uuid])) {
660660
execute on passengers if entity @s[tag=aj.<%export_namespace%>.bone.<%node.name%>] run {
661-
IF (rig.variantModels[variant.name][node.node.uuid] !== undefined) {
662-
data modify entity @s item.components.minecraft:custom_model_data set value <%rig.variantModels[variant.name][node.node.uuid].customModelData%>
661+
IF (rig.variantModels[variant.uuid][node.node.uuid] !== undefined) {
662+
data modify entity @s item.components.minecraft:custom_model_data set value <%rig.variantModels[variant.uuid][node.node.uuid].customModelData%>
663663
}
664664
IF (node.configs.variants[variant.uuid]) {
665665
<%%

src/systems/exporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { translate } from '../util/translation'
88
import { Variant } from '../variants'
99
import { hashAnimations, renderProjectAnimations } from './animationRenderer'
1010
import { compileDataPack } from './datapackCompiler'
11-
import { exportJSON } from './jsonExporter'
11+
import { exportJSON } from './jsonCompiler'
1212
import { compileResourcePack } from './resourcepackCompiler'
1313
import { renderRig, hashRig } from './rigRenderer'
1414

src/systems/jsonExporter.ts renamed to src/systems/jsonCompiler.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
/// <reference path="D:/github-repos/snavesutit/blockbench-types/types/index.d.ts"/>
33
/// <reference path="../global.d.ts"/>
44

5+
import { IBlueprintVariantJSON } from '../blueprintFormat'
56
import { type defaultValues } from '../blueprintSettings'
67
import { EasingKey } from '../util/easing'
78
import { detectCircularReferences, scrubUndefined } from '../util/misc'
9+
import { Variant } from '../variants'
810
import type { IAnimationNode, IRenderedAnimation, IRenderedFrame } from './animationRenderer'
911
import type {
1012
AnyRenderedNode,
@@ -82,6 +84,7 @@ export interface IExportedJSON {
8284
default_pose: ExportedAnimationNode[]
8385
node_map: Record<string, ExportedRenderedNode>
8486
node_structure: INodeStructure
87+
variants: Record<string, IBlueprintVariantJSON>
8588
}
8689
/**
8790
* If `blueprint_settings.baked_animations` is true, this will be an array of `ExportedAnimation` objects. Otherwise, it will be an array of `AnimationUndoCopy` objects, just like the `.bbmodel`'s animation list.
@@ -133,6 +136,9 @@ export function exportJSON(options: {
133136
Object.entries(rig.nodeMap).map(([key, node]) => [key, serailizeRenderedNode(node)])
134137
),
135138
node_structure: rig.nodeStructure,
139+
variants: Object.fromEntries(
140+
Variant.all.map(variant => [variant.uuid, variant.toJSON()])
141+
),
136142
},
137143
animations: aj.baked_animations
138144
? animations.map(serializeAnimation)

src/systems/resourcepackCompiler.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../interface/exportProgressDialog'
22
import { isResourcePackPath, toSafeFuntionName } from '../util/minecraftUtil'
3-
import { TRANSPARENT_TEXTURE } from '../variants'
3+
import { TRANSPARENT_TEXTURE, Variant } from '../variants'
44
import { IRenderedNodes, IRenderedRig } from './rigRenderer'
55
import { sortObjectKeys, zip } from './util'
66

@@ -292,14 +292,22 @@ export async function compileResourcePack(options: {
292292
)
293293

294294
// Variant Models
295-
for (const [variantName, models] of Object.entries(rig.variantModels)) {
295+
for (const [variantUUID, models] of Object.entries(rig.variantModels)) {
296+
const variant = Variant.all.find(v => v.uuid === variantUUID)
297+
if (!variant) {
298+
console.error(
299+
`Variant ${variantUUID} not found while exporting variant models:`,
300+
models
301+
)
302+
continue
303+
}
296304
for (const [boneUuid, variantModel] of Object.entries(models)) {
297305
const bone = rig.nodeMap[boneUuid] as IRenderedNodes['Bone']
298306
variantModel.customModelData = displayItemModel.addOverride(
299307
variantModel.resourceLocation
300308
)
301309
exportedFiles.set(
302-
PathModule.join(modelExportFolder, variantName, bone.name + '.json'),
310+
PathModule.join(modelExportFolder, variant.name, bone.name + '.json'),
303311
autoStringify(variantModel.model)
304312
)
305313
}

src/systems/rigRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export interface IRenderedRig {
154154
*/
155155
models: Record<string, IRenderedModel>
156156
/**
157-
* A map of variant names to maps of rendered models
157+
* A map of variant UUIDs to maps of rendered models
158158
*/
159159
variantModels: Record<string, Record<string, IRenderedBoneVariant>>
160160
/**
@@ -729,7 +729,7 @@ export function renderRig(modelExportFolder: string, textureExportFolder: string
729729

730730
for (const variant of Variant.all) {
731731
if (variant.isDefault) continue // Don't export the default variant, it's redundant data.
732-
rig.variantModels[variant.name] = renderVariantModels(variant, rig)
732+
rig.variantModels[variant.uuid] = renderVariantModels(variant, rig)
733733
}
734734

735735
TEXTURE_RESOURCE_LOCATION_CACHE.clear()

src/variants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ export class Variant {
136136

137137
public toJSON(): IBlueprintVariantJSON {
138138
return {
139-
display_name: this.displayName,
140139
name: this.name,
140+
display_name: this.displayName,
141141
uuid: this.uuid,
142142
texture_map: Object.fromEntries(this.textureMap.map),
143143
excluded_nodes: this.excludedNodes.map(item => item.value),

test_blueprints/armor_stand.ajblueprint

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"meta": {
33
"format": "animated_java_blueprint",
4-
"format_version": "0.5.9",
4+
"format_version": "0.5.10",
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"
@@ -11,7 +11,7 @@
1111
"show_bounding_box": false,
1212
"auto_bounding_box": true,
1313
"bounding_box": [95, 32],
14-
"enable_plugin_mode": false,
14+
"enable_plugin_mode": true,
1515
"resource_pack_export_mode": "raw",
1616
"data_pack_export_mode": "raw",
1717
"display_item": "minecraft:white_dye",
@@ -27,7 +27,7 @@
2727
"interpolation_duration": 1,
2828
"teleportation_duration": 1,
2929
"use_storage_for_animation": false,
30-
"baked_animations": true,
30+
"baked_animations": false,
3131
"json_file": "D:\\github-repos\\animated-java\\animated-java\\dist\\test.json",
3232
"customModelDataOffset": 0,
3333
"custom_summon_commands": ""
@@ -1594,16 +1594,16 @@
15941594
],
15951595
"variants": {
15961596
"default": {
1597-
"display_name": "Default",
15981597
"name": "default",
1598+
"display_name": "Default",
15991599
"uuid": "99583e4c-1e3a-b03f-a802-1b5212a6eedb",
16001600
"texture_map": {},
16011601
"excluded_nodes": []
16021602
},
16031603
"list": [
16041604
{
1605-
"display_name": "no_armor",
16061605
"name": "no_armor",
1606+
"display_name": "no_armor",
16071607
"uuid": "5417306e-2c69-3f36-1e3c-edd904034a36",
16081608
"texture_map": {
16091609
"240844f3-f615-fe51-0ada-d208791fbdc0": "797174ae-5c58-4a83-a630-eefd51007c80",
@@ -1612,8 +1612,8 @@
16121612
"excluded_nodes": []
16131613
},
16141614
{
1615-
"display_name": "no_baseplate",
16161615
"name": "no_baseplate",
1616+
"display_name": "no_baseplate",
16171617
"uuid": "bf2a6915-ec63-7ccf-3844-ea8be00b97e6",
16181618
"texture_map": {
16191619
"eb6c49b8-8e8e-a039-9a6f-ef6a06bc7924": "797174ae-5c58-4a83-a630-eefd51007c80"
@@ -1633,8 +1633,8 @@
16331633
]
16341634
},
16351635
{
1636-
"display_name": "colors",
16371636
"name": "colors",
1637+
"display_name": "colors",
16381638
"uuid": "49521f4b-b970-e4bd-b594-2e05d2d46027",
16391639
"texture_map": {},
16401640
"excluded_nodes": []

0 commit comments

Comments
 (0)