File compression

This commit is contained in:
PeytonPlayz595 2024-02-12 10:07:18 -05:00
parent 2dbebbd2ea
commit be661b51f2
7 changed files with 6554 additions and 3330 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1781,4 +1781,11 @@ public class EaglerAdapterImpl2 {
downloadFile0(filename, b.getBuffer());
}
public static boolean isCompressed(byte[] b) {
if(b == null || b.length < 2) {
return false;
}
return (b[0] == (byte) 0x1F) && (b[1] == (byte) 0x8B);
}
}

View File

@ -69,7 +69,12 @@ public class ChunkLoader implements IChunkLoader {
try {
byte[] data = GL11.readFile(var4);
ByteArrayInputStream var5 = new ByteArrayInputStream(data);
NBTTagCompound var6 = (NBTTagCompound) NBTBase.readTag(new DataInputStream(var5));
NBTTagCompound var6;
if(GL11.isCompressed(data)) {
var6 = CompressedStreamTools.func_1138_a(var5);
} else {
var6 = (NBTTagCompound) NBTBase.readTag(new DataInputStream(var5));
}
if(!var6.hasKey("Level")) {
System.out.println("Chunk file at " + var2 + "," + var3 + " is missing level data, skipping");
return null;
@ -111,15 +116,10 @@ public class ChunkLoader implements IChunkLoader {
NBTTagCompound var7 = new NBTTagCompound();
var6.setTag("Level", var7);
this.storeChunkInCompound(var2, var1, var7);
try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(var5))) {
NBTBase.writeTag(var6, dos);
dos.flush();
var5.flush();
GL11.writeFile(var4, var5.toByteArray());
var5.close();
} catch(IOException e) {
e.printStackTrace();
}
CompressedStreamTools.writeGzippedCompoundToOutputStream(var6, var5);
var5.flush();
GL11.writeFile(var4, var5.toByteArray());
var5.close();
if(GL11.readFile(var3) != null) {
GL11.deleteFile(var3);

View File

@ -1,78 +1,79 @@
//package net.minecraft.src;
//
//import java.io.ByteArrayInputStream;
//import java.io.ByteArrayOutputStream;
//import java.io.DataInput;
//import java.io.DataInputStream;
//import java.io.DataOutput;
//import java.io.DataOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.util.zip.GZIPInputStream;
//import java.util.zip.GZIPOutputStream;
//
//public class CompressedStreamTools {
// public static NBTTagCompound func_1138_a(InputStream var0) throws IOException {
// DataInputStream var1 = new DataInputStream(new GZIPInputStream(var0));
//
// NBTTagCompound var2;
// try {
// var2 = func_1141_a(var1);
// } finally {
// var1.close();
// }
//
// return var2;
// }
//
// public static void writeGzippedCompoundToOutputStream(NBTTagCompound var0, OutputStream var1) throws IOException {
// DataOutputStream var2 = new DataOutputStream(new GZIPOutputStream(var1));
//
// try {
// func_1139_a(var0, var2);
// } finally {
// var2.close();
// }
//
// }
//
// public static NBTTagCompound func_1140_a(byte[] var0) throws IOException {
// DataInputStream var1 = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(var0)));
//
// NBTTagCompound var2;
// try {
// var2 = func_1141_a(var1);
// } finally {
// var1.close();
// }
//
// return var2;
// }
//
// public static byte[] func_1142_a(NBTTagCompound var0) throws IOException {
// ByteArrayOutputStream var1 = new ByteArrayOutputStream();
// DataOutputStream var2 = new DataOutputStream(new GZIPOutputStream(var1));
//
// try {
// func_1139_a(var0, var2);
// } finally {
// var2.close();
// }
//
// return var1.toByteArray();
// }
//
// public static NBTTagCompound func_1141_a(DataInput var0) throws IOException {
// NBTBase var1 = NBTBase.readTag(var0);
// if(var1 instanceof NBTTagCompound) {
// return (NBTTagCompound)var1;
// } else {
// throw new IOException("Root tag must be a named compound tag");
// }
// }
//
// public static void func_1139_a(NBTTagCompound var0, DataOutput var1) throws IOException {
// NBTBase.writeTag(var0, var1);
// }
//}
package net.minecraft.src;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.jcraft.jzlib.GZIPInputStream;
import com.jcraft.jzlib.GZIPOutputStream;
public class CompressedStreamTools {
public static NBTTagCompound func_1138_a(InputStream var0) throws IOException {
DataInputStream var1 = new DataInputStream(new GZIPInputStream(var0));
NBTTagCompound var2;
try {
var2 = func_1141_a(var1);
} finally {
var1.close();
}
return var2;
}
public static void writeGzippedCompoundToOutputStream(NBTTagCompound var0, OutputStream var1) throws IOException {
DataOutputStream var2 = new DataOutputStream(new GZIPOutputStream(var1));
try {
func_1139_a(var0, var2);
} finally {
var2.close();
}
}
public static NBTTagCompound func_1140_a(byte[] var0) throws IOException {
DataInputStream var1 = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(var0)));
NBTTagCompound var2;
try {
var2 = func_1141_a(var1);
} finally {
var1.close();
}
return var2;
}
public static byte[] func_1142_a(NBTTagCompound var0) throws IOException {
ByteArrayOutputStream var1 = new ByteArrayOutputStream();
DataOutputStream var2 = new DataOutputStream(new GZIPOutputStream(var1));
try {
func_1139_a(var0, var2);
} finally {
var2.close();
}
return var1.toByteArray();
}
public static NBTTagCompound func_1141_a(DataInput var0) throws IOException {
NBTBase var1 = NBTBase.readTag(var0);
if(var1 instanceof NBTTagCompound) {
return (NBTTagCompound)var1;
} else {
throw new IOException("Root tag must be a named compound tag");
}
}
public static void func_1139_a(NBTTagCompound var0, DataOutput var1) throws IOException {
NBTBase.writeTag(var0, var1);
}
}

View File

@ -64,7 +64,12 @@ public class World implements IBlockAccess {
byte[] data = GL11.readFile("saves/" + var1 + "/level.dat");
if(!(data == null)) {
try {
NBTTagCompound var5 = (NBTTagCompound) NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(data)));
NBTTagCompound var5;
if(GL11.isCompressed(data)) {
var5 = CompressedStreamTools.func_1138_a(new ByteArrayInputStream(data));
} else {
var5 = (NBTTagCompound) NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(data)));
}
NBTTagCompound var6 = var5.getCompoundTag("Data");
return var6;
} catch (Exception var7) {
@ -233,7 +238,12 @@ public class World implements IBlockAccess {
byte[] data = GL11.readFile(var18);
if(data != null) {
try {
NBTTagCompound var8 = (NBTTagCompound) NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(data)));
NBTTagCompound var8;
if(GL11.isCompressed(data)) {
var8 = CompressedStreamTools.func_1138_a(new ByteArrayInputStream(data));
} else {
var8 = (NBTTagCompound) NBTBase.readTag(new DataInputStream(new ByteArrayInputStream(data)));
}
NBTTagCompound var9 = var8.getCompoundTag("Data");
this.randomSeed = var9.getLong("RandomSeed");
this.spawnX = var9.getInteger("SpawnX");
@ -367,15 +377,7 @@ public class World implements IBlockAccess {
String var5 = field_9432_t + "/level.dat_old";
String var6 = field_9432_t + "/level.dat";
ByteArrayOutputStream data = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(data))) {
NBTBase.writeTag(var3, dos);
dos.flush();
byte[] file = data.toByteArray();
GL11.writeFile(var6, file);
} catch(IOException e) {
e.printStackTrace();
}
CompressedStreamTools.writeGzippedCompoundToOutputStream(var3, data);
GL11.writeFile(var4, data.toByteArray());
if(GL11.readFile(var5) != null) {

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long