@@ -64,100 +64,131 @@ public static LitematicFile load(Path file) throws IOException {
6464 else if (!(versionTag instanceof IntTag ))
6565 throw new IOException ("Version tag is not an integer" );
6666
67-
6867 Tag metadataTag = root .get ("Metadata" );
6968 if (metadataTag == null )
7069 throw new IOException ("Metadata tag not found" );
7170 else if (!(metadataTag instanceof CompoundTag ))
7271 throw new IOException ("Metadata tag is not a compound tag" );
7372
74- return new LitematicFile (file , root );
73+ int regions = 0 ;
74+ Tag regionsTag = root .get ("Regions" );
75+ if (regionsTag instanceof CompoundTag )
76+ regions = ((CompoundTag ) regionsTag ).size ();
77+
78+ return new LitematicFile (file , (CompoundTag ) metadataTag ,
79+ ((IntTag ) versionTag ).getValue (),
80+ tryGetInt (root .get ("SubVersion" )),
81+ tryGetInt (root .get ("MinecraftDataVersion" )),
82+ regions
83+ );
7584 }
7685
7786 private final @ NotNull Path file ;
78- private final @ NotNull CompoundTag root ;
7987
80- private LitematicFile (@ NotNull Path file , @ NotNull CompoundTag root ) {
88+ private final int version ;
89+ private final int subVersion ;
90+ private final int minecraftDataVersion ;
91+ private final int regionCount ;
92+ private final int [] previewImageData ;
93+ private final String name ;
94+ private final String author ;
95+ private final String description ;
96+ private final Instant timeCreated ;
97+ private final Instant timeModified ;
98+ private final int totalBlocks ;
99+ private final int totalVolume ;
100+ private final Point3D enclosingSize ;
101+
102+ private LitematicFile (@ NotNull Path file , @ NotNull CompoundTag metadata ,
103+ int version , int subVersion , int minecraftDataVersion , int regionCount ) {
81104 this .file = file ;
82- this .root = root ;
83- }
105+ this .version = version ;
106+ this .subVersion = subVersion ;
107+ this .minecraftDataVersion = minecraftDataVersion ;
108+ this .regionCount = regionCount ;
109+
110+ Tag previewImageData = metadata .get ("PreviewImageData" );
111+ this .previewImageData = previewImageData instanceof IntArrayTag
112+ ? ((IntArrayTag ) previewImageData ).getValue ()
113+ : null ;
114+
115+ this .name = tryGetString (metadata .get ("Name" ));
116+ this .author = tryGetString (metadata .get ("Author" ));
117+ this .description = tryGetString (metadata .get ("Description" ));
118+ this .timeCreated = tryGetLongTimestamp (metadata .get ("TimeCreated" ));
119+ this .timeModified = tryGetLongTimestamp (metadata .get ("TimeModified" ));
120+ this .totalBlocks = tryGetInt (metadata .get ("TotalBlocks" ));
121+ this .totalVolume = tryGetInt (metadata .get ("TotalVolume" ));
122+
123+
124+ Point3D enclosingSize = null ;
125+ Tag enclosingSizeTag = metadata .get ("EnclosingSize" );
126+ if (enclosingSizeTag instanceof CompoundTag ) {
127+ CompoundTag list = (CompoundTag ) enclosingSizeTag ;
128+ int x = tryGetInt (list .get ("x" ));
129+ int y = tryGetInt (list .get ("y" ));
130+ int z = tryGetInt (list .get ("z" ));
131+
132+ if (x >= 0 && y >= 0 && z >= 0 )
133+ enclosingSize = new Point3D (x , y , z );
134+ }
135+ this .enclosingSize = enclosingSize ;
84136
85- private @ NotNull CompoundTag getMetadata () {
86- return root .get ("Metadata" );
87137 }
88138
89139 public @ NotNull Path getFile () {
90140 return file ;
91141 }
92142
93143 public int getVersion () {
94- return root .< IntTag > get ( "Version" ). getValue () ;
144+ return version ;
95145 }
96146
97147 public int getSubVersion () {
98- return tryGetInt ( root . get ( "SubVersion" )) ;
148+ return subVersion ;
99149 }
100150
101151 public int getMinecraftDataVersion () {
102- return tryGetInt ( root . get ( "MinecraftDataVersion" )) ;
152+ return minecraftDataVersion ;
103153 }
104154
105155 public int [] getPreviewImageData () {
106- Tag previewImageData = getMetadata ().get ("PreviewImageData" );
107- if (previewImageData instanceof IntArrayTag ) {
108- return ((IntArrayTag ) previewImageData ).getValue ().clone ();
109- } else {
110- return null ;
111- }
156+ return previewImageData != null ? previewImageData .clone () : null ;
112157 }
113158
114159 public String getName () {
115- return tryGetString ( getMetadata (). get ( "Name" )) ;
160+ return name ;
116161 }
117162
118163 public String getAuthor () {
119- return tryGetString ( getMetadata (). get ( "Author" )) ;
164+ return author ;
120165 }
121166
122167 public String getDescription () {
123- return tryGetString ( getMetadata (). get ( "Description" )) ;
168+ return description ;
124169 }
125170
126171 public Instant getTimeCreated () {
127- return tryGetLongTimestamp ( getMetadata (). get ( "TimeCreated" )) ;
172+ return timeCreated ;
128173 }
129174
130175 public Instant getTimeModified () {
131- return tryGetLongTimestamp ( getMetadata (). get ( "TimeModified" )) ;
176+ return timeModified ;
132177 }
133178
134179 public int getTotalBlocks () {
135- return tryGetInt ( getMetadata (). get ( "TotalBlocks" )) ;
180+ return totalBlocks ;
136181 }
137182
138183 public int getTotalVolume () {
139- return tryGetInt ( getMetadata (). get ( "TotalVolume" )) ;
184+ return totalVolume ;
140185 }
141186
142187 public Point3D getEnclosingSize () {
143- Tag enclosingSizeTag = getMetadata ().get ("EnclosingSize" );
144- if (enclosingSizeTag instanceof CompoundTag ) {
145- CompoundTag list = (CompoundTag ) enclosingSizeTag ;
146- int x = tryGetInt (list .get ("x" ));
147- int y = tryGetInt (list .get ("y" ));
148- int z = tryGetInt (list .get ("z" ));
149-
150- if (x >= 0 && y >= 0 && z >= 0 )
151- return new Point3D (x , y , z );
152- }
153-
154- return null ;
188+ return enclosingSize ;
155189 }
156190
157191 public int getRegionCount () {
158- Tag regions = root .get ("Regions" );
159- if (regions instanceof CompoundTag )
160- return ((CompoundTag ) regions ).size ();
161- else return 0 ;
192+ return regionCount ;
162193 }
163194}
0 commit comments