@@ -13,7 +13,13 @@ import {
1313 sortObjectKeys ,
1414} from './util'
1515import { 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'
1723import { JsonText } from './minecraft/jsonText'
1824import { MAX_PROGRESS , PROGRESS , PROGRESS_DESCRIPTION } from '../interface/exportProgressDialog'
1925import { roundTo } from '../util/misc'
@@ -531,7 +537,6 @@ export async function compileDataPack(options: {
531537 for ( const file of ajmeta . oldDatapack . files ) {
532538 if ( ! isFunctionTagPath ( file ) ) {
533539 if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
534- PROGRESS . set ( PROGRESS . get ( ) + 1 )
535540 } else if ( aj . export_namespace !== Project ! . last_used_export_namespace ) {
536541 const resourceLocation = parseDataPackPath ( file ) ! . resourceLocation
537542 if (
@@ -550,7 +555,6 @@ export async function compileDataPack(options: {
550555 await fs . promises . copyFile ( file , newPath )
551556 await fs . promises . unlink ( file )
552557 }
553- PROGRESS . set ( PROGRESS . get ( ) + 1 )
554558 }
555559 let folder = PathModule . dirname ( file )
556560 while (
@@ -562,6 +566,7 @@ export async function compileDataPack(options: {
562566 removedFolders . add ( folder )
563567 folder = PathModule . dirname ( folder )
564568 }
569+ PROGRESS . set ( PROGRESS . get ( ) + 1 )
565570 }
566571
567572 const exportedFiles = new Map < string , string > ( )
@@ -618,14 +623,14 @@ export async function compileDataPack(options: {
618623
619624 PROGRESS_DESCRIPTION . set ( 'Writing Data Pack...' )
620625 console . time ( 'Writing Files took' )
621- await writeFiles ( exportedFiles )
626+ await writeFiles ( exportedFiles , options . dataPackFolder )
622627 console . timeEnd ( 'Writing Files took' )
623628
624629 ajmeta . write ( )
625630 console . timeEnd ( 'Data Pack Compilation took' )
626631}
627632
628- async function writeFiles ( map : Map < string , string > ) {
633+ async function writeFiles ( map : Map < string , string > , dataPackFolder : string ) {
629634 PROGRESS . set ( 0 )
630635 MAX_PROGRESS . set ( map . size )
631636 const aj = Project ! . animated_java
@@ -636,6 +641,7 @@ async function writeFiles(map: Map<string, string>) {
636641 const oldFile : IFunctionTag = JSON . parse ( fs . readFileSync ( path , 'utf-8' ) )
637642 const newFile : IFunctionTag = JSON . parse ( content )
638643 const merged = mergeTag ( oldFile , newFile )
644+ // console.log('Merged Function Tag:', path, merged)
639645 if ( aj . export_namespace !== Project ! . last_used_export_namespace ) {
640646 merged . values = merged . values . filter ( v => {
641647 const value = typeof v === 'string' ? v : v . id
@@ -647,6 +653,28 @@ async function writeFiles(map: Map<string, string>) {
647653 )
648654 } )
649655 }
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+ } )
650678 content = JSON . stringify ( merged )
651679 }
652680
0 commit comments