@@ -31,52 +31,25 @@ export default async function compileResourcePack(options: {
3131 )
3232 if ( aj . resource_pack_export_mode === 'raw' ) {
3333 ajmeta . read ( )
34-
35- PROGRESS_DESCRIPTION . set ( 'Removing Old Resource Pack Files...' )
36- PROGRESS . set ( 0 )
37- MAX_PROGRESS . set ( ajmeta . oldFiles . size )
38-
39- const removedFolders = new Set < string > ( )
40- for ( const file of ajmeta . oldFiles ) {
41- if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
42- let folder = PathModule . dirname ( file )
43- while (
44- ! removedFolders . has ( folder ) &&
45- fs . existsSync ( folder ) &&
46- ( await fs . promises . readdir ( folder ) ) . length === 0
47- ) {
48- await fs . promises . rm ( folder , { recursive : true } )
49- removedFolders . add ( folder )
50- folder = PathModule . dirname ( folder )
51- }
52- PROGRESS . set ( PROGRESS . get ( ) + 1 )
53- }
5434 }
5535
5636 const exportedFiles = new Map < string , string | Buffer > ( )
5737
5838 // Texture atlas
59- const blockAtlasFile = PathModule . join (
39+ const blockAtlasPath = PathModule . join (
6040 resourcePackFolder ,
6141 'assets/minecraft/atlases/blocks.json'
6242 )
63- let blockAtlas : ITextureAtlas = { sources : [ ] }
64- if ( fs . existsSync ( blockAtlasFile ) ) {
65- const content = await fs . promises . readFile ( blockAtlasFile , 'utf-8' ) . catch ( ( ) => {
66- throw new IntentionalExportError (
67- 'Failed to read block atlas file after it was confirmed to exist!'
68- )
43+ const blockAtlas : ITextureAtlas = await fs . promises
44+ . readFile ( blockAtlasPath , 'utf-8' )
45+ . catch ( ( ) => {
46+ console . log ( 'Creating new block atlas...' )
47+ return '{ sources: [] }'
6948 } )
70- try {
71- blockAtlas = JSON . parse ( content )
72- } catch ( e : any ) {
73- throw new IntentionalExportError (
74- `Failed to parse block atlas file: ${ e . message as string } `
75- )
76- }
77- }
49+ . then ( content => JSON . parse ( content ) as ITextureAtlas )
50+
7851 if (
79- blockAtlas . sources . some (
52+ blockAtlas . sources ? .some (
8053 source =>
8154 source . type === 'directory' &&
8255 source . source === 'blueprint' &&
@@ -85,13 +58,14 @@ export default async function compileResourcePack(options: {
8558 ) {
8659 // Do nothing. The blueprint directory is already there.
8760 } else {
61+ blockAtlas . sources ??= [ ]
8862 blockAtlas . sources . push ( {
8963 type : 'directory' ,
9064 source : 'blueprint' ,
9165 prefix : 'blueprint/' ,
9266 } )
9367 }
94- exportedFiles . set ( blockAtlasFile , autoStringify ( blockAtlas ) )
68+ exportedFiles . set ( blockAtlasPath , autoStringify ( blockAtlas ) )
9569
9670 // Internal Models
9771 exportedFiles . set (
@@ -154,6 +128,12 @@ export default async function compileResourcePack(options: {
154128 ? PathModule . join ( correctedModelExportFolder , bone . name + '.json' )
155129 : PathModule . join ( correctedModelExportFolder , variant . name , bone . name + '.json' )
156130 // Hacky workaround for this version enforcing the `item` namespace.
131+ if ( variantModel . model ?. parent ) {
132+ variantModel . model . parent = variantModel . model . parent . replace (
133+ 'animated_java:blueprint/' ,
134+ 'animated_java:item/'
135+ )
136+ }
157137 variantModel . item_model = variantModel . item_model . replace (
158138 'animated_java:blueprint/' ,
159139 'animated_java:'
@@ -167,7 +147,30 @@ export default async function compileResourcePack(options: {
167147 // Do nothing
168148 console . log ( 'Plugin mode enabled. Skipping resource pack export.' )
169149 } else if ( aj . resource_pack_export_mode === 'raw' ) {
150+ // Clean up old files
151+ PROGRESS_DESCRIPTION . set ( 'Removing Old Resource Pack Files...' )
152+ PROGRESS . set ( 0 )
153+ MAX_PROGRESS . set ( ajmeta . oldFiles . size )
154+
155+ const removedFolders = new Set < string > ( )
156+ for ( const file of ajmeta . oldFiles ) {
157+ if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
158+ let folder = PathModule . dirname ( file )
159+ while (
160+ ! removedFolders . has ( folder ) &&
161+ fs . existsSync ( folder ) &&
162+ ( await fs . promises . readdir ( folder ) ) . length === 0
163+ ) {
164+ await fs . promises . rm ( folder , { recursive : true } )
165+ removedFolders . add ( folder )
166+ folder = PathModule . dirname ( folder )
167+ }
168+ PROGRESS . set ( PROGRESS . get ( ) + 1 )
169+ }
170+
171+ // Write new files
170172 ajmeta . files = new Set ( exportedFiles . keys ( ) )
173+ ajmeta . files . delete ( blockAtlasPath )
171174 ajmeta . write ( )
172175
173176 PROGRESS_DESCRIPTION . set ( 'Writing Resource Pack...' )
0 commit comments