diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateLight.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateLight.java new file mode 100644 index 000000000..0ad2748a2 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateLight.java @@ -0,0 +1,51 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.game.datatypes.world.ChunkLocation; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.util.ChunkUtil; + +public class PacketUpdateLight implements ClientboundPacket { + ChunkLocation location; + + @Override + public boolean read(InByteBuffer buffer) { + switch (buffer.getVersion()) { + case VERSION_1_14_4: + location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt()); + int skyLightMask = buffer.readVarInt(); + int blockLightMask = buffer.readVarInt(); + int emptyBlockLightMask = buffer.readVarInt(); + int emptySkyLightMask = buffer.readVarInt(); + ChunkUtil.readSkyLightPacket(buffer, skyLightMask, blockLightMask, emptyBlockLightMask, emptySkyLightMask); + return true; + } + + return false; + } + + @Override + public void log() { + Log.protocol(String.format("Received sky light update (location=%s)", location)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index ed54f3967..a02259caf 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -602,4 +602,7 @@ public class PacketHandler { public void handle(PacketStopSound pkg) { } + + public void handle(PacketUpdateLight pkg) { + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java index c65abf0be..a2fa1c45f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -158,6 +158,7 @@ public abstract class Protocol implements ProtocolInterface { packetClassMapping.put(Packets.Clientbound.PLAY_TAGS, PacketTags.class); packetClassMapping.put(Packets.Clientbound.PLAY_DECLARE_RECIPES, PacketDeclareRecipes.class); packetClassMapping.put(Packets.Clientbound.PLAY_STOP_SOUND, PacketStopSound.class); + packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_LIGHT, PacketUpdateLight.class); } public static ProtocolVersion getLowestVersionSupported() { diff --git a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java index c01df3760..24314d0bb 100644 --- a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java +++ b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java @@ -196,7 +196,7 @@ public class ChunkUtil { } } - if (buffer.getVersion().getVersionNumber() < ProtocolVersion.VERSION_1_14_4.getVersionNumber()) { + if (buffer.getVersion().getVersionNumber() <= ProtocolVersion.VERSION_1_13_2.getVersionNumber()) { byte[] light = buffer.readBytes(2048); if (containsSkyLight) { byte[] skyLight = buffer.readBytes(2048); @@ -212,4 +212,20 @@ public class ChunkUtil { throw new RuntimeException("Could not parse chunk!"); } + public static void readSkyLightPacket(InByteBuffer buffer, int skyLightMask, int blockLightMask, int emptyBlockLightMask, int emptySkyLightMask) { + for (byte c = 0; c < 18; c++) { // light sections + if (!BitByte.isBitSet(skyLightMask, c)) { + continue; + } + byte[] skyLight = buffer.readBytes(buffer.readVarInt()); + } + for (byte c = 0; c < 18; c++) { // light sections + if (!BitByte.isBitSet(blockLightMask, c)) { + continue; + } + byte[] blockLight = buffer.readBytes(buffer.readVarInt()); + } + // ToDo + } + }