@@ -13,7 +13,13 @@ import {
13
13
sortObjectKeys ,
14
14
} from './util'
15
15
import { BoneConfig , TextDisplayConfig } from '../nodeConfigs'
16
- import { IFunctionTag , mergeTag , parseBlock , parseDataPackPath } from '../util/minecraftUtil'
16
+ import {
17
+ IFunctionTag ,
18
+ mergeTag ,
19
+ parseBlock ,
20
+ parseDataPackPath ,
21
+ parseResourceLocation ,
22
+ } from '../util/minecraftUtil'
17
23
import { JsonText } from './minecraft/jsonText'
18
24
import { MAX_PROGRESS , PROGRESS , PROGRESS_DESCRIPTION } from '../interface/exportProgressDialog'
19
25
import { roundTo } from '../util/misc'
@@ -531,7 +537,6 @@ export async function compileDataPack(options: {
531
537
for ( const file of ajmeta . oldDatapack . files ) {
532
538
if ( ! isFunctionTagPath ( file ) ) {
533
539
if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
534
- PROGRESS . set ( PROGRESS . get ( ) + 1 )
535
540
} else if ( aj . export_namespace !== Project ! . last_used_export_namespace ) {
536
541
const resourceLocation = parseDataPackPath ( file ) ! . resourceLocation
537
542
if (
@@ -550,7 +555,6 @@ export async function compileDataPack(options: {
550
555
await fs . promises . copyFile ( file , newPath )
551
556
await fs . promises . unlink ( file )
552
557
}
553
- PROGRESS . set ( PROGRESS . get ( ) + 1 )
554
558
}
555
559
let folder = PathModule . dirname ( file )
556
560
while (
@@ -562,6 +566,7 @@ export async function compileDataPack(options: {
562
566
removedFolders . add ( folder )
563
567
folder = PathModule . dirname ( folder )
564
568
}
569
+ PROGRESS . set ( PROGRESS . get ( ) + 1 )
565
570
}
566
571
567
572
const exportedFiles = new Map < string , string > ( )
@@ -618,14 +623,14 @@ export async function compileDataPack(options: {
618
623
619
624
PROGRESS_DESCRIPTION . set ( 'Writing Data Pack...' )
620
625
console . time ( 'Writing Files took' )
621
- await writeFiles ( exportedFiles )
626
+ await writeFiles ( exportedFiles , options . dataPackFolder )
622
627
console . timeEnd ( 'Writing Files took' )
623
628
624
629
ajmeta . write ( )
625
630
console . timeEnd ( 'Data Pack Compilation took' )
626
631
}
627
632
628
- async function writeFiles ( map : Map < string , string > ) {
633
+ async function writeFiles ( map : Map < string , string > , dataPackFolder : string ) {
629
634
PROGRESS . set ( 0 )
630
635
MAX_PROGRESS . set ( map . size )
631
636
const aj = Project ! . animated_java
@@ -636,6 +641,7 @@ async function writeFiles(map: Map<string, string>) {
636
641
const oldFile : IFunctionTag = JSON . parse ( fs . readFileSync ( path , 'utf-8' ) )
637
642
const newFile : IFunctionTag = JSON . parse ( content )
638
643
const merged = mergeTag ( oldFile , newFile )
644
+ // console.log('Merged Function Tag:', path, merged)
639
645
if ( aj . export_namespace !== Project ! . last_used_export_namespace ) {
640
646
merged . values = merged . values . filter ( v => {
641
647
const value = typeof v === 'string' ? v : v . id
@@ -647,6 +653,28 @@ async function writeFiles(map: Map<string, string>) {
647
653
)
648
654
} )
649
655
}
656
+ merged . values = merged . values . filter ( v => {
657
+ const value = typeof v === 'string' ? v : v . id
658
+ const isTag = value . startsWith ( '#' )
659
+ const location = parseResourceLocation ( isTag ? value . substring ( 1 ) : value )
660
+ const vPath = PathModule . join (
661
+ dataPackFolder ,
662
+ 'data' ,
663
+ location . namespace ,
664
+ isTag ? 'tags/function' : 'function' ,
665
+ location . path + ( isTag ? '.json' : '.mcfunction' )
666
+ )
667
+ const exists = map . has ( vPath ) || fs . existsSync ( vPath )
668
+ if ( ! exists ) {
669
+ const parentLocation = parseDataPackPath ( path )
670
+ console . warn (
671
+ `The referenced ${ isTag ? 'tag' : 'function' } '${ value } ' in '${
672
+ parentLocation ?. resourceLocation || path
673
+ } ' does not exist! Removing reference...`
674
+ )
675
+ }
676
+ return exists
677
+ } )
650
678
content = JSON . stringify ( merged )
651
679
}
652
680
0 commit comments