From e4eee7314516d133ea7468fe16bfe6d47592c77f Mon Sep 17 00:00:00 2001 From: bixilon Date: Mon, 15 Jun 2020 22:15:42 +0200 Subject: [PATCH] entity status and animations --- .../play/PacketEntityAnimation.java | 77 ++++++++++++++++ .../clientbound/play/PacketEntityStatus.java | 87 +++++++++++++++++++ .../protocol/protocol/PacketHandler.java | 8 ++ .../minosoft/protocol/protocol/Protocol.java | 2 + 4 files changed, 174 insertions(+) create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java create mode 100644 src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityStatus.java diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java new file mode 100644 index 000000000..711115106 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java @@ -0,0 +1,77 @@ +/* + * 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; + +public class PacketEntityAnimation implements ClientboundPacket { + int entityId; + Animations animation; + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + entityId = buffer.readVarInt(); + animation = Animations.byId(buffer.readByte()); + + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Play entity animation (entityId=%d, animation=%s)", entityId, animation.name())); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public enum Animations { + SWING_ARM(0), + DAMAGE_ANIMATION(1), + LEAVE_BED(2), + EAT_FOOD(3), + CRITICAL_EFFECT(4), + MAGIC_CRITICAL_EFFECT(5), + TO_DO_1(102), // name currently unknown //ToDo + SNEAK(104), + UN_SNEAK(105); + + final int id; + + Animations(int id) { + this.id = id; + } + + public static Animations byId(int id) { + for (Animations a : values()) { + if (a.getId() == id) { + return a; + } + } + return null; + } + + public int getId() { + return id; + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityStatus.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityStatus.java new file mode 100644 index 000000000..036395e7a --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityStatus.java @@ -0,0 +1,87 @@ +/* + * 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; + +public class PacketEntityStatus implements ClientboundPacket { + int entityId; + Status status; + + @Override + public void read(InPacketBuffer buffer, ProtocolVersion v) { + switch (v) { + case VERSION_1_7_10: + entityId = buffer.readInteger(); + status = Status.byId(buffer.readByte()); + + break; + } + } + + @Override + public void log() { + Log.protocol(String.format("Entity status: (entityId=%d, animation=%s)", entityId, status.name())); + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + public enum Status { + TO_DO_1(0), + TO_DO_2(1), + LIVING_ENTITY_HURT(2), + LIVING_ENTITY_DEATH(3), + IRON_GOLEM_SWING_ARMS(4), + TAMING_HARTS(6), + TAMING_SMOKE(7), + WOLF_SHAKE_WATER(8), + EATING_ACCEPTED(9), + SHEEP_EATING_GRASS(10), + IRON_GOLEM_HAND_OVER_ROSE(11), + VILLAGER_MATING_HEARTS(12), + VILLAGER_ANGRY(13), + VILLAGER_HAPPY(14), + WITCH_MAGIC(15), + ZOMBIE_CONVERTING(16), + FIREWORK_EXPLODING(17), + ANIMAL_IN_LOVE(18); + + + final int id; + + Status(int id) { + this.id = id; + } + + public static Status byId(int id) { + for (Status s : values()) { + if (s.getId() == id) { + return s; + } + } + return null; + } + + public int getId() { + return id; + } + } +} 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 b0b6e661d..3b733e45e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -255,4 +255,12 @@ public class PacketHandler { public void handle(PacketUpdateSign pkg) { connection.getPlayer().getWorld().updateSign(pkg.getPosition(), pkg.getLines()); } + + public void handle(PacketEntityAnimation pkg) { + //ToDo + } + + public void handle(PacketEntityStatus pkg) { + //ToDo + } } 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 e4a6f0fce..a98115283 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java @@ -77,6 +77,8 @@ public interface Protocol { packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_EFFECT, PacketEntityEffect.class); packetClassMapping.put(Packets.Clientbound.PLAY_REMOVE_ENTITY_EFFECT, PacketRemoveEntityEffect.class); packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_SIGN, PacketUpdateSign.class); + packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class); + packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.class); } int getProtocolVersion();