diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerAbilitiesReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerAbilitiesReceiving.java new file mode 100644 index 000000000..1a8560a5c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerAbilitiesReceiving.java @@ -0,0 +1,72 @@ +/* + * 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.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; +import de.bixilon.minosoft.util.BitByte; + +public class PacketPlayerAbilitiesReceiving implements ClientboundPacket { + boolean creative; // is this needed? receiving the gameMode in change Gamestate + boolean flying; + boolean canFly; + boolean godMode; + float flyingSpeed; + float walkingSpeed; + + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + byte flags = buffer.readByte(); + creative = BitByte.isBitSet(flags, 0); + flying = BitByte.isBitSet(flags, 1); + canFly = BitByte.isBitSet(flags, 2); + godMode = BitByte.isBitSet(flags, 3); + flyingSpeed = buffer.readFloat(); + walkingSpeed = buffer.readFloat(); + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Received player abilities packet: (creative=%s, flying=%s, canFly=%s, godMode=%s, flyingSpeed=%s, walkingSpeed=%s)", creative, flying, canFly, godMode, flyingSpeed, walkingSpeed)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public boolean canFly() { + return canFly; + } + + public boolean isCreative() { + return creative; + } + + public boolean isGodMode() { + return godMode; + } + + public boolean isFlying() { + return flying; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerAbilitiesSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerAbilitiesSending.java new file mode 100644 index 000000000..ebac0ffff --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerAbilitiesSending.java @@ -0,0 +1,81 @@ +/* + * 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.serverbound.play; + +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ServerboundPacket; +import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer; +import de.bixilon.minosoft.protocol.protocol.Packets; +import de.bixilon.minosoft.protocol.protocol.ProtocolVersion; + +public class PacketPlayerAbilitiesSending implements ServerboundPacket { + boolean creative; + boolean flying; + boolean canFly; + boolean godMode; + float flyingSpeed; + float walkingSpeed; + + public PacketPlayerAbilitiesSending(boolean creative, boolean flying, boolean canFly, boolean godMode, float flyingSpeed, float walkingSpeed) { + this.creative = creative; + this.flying = flying; + this.canFly = canFly; + this.godMode = godMode; + this.flyingSpeed = flyingSpeed; + this.walkingSpeed = walkingSpeed; + log(); + } + + public PacketPlayerAbilitiesSending(boolean flying) { + this.creative = false; + this.flying = flying; + this.canFly = flying; + this.godMode = false; + this.flyingSpeed = 0.05F; + this.walkingSpeed = 0.1F; + + } + + + @Override + public OutPacketBuffer write(ProtocolVersion v) { + OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS)); + switch (v) { + case VERSION_1_7_10: + byte flags = 0; + if (creative) { + flags |= 0b1; + } + if (flying) { + flags |= 0b10; + } + if (canFly) { + flags |= 0b100; + } + if (godMode) { + flags |= 0b1000; + } + buffer.writeByte(flags); + buffer.writeFloat(flyingSpeed); + buffer.writeFloat(walkingSpeed); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Sending player abilities packet: (creative=%s, flying=%s, canFly=%s, godMode=%s, flyingSpeed=%s, walkingSpeed=%s)", creative, flying, canFly, godMode, flyingSpeed, walkingSpeed)); + } +} 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 4219bef1b..c257eb62d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -267,4 +267,8 @@ public class PacketHandler { public void handle(PacketSoundEffect pkg) { //ToDo } + + public void handle(PacketPlayerAbilitiesReceiving pkg) { + //ToDo: used to set fly abilities + } } 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 742fe0033..47a022c8c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -80,6 +80,7 @@ public interface Protocol { packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class); packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.class); packetClassMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, PacketSoundEffect.class); + packetClassMapping.put(Packets.Clientbound.PLAY_PLAYER_ABILITIES, PacketPlayerAbilitiesReceiving.class); } int getProtocolVersion();