diff --git a/build.gradle b/build.gradle index ba9e25645..396f079e1 100644 --- a/build.gradle +++ b/build.gradle @@ -110,6 +110,7 @@ allprojects { implementation "com.github.ben-manes.caffeine:caffeine:$caffeineVersion" implementation "com.github.Querz:NBT:$querzNbtVersion" + implementation "org.lz4:lz4-java:1.8.0" implementation("com.github.Carleslc.Simple-YAML:Simple-Yaml:$simpleYamlVersion") { exclude group: 'org.yaml', module: 'snakeyaml' } diff --git a/core/build.gradle b/core/build.gradle index 7ce448f2b..800de6bef 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -44,6 +44,7 @@ shadowJar { 'io.undertow', //'net.kyori', // do not relocate! 'net.querz', + 'net.jpountz', 'org.checkerframework', 'org.jboss', 'org.simpleyaml', diff --git a/core/src/main/java/net/pl3x/map/core/world/Region.java b/core/src/main/java/net/pl3x/map/core/world/Region.java index 26dcc56a7..10cfceda6 100644 --- a/core/src/main/java/net/pl3x/map/core/world/Region.java +++ b/core/src/main/java/net/pl3x/map/core/world/Region.java @@ -30,9 +30,11 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.io.RandomAccessFile; import java.nio.file.Path; import java.util.Objects; +import net.jpountz.lz4.LZ4BlockInputStream; import net.pl3x.map.core.Pl3xMap; import net.pl3x.map.core.log.Logger; import net.querz.mca.CompressionType; @@ -124,11 +126,14 @@ public void loadChunks() throws IOException { byte compressionTypeByte = raf.readByte(); CompressionType compressionType = CompressionType.getFromID(compressionTypeByte); - if (compressionType == null) { + if (compressionTypeByte != 4 && compressionType == null) { throw new IOException("Invalid compression type " + compressionTypeByte); } - DataInputStream dis = new DataInputStream(new BufferedInputStream(compressionType.decompress(new FileInputStream(raf.getFD())))); + FileInputStream fileInputStream = new FileInputStream(raf.getFD()); + // TODO: hotfix until querz' nbt library supports the LZ4 compression type + InputStream decompress = compressionTypeByte == 4 ? new LZ4BlockInputStream(fileInputStream) : compressionType.decompress(fileInputStream); + DataInputStream dis = new DataInputStream(new BufferedInputStream(decompress)); NamedTag tag = new NBTInputStream(dis).readTag(Tag.DEFAULT_MAX_DEPTH); if (tag != null && tag.getTag() instanceof CompoundTag compoundTag) { return this.chunks[index] = Chunk.create(getWorld(), this, compoundTag, index).populate();