From 4c819fae3cec218b1fb14caf4444ffaa2a7490ca Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 24 Jul 2020 22:24:55 +0200 Subject: [PATCH] PacketOpenBook --- .../clientbound/play/PacketOpenBook.java | 50 +++++++++++++++++++ .../protocol/protocol/PacketHandler.java | 3 ++ .../minosoft/protocol/protocol/Protocol.java | 1 + 3 files changed, 54 insertions(+) create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java new file mode 100644 index 000000000..e2591adb9 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java @@ -0,0 +1,50 @@ +/* + * 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.player.Hand; +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; + +public class PacketOpenBook implements ClientboundPacket { + Hand hand; + + + @Override + public boolean read(InByteBuffer buffer) { + switch (buffer.getVersion()) { + case VERSION_1_14_4: + hand = Hand.byId(buffer.readVarInt()); + return true; + } + + return false; + } + + @Override + public void log() { + Log.protocol(String.format("Received open book packet (hand=%s)", hand)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public Hand getHand() { + return hand; + } +} 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 29bf9f714..b40c46a87 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -613,4 +613,7 @@ public class PacketHandler { public void handle(PacketTradeList pkg) { } + + public void handle(PacketOpenBook 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 950998421..50d76ecbf 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -122,6 +122,7 @@ public abstract class Protocol implements ProtocolInterface { packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_VIEW_POSITION, PacketUpdateViewPosition.class); packetClassMapping.put(Packets.Clientbound.PLAY_OPEN_HORSE_WINDOW, PacketOpenHorseWindow.class); packetClassMapping.put(Packets.Clientbound.PLAY_TRADE_LIST, PacketTradeList.class); + packetClassMapping.put(Packets.Clientbound.PLAY_OPEN_BOOK, PacketOpenBook.class); } protected final HashMap> serverboundPacketMapping;