mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2025-01-18 18:39:46 -05:00
I think this is enough.
This commit is contained in:
parent
a1571ed0cb
commit
8ac2ac9a0f
4 changed files with 47 additions and 21 deletions
|
@ -1,19 +1,21 @@
|
|||
package org.spacehq.mc.protocol.data.game.chunk;
|
||||
|
||||
//TODO: Chunk Data (0x20) now also sends all tile entities in the chunk (at the end of the packet)
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
public class Column {
|
||||
private int x;
|
||||
private int z;
|
||||
private Chunk chunks[];
|
||||
private byte biomeData[];
|
||||
private CompoundTag tileEntities[];
|
||||
|
||||
private boolean skylight;
|
||||
|
||||
public Column(int x, int z, Chunk chunks[]) {
|
||||
this(x, z, chunks, null);
|
||||
public Column(int x, int z, Chunk chunks[], CompoundTag tileEntities[]) {
|
||||
this(x, z, chunks, null, tileEntities);
|
||||
}
|
||||
|
||||
public Column(int x, int z, Chunk chunks[], byte biomeData[]) {
|
||||
public Column(int x, int z, Chunk chunks[], byte biomeData[], CompoundTag tileEntities[]) {
|
||||
if(chunks.length != 16) {
|
||||
throw new IllegalArgumentException("Chunk array length must be 16.");
|
||||
}
|
||||
|
@ -24,9 +26,9 @@ public class Column {
|
|||
|
||||
this.skylight = false;
|
||||
boolean noSkylight = false;
|
||||
for(int index = 0; index < chunks.length; index++) {
|
||||
if(chunks[index] != null) {
|
||||
if(chunks[index].getSkyLight() == null) {
|
||||
for (Chunk chunk : chunks) {
|
||||
if (chunk != null) {
|
||||
if (chunk.getSkyLight() == null) {
|
||||
noSkylight = true;
|
||||
} else {
|
||||
this.skylight = true;
|
||||
|
@ -42,6 +44,7 @@ public class Column {
|
|||
this.z = z;
|
||||
this.chunks = chunks;
|
||||
this.biomeData = biomeData;
|
||||
this.tileEntities = tileEntities;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
|
@ -64,6 +67,10 @@ public class Column {
|
|||
return this.biomeData;
|
||||
}
|
||||
|
||||
public CompoundTag[] getTileEntities() {
|
||||
return this.tileEntities;
|
||||
}
|
||||
|
||||
public boolean hasSkylight() {
|
||||
return this.skylight;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.spacehq.mc.protocol.packet.ingame.server.world;
|
|||
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
||||
import org.spacehq.mc.protocol.util.NetUtil;
|
||||
import org.spacehq.mc.protocol.util.ReflectionToString;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import org.spacehq.packetlib.io.NetInput;
|
||||
import org.spacehq.packetlib.io.NetOutput;
|
||||
import org.spacehq.packetlib.io.stream.StreamNetOutput;
|
||||
|
@ -33,8 +34,9 @@ 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);
|
||||
this.column = NetUtil.readColumn(data, x, z, fullChunk, false, chunkMask, tileEntityData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,6 +51,16 @@ public class ServerChunkDataPacket implements Packet {
|
|||
out.writeVarInt(mask);
|
||||
out.writeVarInt(byteOut.size());
|
||||
out.writeBytes(byteOut.toByteArray(), byteOut.size());
|
||||
|
||||
ByteArrayOutputStream tileEntitiesByteOut = new ByteArrayOutputStream();
|
||||
NetOutput tileEntitiesNetOut = new StreamNetOutput(tileEntitiesByteOut);
|
||||
|
||||
for (CompoundTag compoundTag : column.getTileEntities()) {
|
||||
NetUtil.writeNBT(tileEntitiesNetOut, compoundTag);
|
||||
}
|
||||
out.writeVarInt(tileEntitiesByteOut.size());
|
||||
out.writeBytes(tileEntitiesByteOut.toByteArray(), tileEntitiesByteOut.size());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -236,8 +236,9 @@ public class NetUtil {
|
|||
out.writeByte(255);
|
||||
}
|
||||
|
||||
public static Column readColumn(byte data[], int x, int z, boolean fullChunk, boolean hasSkylight, int mask) throws IOException {
|
||||
public static Column readColumn(byte data[], int x, int z, boolean fullChunk, boolean hasSkylight, int mask, byte tileEntityData[]) throws IOException {
|
||||
NetInput in = new StreamNetInput(new ByteArrayInputStream(data));
|
||||
NetInput tileEntityIn = new StreamNetInput(new ByteArrayInputStream(tileEntityData));
|
||||
Exception ex = null;
|
||||
Column column = null;
|
||||
try {
|
||||
|
@ -256,14 +257,20 @@ public class NetUtil {
|
|||
biomeData = in.readBytes(256);
|
||||
}
|
||||
|
||||
column = new Column(x, z, chunks, biomeData);
|
||||
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()]));
|
||||
} 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);
|
||||
return readColumn(data, x, z, fullChunk, true, mask, tileEntityData);
|
||||
} else if(ex != null) {
|
||||
throw new IOException("Failed to read chunk data.", ex);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue