@@ -4,7 +4,7 @@ import { TRANSPARENT_TEXTURE, Variant } from '../../variants'
4
4
import { IntentionalExportError } from '../exporter'
5
5
import { IItemDefinition } from '../minecraft/itemDefinitions'
6
6
import { type ITextureAtlas } from '../minecraft/textureAtlas'
7
- import { IRenderedNodes , IRenderedRig } from '../rigRenderer'
7
+ import { IRenderedNodes , IRenderedRig , IRenderedVariantModel } from '../rigRenderer'
8
8
import { zip } from '../util'
9
9
import { ResourcePackAJMeta } from './global'
10
10
@@ -148,42 +148,20 @@ export default async function compileResourcePack(options: {
148
148
149
149
// Item Model Definitions
150
150
const defaultVariant = Variant . getDefault ( )
151
+
151
152
for ( const [ boneUuid , model ] of Object . entries ( rig . variants [ defaultVariant . uuid ] . models ) ) {
152
153
const bone = rig . nodes [ boneUuid ] as IRenderedNodes [ 'Bone' ]
153
154
const exportPath = PathModule . join ( itemModelDefinitionsFolder , bone . name + '.json' )
154
- const modelDefinition = {
155
- model : {
156
- type : 'minecraft:select' ,
157
- property : 'minecraft:custom_model_data' ,
158
- cases : [ ] ,
159
- fallback : {
160
- type : 'minecraft:model' ,
161
- model : model . resource_location ,
162
- } ,
163
- tints : [
164
- {
165
- type : 'minecraft:dye' ,
166
- default : [ 1 , 1 , 1 ] ,
167
- } ,
168
- ] ,
169
- } ,
170
- } as IItemDefinition & {
171
- model : { type : 'minecraft:select' ; property : 'minecraft:custom_model_data' }
172
- }
173
155
174
- for ( const variant of Object . values ( rig . variants ) ) {
175
- const variantModel = variant . models [ boneUuid ]
176
- if ( ! variantModel || variant . is_default ) continue
177
- modelDefinition . model . cases . push ( {
178
- when : variant . name ,
179
- model : {
180
- type : 'minecraft:model' ,
181
- model : variantModel . resource_location ,
182
- } ,
183
- } as ( typeof modelDefinition . model . cases ) [ 0 ] )
156
+ let itemDefinition : IItemDefinition
157
+
158
+ if ( Object . values ( rig . variants ) . length === 1 ) {
159
+ itemDefinition = createSingleVariantItemDefinition ( model )
160
+ } else {
161
+ itemDefinition = createMultiVariantItemDefinition ( boneUuid , model , rig )
184
162
}
185
163
186
- exportedFiles . set ( exportPath , autoStringify ( modelDefinition ) )
164
+ exportedFiles . set ( exportPath , autoStringify ( itemDefinition ) )
187
165
}
188
166
189
167
// Variant Models
@@ -250,3 +228,58 @@ export default async function compileResourcePack(options: {
250
228
251
229
console . log ( 'Resource pack compiled!' )
252
230
}
231
+
232
+ function createSingleVariantItemDefinition ( model : IRenderedVariantModel ) : IItemDefinition {
233
+ return {
234
+ model : {
235
+ type : 'minecraft:model' ,
236
+ model : model . resource_location ,
237
+ tints : [
238
+ {
239
+ type : 'minecraft:dye' ,
240
+ default : [ 1 , 1 , 1 ] ,
241
+ } ,
242
+ ] ,
243
+ } ,
244
+ }
245
+ }
246
+
247
+ function createMultiVariantItemDefinition (
248
+ boneUUID : string ,
249
+ model : IRenderedVariantModel ,
250
+ rig : IRenderedRig
251
+ ) : IItemDefinition {
252
+ const itemDefinition : IItemDefinition & {
253
+ model : { type : 'minecraft:select' ; property : 'minecraft:custom_model_data' }
254
+ } = {
255
+ model : {
256
+ type : 'minecraft:select' ,
257
+ property : 'minecraft:custom_model_data' ,
258
+ cases : [ ] ,
259
+ fallback : {
260
+ type : 'minecraft:model' ,
261
+ model : model . resource_location ,
262
+ } ,
263
+ tints : [
264
+ {
265
+ type : 'minecraft:dye' ,
266
+ default : [ 1 , 1 , 1 ] ,
267
+ } ,
268
+ ] ,
269
+ } ,
270
+ }
271
+
272
+ for ( const variant of Object . values ( rig . variants ) ) {
273
+ const variantModel = variant . models [ boneUUID ]
274
+ if ( ! variantModel || variant . is_default ) continue
275
+ itemDefinition . model . cases . push ( {
276
+ when : variant . name ,
277
+ model : {
278
+ type : 'minecraft:model' ,
279
+ model : variantModel . resource_location ,
280
+ } ,
281
+ } as ( typeof itemDefinition . model . cases ) [ 0 ] )
282
+ }
283
+
284
+ return itemDefinition
285
+ }
0 commit comments