reformatted some singleplayer classes

This commit is contained in:
LAX1DUDE 2022-08-03 22:53:10 -07:00
parent 7d0bf17586
commit efcf5f8e77
42 changed files with 525 additions and 478 deletions

View File

@ -1,41 +1,39 @@
package net.lax1dude.eaglercraft.sp;
import org.teavm.classlib.java.util.zip.TChecksum;
import java.util.zip.Checksum;
public class CRC32 implements Checksum {
private com.jcraft.jzlib.CRC32 impl = new com.jcraft.jzlib.CRC32();
long tbytes;
private com.jcraft.jzlib.CRC32 impl = new com.jcraft.jzlib.CRC32();
long tbytes;
@Override
public long getValue() {
return impl.getValue();
}
@Override
public long getValue() {
return impl.getValue();
}
@Override
public void reset() {
impl.reset();
tbytes = 0;
}
@Override
public void reset() {
impl.reset();
tbytes = 0;
}
@Override
public void update(int val) {
impl.update(new byte[] { (byte) val }, 0, 1);
}
@Override
public void update(int val) {
impl.update(new byte[] { (byte) val }, 0, 1);
}
public void update(byte[] buf) {
update(buf, 0, buf.length);
}
public void update(byte[] buf) {
update(buf, 0, buf.length);
}
@Override
public void update(byte[] buf, int off, int nbytes) {
// avoid int overflow, check null buf
if (off <= buf.length && nbytes >= 0 && off >= 0 && buf.length - off >= nbytes) {
impl.update(buf, off, nbytes);
tbytes += nbytes;
} else {
throw new ArrayIndexOutOfBoundsException();
}
}
@Override
public void update(byte[] buf, int off, int nbytes) {
// avoid int overflow, check null buf
if (off <= buf.length && nbytes >= 0 && off >= 0 && buf.length - off >= nbytes) {
impl.update(buf, off, nbytes);
tbytes += nbytes;
} else {
throw new ArrayIndexOutOfBoundsException();
}
}
}

View File

@ -12,16 +12,39 @@ import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.minecraft.src.ChunkCoordIntPair;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSFunctor;
import org.teavm.jso.JSObject;
import org.teavm.jso.typedarrays.ArrayBuffer;
import org.teavm.jso.typedarrays.Uint8Array;
import net.lax1dude.eaglercraft.sp.ipc.*;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket00StartServer;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket01StopServer;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket02InitWorld;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket03DeleteWorld;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket04RenameWorld;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket05RequestData;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket06RenameWorldNBT;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket07ImportWorld;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket09RequestResponse;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0ASetWorldDifficulty;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0BPause;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0CPlayerChannel;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0DProgressUpdate;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0EListWorlds;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0FListFiles;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket10FileRead;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket12FileWrite;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket13FileCopyMove;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket14StringList;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket15ThrowException;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket16NBTList;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacketBase;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacketFFProcessKeepAlive;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacketManager;
import net.minecraft.src.AchievementList;
import net.minecraft.src.AchievementMap;
import net.minecraft.src.ChunkCoordIntPair;
import net.minecraft.src.CompressedStreamTools;
import net.minecraft.src.EnumGameType;
import net.minecraft.src.ILogAgent;

View File

@ -5,165 +5,179 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.jcraft.jzlib.DeflaterOutputStream;
import com.jcraft.jzlib.GZIPInputStream;
import com.jcraft.jzlib.GZIPOutputStream;
import net.minecraft.src.ChunkCoordIntPair;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.InflaterInputStream;
import com.jcraft.jzlib.DeflaterOutputStream;
import com.jcraft.jzlib.GZIPInputStream;
import com.jcraft.jzlib.GZIPOutputStream;
import net.minecraft.src.ChunkCoordIntPair;
public class MCAConverter {
public static void convertFromMCA(VFile dir, byte[] file, String fileName) {
VFile levelDir = new VFile(dir, "level" + (fileName.startsWith("region/") ? "0" : fileName.substring(3, fileName.indexOf('/'))));
public static void convertFromMCA(VFile dir, byte[] file, String fileName) {
VFile levelDir = new VFile(dir,
"level" + (fileName.startsWith("region/") ? "0" : fileName.substring(3, fileName.indexOf('/'))));
String[] xz = fileName.substring(fileName.lastIndexOf('r') + 2, fileName.length() - 4).split("\\.");
int gx = Integer.parseInt(xz[0]);
int gz = Integer.parseInt(xz[1]);
String[] xz = fileName.substring(fileName.lastIndexOf('r') + 2, fileName.length() - 4).split("\\.");
int gx = Integer.parseInt(xz[0]);
int gz = Integer.parseInt(xz[1]);
try {
byte[] buffer = new byte[16000];
for (int x = 0; x < 32; ++x) {
for (int z = 0; z < 32; ++z) {
int i = ((x % 32) + (z % 32) * 32) * 4;
int offset = (((file[i] & 0xff) << 16) | ((file[i + 1] & 0xff) << 8) | (file[i + 2] & 0xff)) * 4096;
if (offset == 0 && file[i + 3] == 0) {
continue;
}
int chunkLen = (((file[offset] & 0xff) << 24) | ((file[offset + 1] & 0xff) << 16) | ((file[offset + 2] & 0xff) << 8) | (file[offset + 3] & 0xff));
if (chunkLen == 0) continue;
byte compression = file[offset + 4];
byte[] data = new byte[chunkLen - 1];
System.arraycopy(file, offset + 5, data, 0, chunkLen - 1);
if (compression == 0) {
OutputStream os = new VFile(levelDir, VFSChunkLoader.getChunkPath(gx * 32 + x, gz * 32 + z) + ".dat").getOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(os);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
int len;
while ((len = bais.read(buffer)) > 0) {
gos.write(buffer, 0, len);
}
gos.close();
os.close();
bais.close();
} else if (compression == 2) {
OutputStream os = new VFile(levelDir, VFSChunkLoader.getChunkPath(gx * 32 + x, gz * 32 + z) + ".dat").getOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(os);
InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(data));
int len;
while ((len = iis.read(buffer)) > 0) {
gos.write(buffer, 0, len);
}
gos.close();
os.close();
iis.close();
} else if (compression == 1) {
new VFile(levelDir, VFSChunkLoader.getChunkPath(gx * 32 + x, gz * 32 + z) + ".dat").setAllBytes(data);
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
try {
byte[] buffer = new byte[16000];
for (int x = 0; x < 32; ++x) {
for (int z = 0; z < 32; ++z) {
int i = ((x % 32) + (z % 32) * 32) * 4;
int offset = (((file[i] & 0xff) << 16) | ((file[i + 1] & 0xff) << 8) | (file[i + 2] & 0xff)) * 4096;
if (offset == 0 && file[i + 3] == 0) {
continue;
}
int chunkLen = (((file[offset] & 0xff) << 24) | ((file[offset + 1] & 0xff) << 16)
| ((file[offset + 2] & 0xff) << 8) | (file[offset + 3] & 0xff));
if (chunkLen == 0)
continue;
byte compression = file[offset + 4];
byte[] data = new byte[chunkLen - 1];
System.arraycopy(file, offset + 5, data, 0, chunkLen - 1);
if (compression == 0) {
OutputStream os = new VFile(levelDir,
VFSChunkLoader.getChunkPath(gx * 32 + x, gz * 32 + z) + ".dat").getOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(os);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
int len;
while ((len = bais.read(buffer)) > 0) {
gos.write(buffer, 0, len);
}
gos.close();
os.close();
bais.close();
} else if (compression == 2) {
OutputStream os = new VFile(levelDir,
VFSChunkLoader.getChunkPath(gx * 32 + x, gz * 32 + z) + ".dat").getOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(os);
InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(data));
int len;
while ((len = iis.read(buffer)) > 0) {
gos.write(buffer, 0, len);
}
gos.close();
os.close();
iis.close();
} else if (compression == 1) {
new VFile(levelDir, VFSChunkLoader.getChunkPath(gx * 32 + x, gz * 32 + z) + ".dat")
.setAllBytes(data);
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
public static Map<String, byte[]> convertToMCA(Map<ChunkCoordIntPair, byte[]> regions) {
Map<String, byte[]> regionsOut = new HashMap<>();
public static Map<String, byte[]> convertToMCA(Map<ChunkCoordIntPair, byte[]> regions) {
Map<String, byte[]> regionsOut = new HashMap<>();
if (regions.size() == 0) return regionsOut;
if (regions.size() == 0)
return regionsOut;
byte[] readBuffer = new byte[16000];
byte[] readBuffer = new byte[16000];
try {
int timestamp = (int) System.currentTimeMillis();
try {
int timestamp = (int) System.currentTimeMillis();
int maxX = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
int minX = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
int minX = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
for (ChunkCoordIntPair coords : regions.keySet()) {
if (maxX < coords.chunkXPos) maxX = coords.chunkXPos;
if (maxZ < coords.chunkZPos) maxZ = coords.chunkZPos;
if (minX > coords.chunkXPos) minX = coords.chunkXPos;
if (minZ > coords.chunkZPos) minZ = coords.chunkZPos;
}
for (ChunkCoordIntPair coords : regions.keySet()) {
if (maxX < coords.chunkXPos)
maxX = coords.chunkXPos;
if (maxZ < coords.chunkZPos)
maxZ = coords.chunkZPos;
if (minX > coords.chunkXPos)
minX = coords.chunkXPos;
if (minZ > coords.chunkZPos)
minZ = coords.chunkZPos;
}
for (int z = minZ - (32 + (minZ % 32)); z <= maxZ + (32 + (maxZ % 32)); z += 32) {
for (int x = minX - (32 + (minX % 32)); x <= maxX + (32 + (maxX % 32)); x += 32) {
ByteArrayOutputStream offsets = new ByteArrayOutputStream();
DataOutputStream offsetsDos = new DataOutputStream(offsets);
ByteArrayOutputStream timestamps = new ByteArrayOutputStream();
DataOutputStream timestampsDos = new DataOutputStream(timestamps);
ByteArrayOutputStream chunks = new ByteArrayOutputStream();
DataOutputStream chunksDos = new DataOutputStream(chunks);
boolean anyChunks = false;
for (int cz = 0; cz < 32; cz++) {
for (int cx = 0; cx < 32; cx++) {
int tx = x + cx;
int tz = z + cz;
for (int z = minZ - (32 + (minZ % 32)); z <= maxZ + (32 + (maxZ % 32)); z += 32) {
for (int x = minX - (32 + (minX % 32)); x <= maxX + (32 + (maxX % 32)); x += 32) {
ByteArrayOutputStream offsets = new ByteArrayOutputStream();
DataOutputStream offsetsDos = new DataOutputStream(offsets);
ByteArrayOutputStream timestamps = new ByteArrayOutputStream();
DataOutputStream timestampsDos = new DataOutputStream(timestamps);
ByteArrayOutputStream chunks = new ByteArrayOutputStream();
DataOutputStream chunksDos = new DataOutputStream(chunks);
boolean anyChunks = false;
for (int cz = 0; cz < 32; cz++) {
for (int cx = 0; cx < 32; cx++) {
int tx = x + cx;
int tz = z + cz;
byte[] region = regions.get(new ChunkCoordIntPair(tx, tz));
if (region == null) {
offsetsDos.writeInt(0);
timestampsDos.writeInt(0);
} else {
anyChunks = true;
byte[] region = regions.get(new ChunkCoordIntPair(tx, tz));
if (region == null) {
offsetsDos.writeInt(0);
timestampsDos.writeInt(0);
} else {
anyChunks = true;
ByteArrayInputStream bais = new ByteArrayInputStream(region);
GZIPInputStream gis = new GZIPInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(baos);
int len;
while ((len = gis.read(readBuffer)) > 0) {
dos.write(readBuffer, 0, len);
}
dos.close();
baos.close();
bais.close();
gis.close();
byte[] zlibbed = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(region);
GZIPInputStream gis = new GZIPInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(baos);
int len;
while ((len = gis.read(readBuffer)) > 0) {
dos.write(readBuffer, 0, len);
}
dos.close();
baos.close();
bais.close();
gis.close();
byte[] zlibbed = baos.toByteArray();
int offset = 2 + (chunksDos.size() / 4096);
offsetsDos.write((offset >> 16) & 0xff);
offsetsDos.write((offset >> 8) & 0xff);
offsetsDos.write(offset & 0xff);
offsetsDos.write((int) Math.ceil((5 + zlibbed.length) / 4096.0));
int offset = 2 + (chunksDos.size() / 4096);
offsetsDos.write((offset >> 16) & 0xff);
offsetsDos.write((offset >> 8) & 0xff);
offsetsDos.write(offset & 0xff);
offsetsDos.write((int) Math.ceil((5 + zlibbed.length) / 4096.0));
timestampsDos.writeInt(timestamp);
timestampsDos.writeInt(timestamp);
chunksDos.writeInt(region.length);
chunksDos.write(2);
chunksDos.write(zlibbed);
chunksDos.writeInt(region.length);
chunksDos.write(2);
chunksDos.write(zlibbed);
int chunksSizeOff = chunksDos.size() % 4096;
if (chunksSizeOff != 0) chunksDos.write(new byte[4096 - chunksSizeOff]);
}
}
}
int chunksSizeOff = chunksDos.size() % 4096;
if (chunksSizeOff != 0)
chunksDos.write(new byte[4096 - chunksSizeOff]);
}
}
}
offsetsDos.close();
timestampsDos.close();
chunksDos.close();
offsetsDos.close();
timestampsDos.close();
chunksDos.close();
if (!anyChunks) continue;
if (!anyChunks)
continue;
byte[] offsetsOut = offsets.toByteArray();
byte[] timestampsOut = timestamps.toByteArray();
byte[] chunksOut = chunks.toByteArray();
byte[] offsetsOut = offsets.toByteArray();
byte[] timestampsOut = timestamps.toByteArray();
byte[] chunksOut = chunks.toByteArray();
byte[] regionFile = new byte[offsetsOut.length + timestampsOut.length + chunksOut.length];
System.arraycopy(offsetsOut, 0, regionFile, 0, offsetsOut.length);
System.arraycopy(timestampsOut, 0, regionFile, offsetsOut.length, timestampsOut.length);
System.arraycopy(chunksOut, 0, regionFile, offsetsOut.length + timestampsOut.length, chunksOut.length);
regionsOut.put("r." + (x / 32) + "." + (z / 32), regionFile);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return regionsOut;
}
byte[] regionFile = new byte[offsetsOut.length + timestampsOut.length + chunksOut.length];
System.arraycopy(offsetsOut, 0, regionFile, 0, offsetsOut.length);
System.arraycopy(timestampsOut, 0, regionFile, offsetsOut.length, timestampsOut.length);
System.arraycopy(chunksOut, 0, regionFile, offsetsOut.length + timestampsOut.length,
chunksOut.length);
regionsOut.put("r." + (x / 32) + "." + (z / 32), regionFile);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return regionsOut;
}
}

View File

@ -15,7 +15,6 @@ import org.teavm.interop.Async;
import org.teavm.interop.AsyncCallback;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.dom.events.Event;
import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.indexeddb.EventHandler;
import org.teavm.jso.indexeddb.IDBCountRequest;

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.NetHandler;

View File

@ -1,7 +1,7 @@
package net.lax1dude.eaglercraft.sp;
import com.jcraft.jzlib.Deflater;
import com.jcraft.jzlib.DeflaterOutputStream;
import static java.util.zip.Deflater.BEST_COMPRESSION;
import static java.util.zip.Deflater.DEFAULT_COMPRESSION;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -11,320 +11,317 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import static java.util.zip.Deflater.BEST_COMPRESSION;
import static java.util.zip.Deflater.DEFAULT_COMPRESSION;
import com.jcraft.jzlib.Deflater;
import com.jcraft.jzlib.DeflaterOutputStream;
public class ZipOutputStream extends DeflaterOutputStream {
long LOCSIG = 0x4034b50;
long EXTSIG = 0x8074b50;
long CENSIG = 0x2014b50;
long ENDSIG = 0x6054b50;
long LOCSIG = 0x4034b50;
long EXTSIG = 0x8074b50;
long CENSIG = 0x2014b50;
long ENDSIG = 0x6054b50;
int LOCHDR = 30;
int EXTHDR = 16;
int LOCHDR = 30;
int EXTHDR = 16;
public static final int DEFLATED = 8;
public static final int STORED = 0;
public static final int DEFLATED = 8;
public static final int STORED = 0;
static final int ZIPDataDescriptorFlag = 8;
static final int ZIPLocalHeaderVersionNeeded = 20;
private String comment;
private final List<String> entries = new ArrayList<>();
private int compressMethod = DEFLATED;
private int compressLevel = -1;
private ByteArrayOutputStream cDir = new ByteArrayOutputStream();
private ZipEntry currentEntry;
private final CRC32 crc = new CRC32();
private int offset;
private int curOffset;
private int nameLength;
private byte[] nameBytes;
static final int ZIPDataDescriptorFlag = 8;
static final int ZIPLocalHeaderVersionNeeded = 20;
private String comment;
private final List<String> entries = new ArrayList<>();
private int compressMethod = DEFLATED;
private int compressLevel = -1;
private ByteArrayOutputStream cDir = new ByteArrayOutputStream();
private ZipEntry currentEntry;
private final CRC32 crc = new CRC32();
private int offset;
private int curOffset;
private int nameLength;
private byte[] nameBytes;
public ZipOutputStream(OutputStream p1) throws IOException {
super(p1, new Deflater(-1, true));
}
public ZipOutputStream(OutputStream p1) throws IOException {
super(p1, new Deflater(-1, true));
}
@Override
public void close() throws IOException {
if (out != null) {
finish();
out.close();
out = null;
}
}
@Override
public void close() throws IOException {
if (out != null) {
finish();
out.close();
out = null;
}
}
public void closeEntry() throws IOException {
if (cDir == null) {
throw new IOException();
}
if (currentEntry == null) {
return;
}
if (currentEntry.getMethod() == DEFLATED) {
super.finish();
}
public void closeEntry() throws IOException {
if (cDir == null) {
throw new IOException();
}
if (currentEntry == null) {
return;
}
if (currentEntry.getMethod() == DEFLATED) {
super.finish();
}
// Verify values for STORED types
if (currentEntry.getMethod() == STORED) {
if (crc.getValue() != currentEntry.getCrc()) {
throw new ZipException();
}
if (currentEntry.getSize() != crc.tbytes) {
throw new ZipException();
}
}
curOffset = LOCHDR;
// Verify values for STORED types
if (currentEntry.getMethod() == STORED) {
if (crc.getValue() != currentEntry.getCrc()) {
throw new ZipException();
}
if (currentEntry.getSize() != crc.tbytes) {
throw new ZipException();
}
}
curOffset = LOCHDR;
// Write the DataDescriptor
if (currentEntry.getMethod() != STORED) {
curOffset += EXTHDR;
writeLong(out, EXTSIG);
currentEntry.setCrc(crc.getValue());
writeLong(out, currentEntry.getCrc());
currentEntry.setCompressedSize(deflater.getTotalOut());
writeLong(out, currentEntry.getCompressedSize());
currentEntry.setSize(deflater.getTotalIn());
writeLong(out, currentEntry.getSize());
}
// Update the CentralDirectory
writeLong(cDir, CENSIG);
writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version created
writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version to extract
writeShort(cDir, currentEntry.getMethod() == STORED ? 0 : ZIPDataDescriptorFlag);
writeShort(cDir, currentEntry.getMethod());
writeShort(cDir, (int) currentEntry.getTime());
writeShort(cDir, 0);
writeLong(cDir, crc.getValue());
if (currentEntry.getMethod() == DEFLATED) {
curOffset += writeLong(cDir, deflater.getTotalOut());
writeLong(cDir, deflater.getTotalIn());
} else {
curOffset += writeLong(cDir, crc.tbytes);
writeLong(cDir, crc.tbytes);
}
curOffset += writeShort(cDir, nameLength);
if (currentEntry.getExtra() != null) {
curOffset += writeShort(cDir, currentEntry.getExtra().length);
} else {
writeShort(cDir, 0);
}
String c = currentEntry.getComment();
writeShort(cDir, c != null ? c.length() : 0);
writeShort(cDir, 0); // Disk Start
writeShort(cDir, 0); // Internal File Attributes
writeLong(cDir, 0); // External File Attributes
writeLong(cDir, offset);
cDir.write(nameBytes);
nameBytes = null;
if (currentEntry.getExtra() != null) {
cDir.write(currentEntry.getExtra());
}
offset += curOffset;
if (c != null) {
cDir.write(c.getBytes());
}
currentEntry = null;
crc.reset();
deflater.end();
deflater.init(-1, true);
}
// Write the DataDescriptor
if (currentEntry.getMethod() != STORED) {
curOffset += EXTHDR;
writeLong(out, EXTSIG);
currentEntry.setCrc(crc.getValue());
writeLong(out, currentEntry.getCrc());
currentEntry.setCompressedSize(deflater.getTotalOut());
writeLong(out, currentEntry.getCompressedSize());
currentEntry.setSize(deflater.getTotalIn());
writeLong(out, currentEntry.getSize());
}
// Update the CentralDirectory
writeLong(cDir, CENSIG);
writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version created
writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version to extract
writeShort(cDir, currentEntry.getMethod() == STORED ? 0 : ZIPDataDescriptorFlag);
writeShort(cDir, currentEntry.getMethod());
writeShort(cDir, (int) currentEntry.getTime());
writeShort(cDir, 0);
writeLong(cDir, crc.getValue());
if (currentEntry.getMethod() == DEFLATED) {
curOffset += writeLong(cDir, deflater.getTotalOut());
writeLong(cDir, deflater.getTotalIn());
} else {
curOffset += writeLong(cDir, crc.tbytes);
writeLong(cDir, crc.tbytes);
}
curOffset += writeShort(cDir, nameLength);
if (currentEntry.getExtra() != null) {
curOffset += writeShort(cDir, currentEntry.getExtra().length);
} else {
writeShort(cDir, 0);
}
String c = currentEntry.getComment();
writeShort(cDir, c != null ? c.length() : 0);
writeShort(cDir, 0); // Disk Start
writeShort(cDir, 0); // Internal File Attributes
writeLong(cDir, 0); // External File Attributes
writeLong(cDir, offset);
cDir.write(nameBytes);
nameBytes = null;
if (currentEntry.getExtra() != null) {
cDir.write(currentEntry.getExtra());
}
offset += curOffset;
if (c != null) {
cDir.write(c.getBytes());
}
currentEntry = null;
crc.reset();
deflater.end();
deflater.init(-1, true);
}
@Override
public void finish() throws IOException {
if (out == null) {
throw new IOException();
}
if (cDir == null) {
return;
}
if (entries.size() == 0) {
throw new ZipException();
}
if (currentEntry != null) {
closeEntry();
}
int cdirSize = cDir.size();
// Write Central Dir End
writeLong(cDir, ENDSIG);
writeShort(cDir, 0); // Disk Number
writeShort(cDir, 0); // Start Disk
writeShort(cDir, entries.size()); // Number of entries
writeShort(cDir, entries.size()); // Number of entries
writeLong(cDir, cdirSize); // Size of central dir
writeLong(cDir, offset); // Offset of central dir
if (comment != null) {
writeShort(cDir, comment.length());
cDir.write(comment.getBytes());
} else {
writeShort(cDir, 0);
}
// Write the central dir
out.write(cDir.toByteArray());
cDir = null;
@Override
public void finish() throws IOException {
if (out == null) {
throw new IOException();
}
if (cDir == null) {
return;
}
if (entries.size() == 0) {
throw new ZipException();
}
if (currentEntry != null) {
closeEntry();
}
int cdirSize = cDir.size();
// Write Central Dir End
writeLong(cDir, ENDSIG);
writeShort(cDir, 0); // Disk Number
writeShort(cDir, 0); // Start Disk
writeShort(cDir, entries.size()); // Number of entries
writeShort(cDir, entries.size()); // Number of entries
writeLong(cDir, cdirSize); // Size of central dir
writeLong(cDir, offset); // Offset of central dir
if (comment != null) {
writeShort(cDir, comment.length());
cDir.write(comment.getBytes());
} else {
writeShort(cDir, 0);
}
// Write the central dir
out.write(cDir.toByteArray());
cDir = null;
}
}
public void putNextEntry(ZipEntry ze) throws IOException {
if (currentEntry != null) {
closeEntry();
}
if (ze.getMethod() == STORED
|| (compressMethod == STORED && ze.getMethod() == -1)) {
if (ze.getCrc() == -1) {
throw new ZipException("Crc mismatch");
}
if (ze.getSize() == -1 && ze.getCompressedSize() == -1) {
throw new ZipException("Size mismatch");
}
if (ze.getSize() != ze.getCompressedSize() && ze.getCompressedSize() != -1 && ze.getSize() != -1) {
throw new ZipException("Size mismatch");
}
}
if (cDir == null) {
throw new IOException("Stream is closed");
}
if (entries.contains(ze.getName())) {
throw new ZipException("Entry already exists: " + ze.getName());
}
nameLength = utf8Count(ze.getName());
if (nameLength > 0xffff) {
throw new IllegalArgumentException("Name too long: " + ze.getName());
}
public void putNextEntry(ZipEntry ze) throws IOException {
if (currentEntry != null) {
closeEntry();
}
if (ze.getMethod() == STORED || (compressMethod == STORED && ze.getMethod() == -1)) {
if (ze.getCrc() == -1) {
throw new ZipException("Crc mismatch");
}
if (ze.getSize() == -1 && ze.getCompressedSize() == -1) {
throw new ZipException("Size mismatch");
}
if (ze.getSize() != ze.getCompressedSize() && ze.getCompressedSize() != -1 && ze.getSize() != -1) {
throw new ZipException("Size mismatch");
}
}
if (cDir == null) {
throw new IOException("Stream is closed");
}
if (entries.contains(ze.getName())) {
throw new ZipException("Entry already exists: " + ze.getName());
}
nameLength = utf8Count(ze.getName());
if (nameLength > 0xffff) {
throw new IllegalArgumentException("Name too long: " + ze.getName());
}
deflater.params(compressLevel, 0);
currentEntry = ze;
entries.add(currentEntry.getName());
if (currentEntry.getMethod() == -1) {
currentEntry.setMethod(compressMethod);
}
writeLong(out, LOCSIG); // Entry header
writeShort(out, ZIPLocalHeaderVersionNeeded); // Extraction version
writeShort(out, currentEntry.getMethod() == STORED ? 0 : ZIPDataDescriptorFlag);
writeShort(out, currentEntry.getMethod());
if (currentEntry.getTime() == -1) {
currentEntry.setTime(System.currentTimeMillis());
}
writeShort(out, (int) currentEntry.getTime());
writeShort(out, 0);
deflater.params(compressLevel, 0);
currentEntry = ze;
entries.add(currentEntry.getName());
if (currentEntry.getMethod() == -1) {
currentEntry.setMethod(compressMethod);
}
writeLong(out, LOCSIG); // Entry header
writeShort(out, ZIPLocalHeaderVersionNeeded); // Extraction version
writeShort(out, currentEntry.getMethod() == STORED ? 0 : ZIPDataDescriptorFlag);
writeShort(out, currentEntry.getMethod());
if (currentEntry.getTime() == -1) {
currentEntry.setTime(System.currentTimeMillis());
}
writeShort(out, (int) currentEntry.getTime());
writeShort(out, 0);
if (currentEntry.getMethod() == STORED) {
if (currentEntry.getSize() == -1) {
currentEntry.setSize(currentEntry.getCompressedSize());
} else if (currentEntry.getCompressedSize() == -1) {
currentEntry.setCompressedSize(currentEntry.getSize());
}
writeLong(out, currentEntry.getCrc());
writeLong(out, currentEntry.getSize());
writeLong(out, currentEntry.getSize());
} else {
writeLong(out, 0);
writeLong(out, 0);
writeLong(out, 0);
}
writeShort(out, nameLength);
writeShort(out, currentEntry.getExtra() != null ? currentEntry.getExtra().length : 0);
nameBytes = toUTF8Bytes(currentEntry.getName(), nameLength);
out.write(nameBytes);
if (currentEntry.getExtra() != null) {
out.write(currentEntry.getExtra());
}
}
if (currentEntry.getMethod() == STORED) {
if (currentEntry.getSize() == -1) {
currentEntry.setSize(currentEntry.getCompressedSize());
} else if (currentEntry.getCompressedSize() == -1) {
currentEntry.setCompressedSize(currentEntry.getSize());
}
writeLong(out, currentEntry.getCrc());
writeLong(out, currentEntry.getSize());
writeLong(out, currentEntry.getSize());
} else {
writeLong(out, 0);
writeLong(out, 0);
writeLong(out, 0);
}
writeShort(out, nameLength);
writeShort(out, currentEntry.getExtra() != null ? currentEntry.getExtra().length : 0);
nameBytes = toUTF8Bytes(currentEntry.getName(), nameLength);
out.write(nameBytes);
if (currentEntry.getExtra() != null) {
out.write(currentEntry.getExtra());
}
}
public void setComment(String comment) {
if (comment.length() > 0xFFFF) {
throw new IllegalArgumentException();
}
this.comment = comment;
}
public void setComment(String comment) {
if (comment.length() > 0xFFFF) {
throw new IllegalArgumentException();
}
this.comment = comment;
}
public void setLevel(int level) {
if (level < DEFAULT_COMPRESSION || level > BEST_COMPRESSION) {
throw new IllegalArgumentException();
}
compressLevel = level;
}
public void setLevel(int level) {
if (level < DEFAULT_COMPRESSION || level > BEST_COMPRESSION) {
throw new IllegalArgumentException();
}
compressLevel = level;
}
public void setMethod(int method) {
if (method != STORED && method != DEFLATED) {
throw new IllegalArgumentException();
}
compressMethod = method;
public void setMethod(int method) {
if (method != STORED && method != DEFLATED) {
throw new IllegalArgumentException();
}
compressMethod = method;
}
}
private long writeLong(OutputStream os, long i) throws IOException {
// Write out the long value as an unsigned int
os.write((int) (i & 0xFF));
os.write((int) (i >> 8) & 0xFF);
os.write((int) (i >> 16) & 0xFF);
os.write((int) (i >> 24) & 0xFF);
return i;
}
private long writeLong(OutputStream os, long i) throws IOException {
// Write out the long value as an unsigned int
os.write((int) (i & 0xFF));
os.write((int) (i >> 8) & 0xFF);
os.write((int) (i >> 16) & 0xFF);
os.write((int) (i >> 24) & 0xFF);
return i;
}
private int writeShort(OutputStream os, int i) throws IOException {
os.write(i & 0xFF);
os.write((i >> 8) & 0xFF);
return i;
private int writeShort(OutputStream os, int i) throws IOException {
os.write(i & 0xFF);
os.write((i >> 8) & 0xFF);
return i;
}
}
/**
* Writes data for the current entry to the underlying stream.
*
* @exception IOException
* If an error occurs writing to the stream
*/
@Override
public void write(byte[] buffer, int off, int nbytes)
throws IOException {
// avoid int overflow, check null buf
if ((off < 0 || (nbytes < 0) || off > buffer.length) || (buffer.length - off < nbytes)) {
throw new IndexOutOfBoundsException();
}
/**
* Writes data for the current entry to the underlying stream.
*
* @exception IOException If an error occurs writing to the stream
*/
@Override
public void write(byte[] buffer, int off, int nbytes) throws IOException {
// avoid int overflow, check null buf
if ((off < 0 || (nbytes < 0) || off > buffer.length) || (buffer.length - off < nbytes)) {
throw new IndexOutOfBoundsException();
}
if (currentEntry == null) {
throw new ZipException("No active entry");
}
if (currentEntry == null) {
throw new ZipException("No active entry");
}
if (currentEntry.getMethod() == STORED) {
out.write(buffer, off, nbytes);
} else {
super.write(buffer, off, nbytes);
}
crc.update(buffer, off, nbytes);
}
if (currentEntry.getMethod() == STORED) {
out.write(buffer, off, nbytes);
} else {
super.write(buffer, off, nbytes);
}
crc.update(buffer, off, nbytes);
}
static int utf8Count(String value) {
int total = 0;
for (int i = value.length(); --i >= 0;) {
char ch = value.charAt(i);
if (ch < 0x80) {
total++;
} else if (ch < 0x800) {
total += 2;
} else {
total += 3;
}
}
return total;
}
static int utf8Count(String value) {
int total = 0;
for (int i = value.length(); --i >= 0;) {
char ch = value.charAt(i);
if (ch < 0x80) {
total++;
} else if (ch < 0x800) {
total += 2;
} else {
total += 3;
}
}
return total;
}
static byte[] toUTF8Bytes(String value, int length) {
byte[] result = new byte[length];
int pos = result.length;
for (int i = value.length(); --i >= 0;) {
char ch = value.charAt(i);
if (ch < 0x80) {
result[--pos] = (byte) ch;
} else if (ch < 0x800) {
result[--pos] = (byte) (0x80 | (ch & 0x3f));
result[--pos] = (byte) (0xc0 | (ch >> 6));
} else {
result[--pos] = (byte) (0x80 | (ch & 0x3f));
result[--pos] = (byte) (0x80 | ((ch >> 6) & 0x3f));
result[--pos] = (byte) (0xe0 | (ch >> 12));
}
}
return result;
}
static byte[] toUTF8Bytes(String value, int length) {
byte[] result = new byte[length];
int pos = result.length;
for (int i = value.length(); --i >= 0;) {
char ch = value.charAt(i);
if (ch < 0x80) {
result[--pos] = (byte) ch;
} else if (ch < 0x800) {
result[--pos] = (byte) (0x80 | (ch & 0x3f));
result[--pos] = (byte) (0xc0 | (ch >> 6));
} else {
result[--pos] = (byte) (0x80 | (ch & 0x3f));
result[--pos] = (byte) (0x80 | ((ch >> 6) & 0x3f));
result[--pos] = (byte) (0xe0 | (ch >> 12));
}
}
return result;
}
}

View File

@ -8,9 +8,9 @@ import java.util.List;
import net.lax1dude.eaglercraft.sp.IntegratedServer;
import net.lax1dude.eaglercraft.sp.SYS;
import net.lax1dude.eaglercraft.sp.WorkerListenThread;
import net.lax1dude.eaglercraft.sp.VFSSaveHandler;
import net.lax1dude.eaglercraft.sp.VFile;
import net.lax1dude.eaglercraft.sp.WorkerListenThread;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0DProgressUpdate;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket14StringList;
import net.minecraft.src.AxisAlignedBB;
@ -24,7 +24,6 @@ import net.minecraft.src.ICommandManager;
import net.minecraft.src.ICommandSender;
import net.minecraft.src.ILogAgent;
import net.minecraft.src.IProgressUpdate;
import net.minecraft.src.ISaveFormat;
import net.minecraft.src.ISaveHandler;
import net.minecraft.src.IUpdatePlayerListBox;
import net.minecraft.src.MinecraftException;

View File

@ -1,7 +1,6 @@
package net.minecraft.src;
import java.util.Iterator;
import java.util.Random;
import net.lax1dude.eaglercraft.sp.EaglercraftRandom;

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public abstract class CommandBase implements ICommand {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandClearInventory extends CommandBase {

View File

@ -1,10 +1,7 @@
package net.minecraft.src;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandDebug extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandDifficulty extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandEffect extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandEnchant extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandGameMode extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandGameRule extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandGive extends CommandBase {

View File

@ -6,8 +6,8 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
public class CommandHandler implements ICommandManager {
/** Map of Strings to the ICommand objects they represent */

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.minecraft.server.MinecraftServer;
public class CommandHelp extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandServerEmote extends CommandBase {

View File

@ -2,6 +2,7 @@ package net.minecraft.src;
import java.util.Arrays;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandServerMessage extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandServerSay extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandServerTp extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandSetSpawnpoint extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandTime extends CommandBase {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class CommandXP extends CommandBase {

View File

@ -10,7 +10,6 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import com.jcraft.jzlib.Deflater;
import com.jcraft.jzlib.GZIPInputStream;

View File

@ -8,8 +8,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class DataWatcher {
/** When isBlank is true the DataWatcher is not watching any objects */

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public abstract class EntityMinecart extends Entity {

View File

@ -9,6 +9,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public class EntityPlayerMP extends EntityPlayer implements ICrafting {

View File

@ -5,7 +5,6 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
public class LowerStringMap implements Map {
private final Map internalMap = new LinkedHashMap();

View File

@ -3,9 +3,6 @@ package net.minecraft.src;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public class Packet51MapChunk extends Packet {
/** The x-position of the transmitted chunk, in chunk coordinates. */

View File

@ -1,7 +1,9 @@
package net.minecraft.src;
import java.util.Vector;
import javax.swing.JList;
import net.minecraft.server.MinecraftServer;
public class PlayerListBox extends JList implements IUpdatePlayerListBox {

View File

@ -2,7 +2,6 @@ package net.minecraft.src;
import java.util.ArrayList;
import java.util.List;
import java.util.UnknownFormatConversionException;
public class PlayerManager {
private final WorldServer theWorldServer;

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.minecraft.server.MinecraftServer;
public class PlayerSelector {

View File

@ -2,6 +2,7 @@ package net.minecraft.src;
import java.util.Collection;
import java.util.Iterator;
import net.minecraft.server.MinecraftServer;
public class ScoreboardSaveData extends WorldSavedData {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.Iterator;
import net.minecraft.server.MinecraftServer;
public class ServerCommandManager extends CommandHandler implements IAdminCommand {

View File

@ -7,6 +7,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.minecraft.server.MinecraftServer;
public class ServerCommandScoreboard extends CommandBase {

View File

@ -7,8 +7,9 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import net.minecraft.server.MinecraftServer;
public class ServerConfigurationManager {

View File

@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.minecraft.server.MinecraftServer;
public class ServerScoreboard extends Scoreboard {

View File

@ -2,6 +2,7 @@ package net.minecraft.src;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.server.MinecraftServer;
public class TileEntity {

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.util.Iterator;
import net.minecraft.server.MinecraftServer;
public class WorldManager implements IWorldAccess {