Skip to content

Commit

Permalink
support the LZ4 compression type, closes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed May 27, 2024
1 parent a51cad5 commit d9db26b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ shadowJar {
'io.undertow',
//'net.kyori', // do not relocate!
'net.querz',
'net.jpountz',
'org.checkerframework',
'org.jboss',
'org.simpleyaml',
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/net/pl3x/map/core/world/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d9db26b

Please sign in to comment.