оптимизация передачи данных block light
This commit is contained in:
@@ -23,9 +23,17 @@ public class BlockLocation implements Cloneable {
|
|||||||
|
|
||||||
public BlockLocation toGlobal(ChunkSection chunkSection) {
|
public BlockLocation toGlobal(ChunkSection chunkSection) {
|
||||||
return new BlockLocation(
|
return new BlockLocation(
|
||||||
(chunkSection.getX() << 8) + x,
|
(chunkSection.getX() << 4) + x,
|
||||||
(chunkSection.getY() << 8) + y,
|
(chunkSection.getY() << 4) + y,
|
||||||
(chunkSection.getZ() << 8) + z
|
(chunkSection.getZ() << 4) + z
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockLocation toLocal() {
|
||||||
|
return new BlockLocation(
|
||||||
|
x - (x >> 4 << 4),
|
||||||
|
y - (y >> 4 << 4),
|
||||||
|
z - (z >> 4 << 4)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,14 +184,12 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
private TIntList palette = new TIntArrayList();
|
private TIntList palette = new TIntArrayList();
|
||||||
private int dataItems = 0;
|
private int dataItems = 0;
|
||||||
private ByteArrayOutputNetStream dataArray = new ByteArrayOutputNetStream();
|
private ByteArrayOutputNetStream dataArray = new ByteArrayOutputNetStream();
|
||||||
private ByteArrayOutputNetStream blockLight = new ByteArrayOutputNetStream();
|
private NibbleArray blockLight = new NibbleArray();
|
||||||
private NibbleArray skyLight = new NibbleArray();
|
private NibbleArray skyLight = new NibbleArray();
|
||||||
|
|
||||||
private int idxHalfLong = 0;
|
private int idxHalfLong = 0;
|
||||||
private int idxHalfByte1 = 0;
|
|
||||||
|
|
||||||
private long dataValueCompacted = 0;
|
private long dataValueCompacted = 0;
|
||||||
private int blockLightCompacted = 0;
|
|
||||||
|
|
||||||
private int serializeBlockState(BlockType blockType) {
|
private int serializeBlockState(BlockType blockType) {
|
||||||
return (blockType.getId() << 4) | blockType.getMeta();
|
return (blockType.getId() << 4) | blockType.getMeta();
|
||||||
@@ -230,14 +228,7 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// block light data
|
// block light data
|
||||||
if (idxHalfByte1 == 0) {
|
blockLight.set(block.getLocation().toLocal(), block.getLight());
|
||||||
blockLightCompacted = block.getLight();
|
|
||||||
idxHalfByte1++;
|
|
||||||
} else {
|
|
||||||
blockLightCompacted = (blockLightCompacted << 4) | block.getLight();
|
|
||||||
blockLight.writeByte(blockLightCompacted);
|
|
||||||
idxHalfByte1 = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSkyLight(int x, int y, int z, int value) {
|
void addSkyLight(int x, int y, int z, int value) {
|
||||||
@@ -256,7 +247,7 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
netOutputStream.writeBytes(dataArray.toByteArray()); // Data Array
|
netOutputStream.writeBytes(dataArray.toByteArray()); // Data Array
|
||||||
// </Data Array>
|
// </Data Array>
|
||||||
// <Block Light>
|
// <Block Light>
|
||||||
netOutputStream.writeBytes(blockLight.toByteArray());
|
netOutputStream.writeBytes(blockLight.getRawData());
|
||||||
// </Block Light>
|
// </Block Light>
|
||||||
// <Sky Light>
|
// <Sky Light>
|
||||||
netOutputStream.writeBytes(skyLight.getRawData());
|
netOutputStream.writeBytes(skyLight.getRawData());
|
||||||
|
|||||||
Reference in New Issue
Block a user