From c1b6f71452a37f08b8aab8b5439e0da8513380c2 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 24 Jul 2020 23:24:39 +0200 Subject: [PATCH] PacketUpdateJigsawBlock, PacketAcknowledgePlayerDigging --- .../login/PacketEncryptionRequest.java | 1 + .../play/PacketAcknowledgePlayerDigging.java | 71 +++++++++++++++++++ .../clientbound/play/PacketEntityEffect.java | 29 ++++++-- .../serverbound/play/PacketPlayerDigging.java | 10 +++ .../play/PacketUpdateJigsawBlock.java | 52 ++++++++++++++ .../protocol/protocol/PacketHandler.java | 3 + .../minosoft/protocol/protocol/Protocol.java | 1 + 7 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java index 2661734cb..8084b40cc 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java @@ -19,6 +19,7 @@ import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; public class PacketEncryptionRequest implements ClientboundPacket { + String serverId; //normally empty byte[] publicKey; byte[] verifyToken; diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java new file mode 100644 index 000000000..e9670cd65 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java @@ -0,0 +1,71 @@ +/* + * 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.objectLoader.blocks.Block; +import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks; +import de.bixilon.minosoft.game.datatypes.world.BlockPosition; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerDigging; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; + +public class PacketAcknowledgePlayerDigging implements ClientboundPacket { + BlockPosition position; + Block block; + PacketPlayerDigging.DiggingStatus status; + boolean successful; + + + @Override + public boolean read(InByteBuffer buffer) { + switch (buffer.getVersion()) { + case VERSION_1_14_4: + position = buffer.readPosition(); + block = Blocks.getBlock(buffer.readVarInt(), buffer.getVersion()); + status = PacketPlayerDigging.DiggingStatus.byId(buffer.readVarInt()); + successful = buffer.readBoolean(); + return true; + } + + return false; + } + + @Override + public void log() { + Log.protocol(String.format("Received acknowledge digging packet (position=%s, block=%s, status=%s, successful=%s)", position.toString(), block, status, successful)); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public BlockPosition getPosition() { + return position; + } + + public Block getBlock() { + return block; + } + + public PacketPlayerDigging.DiggingStatus getStatus() { + return status; + } + + public boolean isSuccessful() { + return successful; + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java index 6ee96439c..bfd2f294c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java @@ -19,12 +19,15 @@ 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.protocol.protocol.ProtocolVersion; import de.bixilon.minosoft.util.BitByte; public class PacketEntityEffect implements ClientboundPacket { int entityId; StatusEffect effect; - boolean hideParticle; + boolean isAmbient; + boolean hideParticles; + boolean showIcon; @Override @@ -33,13 +36,13 @@ public class PacketEntityEffect implements ClientboundPacket { case VERSION_1_7_10: entityId = buffer.readInt(); effect = new StatusEffect(StatusEffects.byId(buffer.readByte()), buffer.readByte(), buffer.readShort()); - hideParticle = false; + hideParticles = false; return true; case VERSION_1_8: case VERSION_1_9_4: entityId = buffer.readVarInt(); effect = new StatusEffect(StatusEffects.byId(buffer.readByte()), buffer.readByte(), buffer.readVarInt()); - hideParticle = buffer.readBoolean(); + hideParticles = buffer.readBoolean(); return true; case VERSION_1_10: case VERSION_1_11_2: @@ -49,7 +52,13 @@ public class PacketEntityEffect implements ClientboundPacket { entityId = buffer.readVarInt(); effect = new StatusEffect(StatusEffects.byId(buffer.readByte()), buffer.readByte(), buffer.readVarInt()); byte flags = buffer.readByte(); - hideParticle = BitByte.isBitMask(flags, 0x02); + isAmbient = BitByte.isBitMask(flags, 0x01); + hideParticles = !BitByte.isBitMask(flags, 0x02); + if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_14_4.getVersionNumber()) { + showIcon = BitByte.isBitMask(flags, 0x04); + } else { + showIcon = true; + } return true; } @@ -73,4 +82,16 @@ public class PacketEntityEffect implements ClientboundPacket { public StatusEffect getEffect() { return effect; } + + public boolean hideParticles() { + return hideParticles; + } + + public boolean showIcon() { + return showIcon; + } + + public boolean isAmbient() { + return isAmbient; + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java index d1ef284a2..50c3f2518 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java @@ -95,6 +95,16 @@ public class PacketPlayerDigging implements ServerboundPacket { this.id = id; } + + public static DiggingStatus byId(int id) { + for (DiggingStatus status : values()) { + if (status.getId() == id) { + return status; + } + } + return null; + } + public int getId() { return id; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java new file mode 100644 index 000000000..dc2588271 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java @@ -0,0 +1,52 @@ +/* + * 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.game.datatypes.world.BlockPosition; +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 PacketUpdateJigsawBlock implements ServerboundPacket { + final BlockPosition position; + final String attachmentType; + final String targetPool; + final String finalState; + + public PacketUpdateJigsawBlock(BlockPosition position, String attachmentType, String targetPool, String finalState) { + this.position = position; + this.attachmentType = attachmentType; + this.targetPool = targetPool; + this.finalState = finalState; + } + + + @Override + public OutPacketBuffer write(ProtocolVersion version) { + OutPacketBuffer buffer = new OutPacketBuffer(version, version.getPacketCommand(Packets.Serverbound.PLAY_UPDATE_JIGSAW_BLOCK)); + switch (version) { + case VERSION_1_14_4: + buffer.writePosition(position); + break; + } + return buffer; + } + + @Override + public void log() { + Log.protocol(String.format("Updating jigsaw block (position=%s, attachmentType=%s, targetPool=%s, finalState=%s)", position, attachmentType, targetPool, finalState)); + } +} 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 b40c46a87..3c3944f52 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -616,4 +616,7 @@ public class PacketHandler { public void handle(PacketOpenBook pkg) { } + + public void handle(PacketAcknowledgePlayerDigging 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 50d76ecbf..7d3af5990 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -123,6 +123,7 @@ public abstract class Protocol implements ProtocolInterface { 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); + packetClassMapping.put(Packets.Clientbound.PLAY_ACKNOWLEDGE_PLAYER_DIGGING, PacketAcknowledgePlayerDigging.class); } protected final HashMap> serverboundPacketMapping;