Skip to content

Commit a7b1753

Browse files
committed
🛠️ Fix #348
1 parent 5d24c77 commit a7b1753

File tree

1 file changed

+64
-31
lines changed

1 file changed

+64
-31
lines changed

src/systems/resourcepackCompiler/1.21.4.ts

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TRANSPARENT_TEXTURE, Variant } from '../../variants'
44
import { IntentionalExportError } from '../exporter'
55
import { IItemDefinition } from '../minecraft/itemDefinitions'
66
import { type ITextureAtlas } from '../minecraft/textureAtlas'
7-
import { IRenderedNodes, IRenderedRig } from '../rigRenderer'
7+
import { IRenderedNodes, IRenderedRig, IRenderedVariantModel } from '../rigRenderer'
88
import { zip } from '../util'
99
import { ResourcePackAJMeta } from './global'
1010

@@ -148,42 +148,20 @@ export default async function compileResourcePack(options: {
148148

149149
// Item Model Definitions
150150
const defaultVariant = Variant.getDefault()
151+
151152
for (const [boneUuid, model] of Object.entries(rig.variants[defaultVariant.uuid].models)) {
152153
const bone = rig.nodes[boneUuid] as IRenderedNodes['Bone']
153154
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-
}
173155

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)
184162
}
185163

186-
exportedFiles.set(exportPath, autoStringify(modelDefinition))
164+
exportedFiles.set(exportPath, autoStringify(itemDefinition))
187165
}
188166

189167
// Variant Models
@@ -250,3 +228,58 @@ export default async function compileResourcePack(options: {
250228

251229
console.log('Resource pack compiled!')
252230
}
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

Comments
 (0)