@@ -8,11 +8,11 @@ import { Variant } from '../../variants'
8
8
import { NbtByte , NbtCompound , NbtFloat , NbtInt , NbtList , NbtString } from 'deepslate/lib/nbt'
9
9
import {
10
10
arrayToNbtFloatArray ,
11
+ getFunctionNamespace ,
11
12
matrixToNbtFloatArray ,
12
13
replacePathPart ,
13
14
sortObjectKeys ,
14
15
transformationToNbt ,
15
- zip ,
16
16
} from '../util'
17
17
import { BoneConfig , TextDisplayConfig } from '../../nodeConfigs'
18
18
import {
@@ -26,7 +26,6 @@ import {
26
26
import { JsonText } from '../minecraft/jsonText'
27
27
import { MAX_PROGRESS , PROGRESS , PROGRESS_DESCRIPTION } from '../../interface/exportProgressDialog'
28
28
import { eulerFromQuaternion , floatToHex , roundTo , tinycolorToDecimal } from '../../util/misc'
29
- import { setTimeout } from 'timers'
30
29
import { MSLimiter } from '../../util/msLimiter'
31
30
32
31
const BONE_TYPES = [ 'bone' , 'text_display' , 'item_display' , 'block_display' ]
@@ -616,7 +615,9 @@ export default async function compileDataPack(options: {
616
615
animationHash : string
617
616
} ) {
618
617
console . time ( 'Data Pack Compilation took' )
619
- const { rig, animations, rigHash, animationHash } = options
618
+ const { rig, animations, rigHash, animationHash, dataPackFolder } = options
619
+ const overrideFolder = PathModule . join ( dataPackFolder , 'animated_java' )
620
+
620
621
const aj = Project ! . animated_java
621
622
console . log ( 'Compiling Data Pack...' , options )
622
623
const compiler = new Compiler ( 'src/' , {
@@ -635,10 +636,10 @@ export default async function compileDataPack(options: {
635
636
let ajmeta : DataPackAJMeta | null = null
636
637
if ( aj . data_pack_export_mode === 'raw' ) {
637
638
ajmeta = new DataPackAJMeta (
638
- PathModule . join ( options . dataPackFolder , 'data.ajmeta' ) ,
639
+ PathModule . join ( dataPackFolder , 'data.ajmeta' ) ,
639
640
aj . export_namespace ,
640
641
Project ! . last_used_export_namespace ,
641
- options . dataPackFolder
642
+ dataPackFolder
642
643
)
643
644
ajmeta . read ( )
644
645
@@ -698,7 +699,7 @@ export default async function compileDataPack(options: {
698
699
function createSyncIO ( ) : SyncIo {
699
700
const io = new SyncIo ( )
700
701
io . write = ( localPath , content ) => {
701
- const writePath = PathModule . join ( options . dataPackFolder , localPath )
702
+ const writePath = PathModule . join ( overrideFolder , localPath )
702
703
exportedFiles . set ( writePath , content )
703
704
if ( ajmeta ) ajmeta . files . add ( writePath )
704
705
}
@@ -753,56 +754,98 @@ export default async function compileDataPack(options: {
753
754
754
755
PROGRESS_DESCRIPTION . set ( 'Compiling Data Pack...' )
755
756
PROGRESS . set ( 0 )
756
- await new Promise ( resolve => setTimeout ( resolve , 2000 / framespersecond ) )
757
+ await new Promise ( resolve => requestAnimationFrame ( resolve ) )
757
758
console . time ( 'MC-Build Compiler took' )
758
759
const tokens = Tokenizer . tokenize ( mcbFile , 'src/animated_java.mcb' )
759
760
compiler . addFile ( 'src/animated_java.mcb' , Parser . parseMcbFile ( tokens ) )
760
761
compiler . compile ( VariableMap . fromObject ( variables ) )
761
762
console . timeEnd ( 'MC-Build Compiler took' )
762
763
764
+ // Incorrect version warning
765
+ const functionNamespace = getFunctionNamespace ( aj . target_minecraft_version )
766
+ const invalidVersionMessage = new JsonText ( [
767
+ TELLRAW_ERROR_PREFIX ( ) ,
768
+ [
769
+ {
770
+ text : 'Attempting to load an Animated Java Data Pack that was exported for ' ,
771
+ color : 'red' ,
772
+ } ,
773
+ { text : `Minecraft ${ aj . target_minecraft_version } ` , color : 'aqua' } ,
774
+ { text : ' in an different version!' , color : 'red' } ,
775
+ {
776
+ text : '\n Please ensure that the data pack is loaded in the correct version, or that your blueprint settings are configured to target the correct version(s) of Minecraft.' ,
777
+ color : 'yellow' ,
778
+ } ,
779
+ ] ,
780
+ TELLRAW_SUFFIX ( ) ,
781
+ ] )
782
+ exportedFiles . set (
783
+ PathModule . join (
784
+ dataPackFolder ,
785
+ `data/animated_java/${ functionNamespace } /global/on_load.mcfunction`
786
+ ) ,
787
+ `tellraw @a ${ invalidVersionMessage } `
788
+ )
789
+ exportedFiles . set (
790
+ PathModule . join ( dataPackFolder , `data/minecraft/tags/${ functionNamespace } /load.json` ) ,
791
+ autoStringify ( {
792
+ replace : false ,
793
+ values : [ 'animated_java:global/on_load' ] ,
794
+ } )
795
+ )
796
+
797
+ interface IPackMeta {
798
+ pack ?: {
799
+ pack_format ?: number
800
+ description ?: string
801
+ }
802
+ overlays ?: {
803
+ entries ?: Array < {
804
+ directory ?: string
805
+ formats ?: number | number [ ] | { min_inclusive : number ; max_inclusive : number }
806
+ } >
807
+ }
808
+ }
809
+
810
+ // pack.mcmeta
811
+ const packMetaPath = PathModule . join ( dataPackFolder , 'pack.mcmeta' )
812
+ let packMeta = { } as IPackMeta
813
+ if ( fs . existsSync ( packMetaPath ) ) {
814
+ try {
815
+ const content = fs . readFileSync ( packMetaPath , 'utf-8' )
816
+ packMeta = JSON . parse ( content )
817
+ } catch ( e ) {
818
+ console . error ( 'Failed to parse pack.mcmeta:' , e )
819
+ }
820
+ }
821
+ packMeta . pack ??= { }
822
+ packMeta . pack . pack_format = getDataPackFormat ( aj . target_minecraft_version )
823
+ packMeta . pack . description ??= `Animated Java Data Pack for ${ aj . target_minecraft_version } `
824
+ packMeta . overlays ??= { }
825
+ packMeta . overlays . entries ??= [ ]
826
+ const overlay = packMeta . overlays . entries . find ( e => e . directory === 'animated_java' )
827
+ if ( ! overlay ) {
828
+ packMeta . overlays . entries . push ( {
829
+ directory : 'animated_java' ,
830
+ formats : getDataPackFormat ( aj . target_minecraft_version ) ,
831
+ } )
832
+ } else {
833
+ overlay . formats = getDataPackFormat ( aj . target_minecraft_version )
834
+ }
835
+
836
+ exportedFiles . set ( PathModule . join ( dataPackFolder , 'pack.mcmeta' ) , autoStringify ( packMeta ) )
837
+
763
838
PROGRESS_DESCRIPTION . set ( 'Writing Data Pack...' )
764
839
if ( aj . data_pack_export_mode === 'raw' ) {
765
840
console . time ( 'Writing Files took' )
766
- await writeFiles ( exportedFiles , options . dataPackFolder )
841
+ await writeFiles ( exportedFiles , overrideFolder )
767
842
console . timeEnd ( 'Writing Files took' )
768
843
ajmeta ! . write ( )
769
- } else if ( aj . data_pack_export_mode === 'zip' ) {
770
- exportedFiles . set (
771
- PathModule . join ( options . dataPackFolder , 'pack.mcmeta' ) ,
772
- autoStringify ( {
773
- pack : {
774
- pack_format : 48 ,
775
- description : `${ Project ! . name } . Generated with Animated Java` ,
776
- } ,
777
- } )
778
- )
779
-
780
- const exportPath =
781
- options . dataPackFolder + ( options . dataPackFolder . endsWith ( '.zip' ) ? '' : '.zip' )
782
- console . time ( 'Writing Zip took' )
783
- await writeZip ( exportedFiles , exportPath )
784
- console . timeEnd ( 'Writing Zip took' )
785
844
}
786
845
787
846
console . timeEnd ( 'Data Pack Compilation took' )
788
847
}
789
848
790
- async function writeZip ( map : Map < string , string > , dataPackPath : string ) {
791
- const data : Record < string , Uint8Array > = { }
792
-
793
- for ( const [ path , content ] of map ) {
794
- const relativePath = PathModule . relative ( dataPackPath , path )
795
- if ( typeof content === 'string' ) {
796
- data [ relativePath ] = Buffer . from ( content )
797
- } else {
798
- data [ relativePath ] = content
799
- }
800
- }
801
-
802
- const zipped = await zip ( data , { } )
803
- await fs . promises . writeFile ( dataPackPath , zipped )
804
- }
805
-
806
849
async function writeFiles ( map : Map < string , string > , dataPackFolder : string ) {
807
850
PROGRESS . set ( 0 )
808
851
MAX_PROGRESS . set ( map . size )
@@ -829,10 +872,7 @@ async function writeFiles(map: Map<string, string>, dataPackFolder: string) {
829
872
const value = typeof v === 'string' ? v : v . id
830
873
const isTag = value . startsWith ( '#' )
831
874
const location = parseResourceLocation ( isTag ? value . substring ( 1 ) : value )
832
- // If the target version is 1.21.0 or higher, use the 'function' namespace instead of 'functions'
833
- const functionNamespace = compareVersions ( aj . target_minecraft_version , '1.21.0' )
834
- ? 'function'
835
- : 'functions'
875
+ const functionNamespace = getFunctionNamespace ( aj . target_minecraft_version )
836
876
console . log ( 'Checking:' , value , location , functionNamespace )
837
877
const vPath = PathModule . join (
838
878
dataPackFolder ,
0 commit comments