mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Fix ServerChunkDataPacket
This commit is contained in:
parent
8ac2ac9a0f
commit
c36ab6b76e
2 changed files with 9 additions and 15 deletions
|
@ -34,9 +34,11 @@ public class ServerChunkDataPacket implements Packet {
|
|||
boolean fullChunk = in.readBoolean();
|
||||
int chunkMask = in.readVarInt();
|
||||
byte data[] = in.readBytes(in.readVarInt());
|
||||
byte tileEntityData[] = in.readBytes(in.readVarInt());
|
||||
|
||||
this.column = NetUtil.readColumn(data, x, z, fullChunk, false, chunkMask, tileEntityData);
|
||||
CompoundTag[] tileEntities = new CompoundTag[in.readVarInt()];
|
||||
for (int i = 0; i < tileEntities.length; i++) {
|
||||
tileEntities[i] = NetUtil.readNBT(in);
|
||||
}
|
||||
this.column = NetUtil.readColumn(data, x, z, fullChunk, false, chunkMask, tileEntities);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,7 +60,7 @@ public class ServerChunkDataPacket implements Packet {
|
|||
for (CompoundTag compoundTag : column.getTileEntities()) {
|
||||
NetUtil.writeNBT(tileEntitiesNetOut, compoundTag);
|
||||
}
|
||||
out.writeVarInt(tileEntitiesByteOut.size());
|
||||
out.writeVarInt(column.getTileEntities().length);
|
||||
out.writeBytes(tileEntitiesByteOut.toByteArray(), tileEntitiesByteOut.size());
|
||||
|
||||
}
|
||||
|
|
|
@ -236,9 +236,8 @@ public class NetUtil {
|
|||
out.writeByte(255);
|
||||
}
|
||||
|
||||
public static Column readColumn(byte data[], int x, int z, boolean fullChunk, boolean hasSkylight, int mask, byte tileEntityData[]) throws IOException {
|
||||
public static Column readColumn(byte data[], int x, int z, boolean fullChunk, boolean hasSkylight, int mask, CompoundTag[] tileEntities) throws IOException {
|
||||
NetInput in = new StreamNetInput(new ByteArrayInputStream(data));
|
||||
NetInput tileEntityIn = new StreamNetInput(new ByteArrayInputStream(tileEntityData));
|
||||
Exception ex = null;
|
||||
Column column = null;
|
||||
try {
|
||||
|
@ -256,21 +255,14 @@ public class NetUtil {
|
|||
if(fullChunk) {
|
||||
biomeData = in.readBytes(256);
|
||||
}
|
||||
|
||||
int available = tileEntityIn.available();
|
||||
List<CompoundTag> tileEntities = new ArrayList<CompoundTag>();
|
||||
while (available > 0) {
|
||||
tileEntities.add(NetUtil.readNBT(tileEntityIn));
|
||||
available = tileEntityIn.available();
|
||||
}
|
||||
column = new Column(x, z, chunks, biomeData, tileEntities.toArray(new CompoundTag[tileEntities.size()]));
|
||||
column = new Column(x, z, chunks, biomeData, tileEntities);
|
||||
} catch(Exception e) {
|
||||
ex = e;
|
||||
}
|
||||
|
||||
// Unfortunately, this is needed to detect whether the chunks contain skylight or not.
|
||||
if((in.available() > 0 || ex != null) && !hasSkylight) {
|
||||
return readColumn(data, x, z, fullChunk, true, mask, tileEntityData);
|
||||
return readColumn(data, x, z, fullChunk, true, mask, tileEntities);
|
||||
} else if(ex != null) {
|
||||
throw new IOException("Failed to read chunk data.", ex);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue