@@ -197,6 +197,7 @@ interface PredicateModel {
197197 layer0 : string
198198 }
199199 overrides : Override [ ]
200+ ajMeta : Record < string , ( number | [ number , number ] ) [ ] >
200201}
201202
202203let predicateIDMap = { }
@@ -209,35 +210,71 @@ async function exportPredicate(
209210 console . groupCollapsed ( 'Export Predicate Model' )
210211 const projectName = safeFunctionName ( ajSettings . projectName )
211212
213+ const predicateJSON = {
214+ parent : 'item/generated' ,
215+ textures : {
216+ layer0 : `item/${ ajSettings . rigItem . replace ( 'minecraft:' , '' ) } ` ,
217+ } ,
218+ overrides : [ ] ,
219+ ajMeta : { } ,
220+ }
221+ let usedIDs = [ ]
222+ function * idGen ( ) {
223+ let id = 1
224+ while ( true ) {
225+ if ( ! usedIDs . includes ( id ) ) yield id
226+ id ++
227+ }
228+ }
212229 if ( fs . existsSync ( ajSettings . predicateFilePath ) ) {
213230 const oldPredicate : PredicateModel = JSON . parse (
214231 await fs . promises . readFile ( ajSettings . predicateFilePath , {
215232 encoding : 'utf-8' ,
216233 } )
217234 )
218235 console . log ( oldPredicate )
236+ // @ts -ignore
237+ const data = oldPredicate ?. ajMeta || { }
238+ Object . entries ( data ) . forEach ( ( [ id , ids ] ) => {
239+ // @ts -ignore
240+ if ( id !== Project . UUID ) {
241+ for ( let i = 0 ; i < ids . length ; i ++ ) {
242+ if ( Array . isArray ( ids [ i ] ) ) {
243+ for ( let k = ids [ i ] [ 0 ] ; k <= ids [ i ] [ 1 ] ; k ++ ) {
244+ usedIDs . push ( k )
245+ }
246+ } else {
247+ usedIDs . push ( ids [ i ] )
248+ }
249+ }
250+ }
251+ } )
252+ // @ts -ignore
253+ delete data [ Project . UUID ]
254+ predicateJSON . ajMeta = data
255+ predicateJSON . overrides = oldPredicate . overrides . filter ( ( override ) => {
256+ return usedIDs . includes ( override . predicate . custom_model_data )
257+ } )
219258 }
220-
221- const predicateJSON = {
222- parent : 'item/generated' ,
223- textures : {
224- layer0 : `item/${ ajSettings . rigItem . replace ( 'minecraft:' , '' ) } ` ,
225- } ,
226- overrides : [ ] ,
227- }
228-
259+ const idGenerator = idGen ( )
260+ let myMeta = [ ]
229261 for ( const [ modelName , model ] of Object . entries ( models ) ) {
262+ // this will always be a number as the generator is infinite.
263+ model . aj . customModelData = idGenerator . next ( ) . value as number
230264 predicateJSON . overrides . push ( {
231265 predicate : { custom_model_data : model . aj . customModelData } ,
232266 model : getModelPath (
233267 path . join ( ajSettings . rigModelsExportFolder , modelName ) ,
234268 modelName
235269 ) ,
236270 } )
271+ myMeta . push ( model . aj . customModelData )
237272 }
238273
239274 for ( const [ variantName , variant ] of Object . entries ( variantModels ) )
240275 for ( const [ modelName , model ] of Object . entries ( variant ) ) {
276+ model . aj . customModelData = idGenerator . next ( ) . value as number
277+ myMeta . push ( model . aj . customModelData )
241278 predicateJSON . overrides . push ( {
242279 predicate : { custom_model_data : model . aj . customModelData } ,
243280 model : getModelPath (
@@ -250,7 +287,8 @@ async function exportPredicate(
250287 ) ,
251288 } )
252289 }
253-
290+ //@ts -ignore
291+ predicateJSON . ajMeta [ Project . UUID ] = myMeta
254292 Blockbench . writeFile ( ajSettings . predicateFilePath , {
255293 content : autoStringify ( predicateJSON ) ,
256294 custom_writer : null ,
0 commit comments