diff --git a/.gitignore b/.gitignore index bf59b54c..7a2ac475 100644 --- a/.gitignore +++ b/.gitignore @@ -77,10 +77,13 @@ local.properties # IDEA folder .idea/ +# .iml files +*.iml + # ignore javadoc for now doc/ # ignore out out/ -*.patch \ No newline at end of file +*.patch diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ae6575fa..62d4c053 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 77a041f6..622ab64a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Mar 29 16:28:10 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/gradlew b/gradlew index 4453ccea..fbd7c515 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,16 +44,16 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -66,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -109,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -138,35 +156,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Escape application args -save ( ) { +save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d6..a9f778a7 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -65,6 +84,7 @@ set CMD_LINE_ARGS=%* set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% diff --git a/src/main/java/net/querz/mca/Chunk.java b/src/main/java/net/querz/mca/Chunk.java index 6a9873a5..d305df04 100644 --- a/src/main/java/net/querz/mca/Chunk.java +++ b/src/main/java/net/querz/mca/Chunk.java @@ -12,11 +12,14 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.Arrays; +import static net.querz.mca.LoadFlags.*; public class Chunk { public static final int DEFAULT_DATA_VERSION = 1628; + private boolean partial; + private int lastMCAUpdate; private CompoundTag data; @@ -49,10 +52,10 @@ public class Chunk { */ public Chunk(CompoundTag data) { this.data = data; - initReferences(); + initReferences(ALL_DATA); } - private void initReferences() { + private void initReferences(long loadFlags) { if (data == null) { throw new NullPointerException("data cannot be null"); } @@ -60,36 +63,67 @@ private void initReferences() { if ((level = data.getCompoundTag("Level")) == null) { throw new IllegalArgumentException("data does not contain \"Level\" tag"); } - this.dataVersion = data.getInt("DataVersion"); - this.inhabitedTime = level.getLong("InhabitedTime"); - this.lastUpdate = level.getLong("LastUpdate"); - this.biomes = level.getIntArray("Biomes"); - this.heightMaps = level.getCompoundTag("Heightmaps"); - this.carvingMasks = level.getCompoundTag("CarvingMasks"); - this.entities = level.containsKey("Entities") ? level.getListTag("Entities").asCompoundTagList() : null; - this.tileEntities = level.containsKey("TileEntities") ? level.getListTag("TileEntities").asCompoundTagList() : null; - this.tileTicks = level.containsKey("TileTicks") ? level.getListTag("TileTicks").asCompoundTagList() : null; - this.liquidTicks = level.containsKey("LiquidTicks") ? level.getListTag("LiquidTicks").asCompoundTagList() : null; - this.lights = level.containsKey("Lights") ? level.getListTag("Lights").asListTagList() : null; - this.liquidsToBeTicked = level.containsKey("LiquidsToBeTicked") ? level.getListTag("LiquidsToBeTicked").asListTagList() : null; - this.toBeTicked = level.containsKey("ToBeTicked") ? level.getListTag("ToBeTicked").asListTagList() : null; - this.postProcessing = level.containsKey("PostProcessing") ? level.getListTag("PostProcessing").asListTagList() : null; - this.status = level.getString("Status"); - this.structures = level.getCompoundTag("Structures"); - if (level.containsKey("Sections")) { + dataVersion = data.getInt("DataVersion"); + inhabitedTime = level.getLong("InhabitedTime"); + lastUpdate = level.getLong("LastUpdate"); + if ((loadFlags & BIOMES) != 0) { + biomes = level.getIntArray("Biomes"); + } + if ((loadFlags & HEIGHTMAPS) != 0) { + heightMaps = level.getCompoundTag("Heightmaps"); + } + if ((loadFlags & CARVING_MASKS) != 0) { + carvingMasks = level.getCompoundTag("CarvingMasks"); + } + if ((loadFlags & ENTITIES) != 0) { + entities = level.containsKey("Entities") ? level.getListTag("Entities").asCompoundTagList() : null; + } + if ((loadFlags & TILE_ENTITIES) != 0) { + tileEntities = level.containsKey("TileEntities") ? level.getListTag("TileEntities").asCompoundTagList() : null; + } + if ((loadFlags & TILE_TICKS) != 0) { + tileTicks = level.containsKey("TileTicks") ? level.getListTag("TileTicks").asCompoundTagList() : null; + } + if ((loadFlags & LIQUID_TICKS) != 0) { + liquidTicks = level.containsKey("LiquidTicks") ? level.getListTag("LiquidTicks").asCompoundTagList() : null; + } + if ((loadFlags & LIGHTS) != 0) { + lights = level.containsKey("Lights") ? level.getListTag("Lights").asListTagList() : null; + } + if ((loadFlags & LIQUIDS_TO_BE_TICKED) != 0) { + liquidsToBeTicked = level.containsKey("LiquidsToBeTicked") ? level.getListTag("LiquidsToBeTicked").asListTagList() : null; + } + if ((loadFlags & TO_BE_TICKED) != 0) { + toBeTicked = level.containsKey("ToBeTicked") ? level.getListTag("ToBeTicked").asListTagList() : null; + } + if ((loadFlags & POST_PROCESSING) != 0) { + postProcessing = level.containsKey("PostProcessing") ? level.getListTag("PostProcessing").asListTagList() : null; + } + status = level.getString("Status"); + if ((loadFlags & STRUCTURES) != 0) { + structures = level.getCompoundTag("Structures"); + } + if ((loadFlags & (BLOCK_LIGHTS|BLOCK_STATES|SKY_LIGHT)) != 0 && level.containsKey("Sections")) { for (CompoundTag section : level.getListTag("Sections").asCompoundTagList()) { int sectionIndex = section.getByte("Y"); if (sectionIndex > 15 || sectionIndex < 0) { continue; } - Section newSection = new Section(section, dataVersion); + Section newSection = new Section(section, dataVersion, loadFlags); if (newSection.isEmpty()) { continue; } - - this.sections[sectionIndex] = newSection; + sections[sectionIndex] = newSection; } } + + // If we haven't requested the full set of data we can drop the underlying raw data to let the GC handle it. + if (loadFlags != ALL_DATA) { + data = null; + partial = true; + } else { + partial = false; + } } /** @@ -98,9 +132,13 @@ private void initReferences() { * @param xPos The x-coordinate of the chunk. * @param zPos The z-coodrinate of the chunk. * @return The amount of bytes written to the RandomAccessFile. + * @throws UnsupportedOperationException When something went wrong during writing. * @throws IOException When something went wrong during writing. */ public int serialize(RandomAccessFile raf, int xPos, int zPos) throws IOException { + if (partial) { + throw new UnsupportedOperationException("Partially loaded chunks cannot be serialized"); + } ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); try (BufferedOutputStream nbtOut = new BufferedOutputStream(CompressionType.ZLIB.compress(baos))) { new NBTSerializer(false).toStream(new NamedTag(null, updateHandle(xPos, zPos)), nbtOut); @@ -118,6 +156,16 @@ public int serialize(RandomAccessFile raf, int xPos, int zPos) throws IOExceptio * @throws IOException When something went wrong during reading. */ public void deserialize(RandomAccessFile raf) throws IOException { + deserialize(raf, ALL_DATA); + } + + /** + * Reads chunk data from a RandomAccessFile. The RandomAccessFile must already be at the correct position. + * @param raf The RandomAccessFile to read the chunk data from. + * @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded + * @throws IOException When something went wrong during reading. + */ + public void deserialize(RandomAccessFile raf, long loadFlags) throws IOException { byte compressionTypeByte = raf.readByte(); CompressionType compressionType = CompressionType.getFromID(compressionTypeByte); if (compressionType == null) { @@ -127,7 +175,7 @@ public void deserialize(RandomAccessFile raf) throws IOException { NamedTag tag = new NBTDeserializer(false).fromStream(dis); if (tag != null && tag.getTag() instanceof CompoundTag) { data = (CompoundTag) tag.getTag(); - initReferences(); + initReferences(loadFlags); } else { throw new IOException("invalid data tag: " + (tag == null ? "null" : tag.getClass().getName())); } @@ -571,7 +619,7 @@ public CompoundTag updateHandle(int xPos, int zPos) { } else { if (biomes != null && biomes.length == 1024) level.putIntArray("Biomes", biomes); } - if (heightMaps != null) level.put("HeightMaps", heightMaps); + if (heightMaps != null) level.put("Heightmaps", heightMaps); if (carvingMasks != null) level.put("CarvingMasks", carvingMasks); if (entities != null) level.put("Entities", entities); if (tileEntities != null) level.put("TileEntities", tileEntities); diff --git a/src/main/java/net/querz/mca/LoadFlags.java b/src/main/java/net/querz/mca/LoadFlags.java new file mode 100644 index 00000000..e4122898 --- /dev/null +++ b/src/main/java/net/querz/mca/LoadFlags.java @@ -0,0 +1,24 @@ +package net.querz.mca; + +public class LoadFlags { + + public static long BIOMES = 0x0001; + public static long HEIGHTMAPS = 0x0002; + public static long CARVING_MASKS = 0x0004; + public static long ENTITIES = 0x0008; + public static long TILE_ENTITIES = 0x0010; + public static long TILE_TICKS = 0x0040; + public static long LIQUID_TICKS = 0x0080; + public static long TO_BE_TICKED = 0x0100; + public static long POST_PROCESSING = 0x0200; + public static long STRUCTURES = 0x0400; + public static long BLOCK_LIGHTS = 0x0800; + public static long BLOCK_STATES = 0x1000; + public static long SKY_LIGHT = 0x2000; + public static long LIGHTS = 0x4000; + public static long LIQUIDS_TO_BE_TICKED = 0x8000; + + public static long ALL_DATA = 0xffffffffffffffffL; + + +} diff --git a/src/main/java/net/querz/mca/MCAFile.java b/src/main/java/net/querz/mca/MCAFile.java index c68c5123..92037224 100644 --- a/src/main/java/net/querz/mca/MCAFile.java +++ b/src/main/java/net/querz/mca/MCAFile.java @@ -34,6 +34,17 @@ public MCAFile(int regionX, int regionZ) { * @throws IOException If something went wrong during deserialization. * */ public void deserialize(RandomAccessFile raf) throws IOException { + deserialize(raf, LoadFlags.ALL_DATA); + } + + /** + * Reads an .mca file from a {@code RandomAccessFile} into this object. + * This method does not perform any cleanups on the data. + * @param raf The {@code RandomAccessFile} to read from. + * @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded + * @throws IOException If something went wrong during deserialization. + * */ + public void deserialize(RandomAccessFile raf, long loadFlags) throws IOException { chunks = new Chunk[1024]; for (int i = 0; i < 1024; i++) { raf.seek(i * 4); @@ -47,7 +58,7 @@ public void deserialize(RandomAccessFile raf) throws IOException { int timestamp = raf.readInt(); Chunk chunk = new Chunk(timestamp); raf.seek(4096 * offset + 4); //+4: skip data size - chunk.deserialize(raf); + chunk.deserialize(raf, loadFlags); chunks[i] = chunk; } } diff --git a/src/main/java/net/querz/mca/MCAUtil.java b/src/main/java/net/querz/mca/MCAUtil.java index b12304a2..f5ddecc5 100644 --- a/src/main/java/net/querz/mca/MCAUtil.java +++ b/src/main/java/net/querz/mca/MCAUtil.java @@ -23,7 +23,7 @@ private MCAUtil() {} * @throws IOException if something during deserialization goes wrong. * */ public static MCAFile read(String file) throws IOException { - return read(new File(file)); + return read(new File(file), LoadFlags.ALL_DATA); } /** @@ -33,9 +33,31 @@ public static MCAFile read(String file) throws IOException { * @throws IOException if something during deserialization goes wrong. * */ public static MCAFile read(File file) throws IOException { + return read(file, LoadFlags.ALL_DATA); + } + + /** + * @see MCAUtil#read(File) + * @param file The file to read the data from. + * @return An in-memory representation of the MCA file with decompressed chunk data. + * @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded + * @throws IOException if something during deserialization goes wrong. + * */ + public static MCAFile read(String file, long loadFlags) throws IOException { + return read(new File(file), loadFlags); + } + + /** + * Reads an MCA file and loads all of its chunks. + * @param file The file to read the data from. + * @return An in-memory representation of the MCA file with decompressed chunk data + * @param loadFlags A logical or of {@link LoadFlags} constants indicating what data should be loaded + * @throws IOException if something during deserialization goes wrong. + * */ + public static MCAFile read(File file, long loadFlags) throws IOException { MCAFile mcaFile = newMCAFile(file); try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { - mcaFile.deserialize(raf); + mcaFile.deserialize(raf, loadFlags); return mcaFile; } } diff --git a/src/main/java/net/querz/mca/Section.java b/src/main/java/net/querz/mca/Section.java index 8958b649..312035a3 100644 --- a/src/main/java/net/querz/mca/Section.java +++ b/src/main/java/net/querz/mca/Section.java @@ -1,10 +1,10 @@ package net.querz.mca; +import static net.querz.mca.LoadFlags.*; import net.querz.nbt.tag.ByteArrayTag; import net.querz.nbt.tag.CompoundTag; import net.querz.nbt.tag.ListTag; import net.querz.nbt.tag.LongArrayTag; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -21,6 +21,10 @@ public class Section { private int dataVersion; public Section(CompoundTag sectionRoot, int dataVersion) { + this(sectionRoot, dataVersion, ALL_DATA); + } + + public Section(CompoundTag sectionRoot, int dataVersion, long loadFlags) { data = sectionRoot; this.dataVersion = dataVersion; ListTag rawPalette = sectionRoot.getListTag("Palette"); @@ -37,9 +41,15 @@ public Section(CompoundTag sectionRoot, int dataVersion) { LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight"); - this.blockLight = blockLight != null ? blockLight.getValue() : null; - this.blockStates = blockStates != null ? blockStates.getValue() : null; - this.skyLight = skyLight != null ? skyLight.getValue() : null; + if ((loadFlags & BLOCK_LIGHTS) != 0) { + this.blockLight = blockLight != null ? blockLight.getValue() : null; + } + if ((loadFlags & BLOCK_STATES) != 0) { + this.blockStates = blockStates != null ? blockStates.getValue() : null; + } + if ((loadFlags & SKY_LIGHT) != 0) { + this.skyLight = skyLight != null ? skyLight.getValue() : null; + } } Section() {} diff --git a/src/test/java/net/querz/NBTTestCase.java b/src/test/java/net/querz/NBTTestCase.java index d1935be5..7d412a59 100644 --- a/src/test/java/net/querz/NBTTestCase.java +++ b/src/test/java/net/querz/NBTTestCase.java @@ -252,6 +252,7 @@ protected void cleanupTmpDir() { file.delete(); } } + tmpDir.delete(); } protected String calculateFileMD5(File file) { diff --git a/src/test/java/net/querz/mca/MCAFileTest.java b/src/test/java/net/querz/mca/MCAFileTest.java index 794489bf..38e09f49 100644 --- a/src/test/java/net/querz/mca/MCAFileTest.java +++ b/src/test/java/net/querz/mca/MCAFileTest.java @@ -2,6 +2,7 @@ import net.querz.nbt.tag.CompoundTag; import net.querz.nbt.tag.ListTag; +import static net.querz.mca.LoadFlags.*; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; @@ -343,6 +344,78 @@ public void testChunkInvalidDataTag() { }, IOException.class); } + private void assertLoadFLag(Object field, long flags, long wantedFlag) { + if((flags & wantedFlag) != 0) { + assertNotNull(String.format("Should not be null. Flags=%08x, Wanted flag=%08x", flags, wantedFlag), field); + } else { + assertNull(String.format("Should be null. Flags=%08x, Wanted flag=%08x", flags, wantedFlag), field); + } + } + + private void assertPartialChunk(Chunk c, long loadFlags) { + assertLoadFLag(c.getBiomes(), loadFlags, BIOMES); + assertLoadFLag(c.getHeightMaps(), loadFlags, HEIGHTMAPS); + assertLoadFLag(c.getEntities(), loadFlags, ENTITIES); + assertLoadFLag(c.getCarvingMasks(), loadFlags, CARVING_MASKS); + assertLoadFLag(c.getLights(), loadFlags, LIGHTS); + assertLoadFLag(c.getPostProcessing(), loadFlags, POST_PROCESSING); + assertLoadFLag(c.getLiquidTicks(), loadFlags, LIQUID_TICKS); + assertLoadFLag(c.getLiquidsToBeTicked(), loadFlags, LIQUIDS_TO_BE_TICKED); + assertLoadFLag(c.getTileTicks(), loadFlags, TILE_TICKS); + assertLoadFLag(c.getTileEntities(), loadFlags, TILE_ENTITIES); + assertLoadFLag(c.getToBeTicked(), loadFlags, TO_BE_TICKED); + assertLoadFLag(c.getSection(0), loadFlags, BLOCK_LIGHTS|BLOCK_STATES|SKY_LIGHT); + if ((loadFlags & (BLOCK_LIGHTS|BLOCK_STATES|SKY_LIGHT)) != 0) { + Section s = c.getSection(0); + assertNotNull(String.format("Section is null. Flags=%08x", loadFlags), s); + assertLoadFLag(s.getBlockStates(), loadFlags, BLOCK_STATES); + assertLoadFLag(s.getBlockLight(), loadFlags, BLOCK_LIGHTS); + assertLoadFLag(s.getSkyLight(), loadFlags, SKY_LIGHT); + } + } + + public void testPartialLoad() { + long[] flags = new long[] { + BIOMES, + HEIGHTMAPS, + ENTITIES, + CARVING_MASKS, + LIGHTS, + POST_PROCESSING, + LIQUID_TICKS, + LIQUIDS_TO_BE_TICKED, + TILE_TICKS, + TILE_ENTITIES, + TO_BE_TICKED, + BLOCK_STATES, + BLOCK_LIGHTS, + SKY_LIGHT + }; + + MCAFile f = assertThrowsNoException(() -> MCAUtil.read(copyResourceToTmp("r.2.2.mca"))); + Chunk c = f.getChunk(0); + c.setCarvingMasks(getSomeCompoundTag()); + c.setEntities(getSomeCompoundTagList()); + c.setLights(getSomeListTagList()); + c.setTileEntities(getSomeCompoundTagList()); + c.setTileTicks(getSomeCompoundTagList()); + c.setLiquidTicks(getSomeCompoundTagList()); + c.setToBeTicked(getSomeListTagList()); + c.setLiquidsToBeTicked(getSomeListTagList()); + c.setHeightMaps(getSomeCompoundTag()); + c.setPostProcessing(getSomeListTagList()); + c.getSection(0).setBlockLight(new byte[2048]); + File tmp = this.getNewTmpFile("r.2.2.mca"); + assertThrowsNoException(() -> MCAUtil.write(f, tmp)); + + for (long flag : flags) { + MCAFile mcaFile = assertThrowsNoException(() -> MCAUtil.read(tmp, flag)); + c = mcaFile.getChunk(0, 0); + assertPartialChunk(c, flag); + assertThrowsException(() -> MCAUtil.write(mcaFile, getNewTmpFile("r.12.34.mca")), UnsupportedOperationException.class); + } + } + public void test1_15GetBiomeAt() throws IOException { MCAFile f = assertThrowsNoException(() -> MCAUtil.read(copyResourceToTmp("r.0.0.mca"))); assertEquals(162, f.getBiomeAt(31, 0, 63));