From a368f0babc905773d517f04af406588de13350cb Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Wed, 24 Oct 2018 19:07:16 -0300 Subject: [PATCH] trying to implement lightning based on Pokechu22 documentation --- .../packets/WorldPackets.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java index a8c7c93e6..dc68b6395 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java @@ -1,5 +1,7 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; +import com.google.common.primitives.Bytes; +import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; @@ -14,8 +16,6 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -import java.util.Arrays; - public class WorldPackets { public static void register(Protocol protocol) { @@ -38,9 +38,40 @@ public class WorldPackets { } } - if (chunk.isBiomeData()) { - Arrays.fill(chunk.getBiomeData(), (byte) 0); //TODO map biome ids + PacketWrapper lightPacket = wrapper.create(0x57); + lightPacket.write(Type.VAR_INT, chunk.getX()); + lightPacket.write(Type.VAR_INT, chunk.getZ()); + int skyLightMask = 0; + int blockLightMask = 0; + for (int i = 0; i < chunk.getSections().length; i++) { + ChunkSection sec = chunk.getSections()[i]; + if (sec == null) continue; + if (sec.hasSkyLight()) { + skyLightMask |= (1 << (i + 1)); + } + blockLightMask |= (1 << (i + 1)); } + lightPacket.write(Type.VAR_INT, blockLightMask); + lightPacket.write(Type.VAR_INT, skyLightMask); + for (ChunkSection section : chunk.getSections()) { + if (section == null) continue; + ByteBuf buf = wrapper.user().getChannel().alloc().buffer(); + section.writeBlockLight(buf); + byte[] data = new byte[buf.readableBytes()]; + buf.readBytes(data); + buf.release(); + lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(data).toArray(new Byte[0])); + } + for (ChunkSection section : chunk.getSections()) { + if (section == null || !section.hasSkyLight()) continue; + ByteBuf buf = wrapper.user().getChannel().alloc().buffer(); + section.writeSkyLight(buf); + byte[] data = new byte[buf.readableBytes()]; + buf.readBytes(data); + buf.release(); + lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(data).toArray(new Byte[0])); + } + lightPacket.send(Protocol1_14To1_13_2.class); } }); }