Skip to content

Commit ede24f6

Browse files
committed
🛠️ Fix some resource pack conflicts
- Fixed assets.ajmeta resetting the display item model every time it's exported. - Fixed some assumptions made about the display item model.
1 parent df879a6 commit ede24f6

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/systems/resourcepackCompiler.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { IRenderedNodes, IRenderedRig } from './rigRenderer'
55
import { sortObjectKeys, zip } from './util'
66

77
interface IPredicateItemModel {
8-
parent: string
9-
textures: any
8+
parent?: string
9+
textures: Record<string, string>
1010
overrides: Array<{
1111
predicate: { custom_model_data: number }
1212
model: string
@@ -19,8 +19,8 @@ class PredicateItemModel {
1919
private overrides = new Map<number, string>()
2020
private externalOverrides = new Map<number, string>()
2121
public rigs: Record<string, number[]> = {}
22-
23-
// constructor() {}
22+
public parent? = 'item/generated'
23+
public textures: IPredicateItemModel['textures'] = {}
2424

2525
setOverride(id: number, model: string) {
2626
this.overrides.set(id, model)
@@ -52,6 +52,11 @@ class PredicateItemModel {
5252
// TODO Inform the user that they are attempting to merge into a non-animated_java model. And give them the option to cancel.
5353
}
5454

55+
// Assert parent
56+
if (file.parent) this.parent = file.parent
57+
// Assert textures
58+
if (file.textures) this.textures = file.textures
59+
5560
// Assert important fields
5661
file.overrides ??= []
5762
file.animated_java ??= {}
@@ -99,10 +104,13 @@ class PredicateItemModel {
99104
const exportNamespace = Project!.animated_java.export_namespace
100105

101106
return {
102-
parent: 'item/generated',
103-
textures: {
104-
layer0: `${displayItemNamespace}:item/${displayItemName}`,
105-
},
107+
parent: this.parent,
108+
textures:
109+
Object.keys(this.textures).length > 0
110+
? this.textures
111+
: {
112+
layer0: `${displayItemNamespace}:item/${displayItemName}`,
113+
},
106114
overrides: [...this.externalOverrides.entries(), ...this.overrides.entries()]
107115
.sort((a, b) => a[0] - b[0])
108116
.map(([id, model]) => ({
@@ -297,17 +305,17 @@ export async function compileResourcePack(options: {
297305
}
298306
}
299307

300-
// Write display item model
301-
console.log('Display Item Model', displayItemModel.toJSON())
302-
exportedFiles.set(displayItemPath, autoStringify(displayItemModel.toJSON()))
303-
304308
if (aj.enable_plugin_mode) {
305309
// Do nothing
306310
console.log('Plugin mode enabled. Skipping resource pack export.')
307311
} else if (aj.resource_pack_export_mode === 'raw') {
308312
ajmeta.files = new Set(exportedFiles.keys())
309313
ajmeta.write()
310314

315+
// Since we don't want to erase the display item every export, we add it's model file after the files have been added to the ajmeta.
316+
console.log('Display Item Model', displayItemModel.toJSON())
317+
exportedFiles.set(displayItemPath, autoStringify(displayItemModel.toJSON()))
318+
311319
PROGRESS_DESCRIPTION.set('Writing Resource Pack...')
312320
PROGRESS.set(0)
313321
MAX_PROGRESS.set(exportedFiles.size)

0 commit comments

Comments
 (0)