Skip to content

Commit 9182999

Browse files
committed
sends light along with chunk data
1 parent 0c045ad commit 9182999

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

src/main/java/net/potato/tuff/TuffX.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,39 @@ private byte[] createWelcomePayload(String message, int someNumber) {
315315
}
316316

317317
private byte[] createSectionPayload(ChunkSnapshot snapshot, int cx, int cz, int sectionY, Map<BlockData, int[]> cache) throws IOException {
318-
try (ByteArrayOutputStream bout = new ByteArrayOutputStream(8200); DataOutputStream out = new DataOutputStream(bout)) {
319-
out.writeUTF("chunk_data");
320-
out.writeInt(cx); out.writeInt(cz); out.writeInt(sectionY);
321-
boolean hasNonAirBlock = false;
322-
int baseY = sectionY * 16;
323-
for (int y = 0; y < 16; y++) for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) {
324-
int worldY = baseY + y;
325-
BlockData blockData = snapshot.getBlockData(x, worldY, z);
326-
327-
int[] legacyData = cache.computeIfAbsent(blockData, viablockids::toLegacy);
328-
329-
if (legacyData[0] != 0) hasNonAirBlock = true;
330-
out.writeShort((short) ((legacyData[1] << 12) | (legacyData[0] & 0xFFF)));
318+
try (ByteArrayOutputStream bout = new ByteArrayOutputStream(12300); DataOutputStream out = new DataOutputStream(bout)) {
319+
out.writeUTF("chunk_data");
320+
out.writeInt(cx);
321+
out.writeInt(cz);
322+
out.writeInt(sectionY);
323+
324+
boolean hasAnythingToSend = false;
325+
int baseY = sectionY * 16;
326+
327+
for (int y = 0; y < 16; y++) {
328+
for (int z = 0; z < 16; z++) {
329+
for (int x = 0; x < 16; x++) {
330+
int worldY = baseY + y;
331+
332+
BlockData blockData = snapshot.getBlockData(x, worldY, z);
333+
int[] legacyData = cache.computeIfAbsent(blockData, viablockids::toLegacy);
334+
out.writeShort((short) ((legacyData[1] << 12) | (legacyData[0] & 0xFFF)));
335+
336+
int blockLight = snapshot.getBlockEmittedLight(x, worldY, z);
337+
int skyLight = snapshot.getBlockSkyLight(x, worldY, z);
338+
out.writeByte((byte) ((skyLight << 4) | blockLight));
339+
340+
if (legacyData[0] != 0 || blockLight != 0 || skyLight != 0) {
341+
hasAnythingToSend = true;
342+
}
343+
}
331344
}
332-
return hasNonAirBlock ? bout.toByteArray() : null;
333345
}
346+
347+
return hasAnythingToSend ? bout.toByteArray() : null;
334348
}
349+
}
350+
335351

336352
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
337353
public void onBlockBreak(BlockBreakEvent event) { if (event.getBlock().getY() < 0) sendBlockUpdateToNearby(event.getBlock().getLocation(), Material.AIR.createBlockData()); }

target/TuffX.jar

154 Bytes
Binary file not shown.
264 Bytes
Binary file not shown.

target/original-TuffX.jar

154 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)