entity status and animations

This commit is contained in:
bixilon 2020-06-15 22:15:42 +02:00
parent af9d75e764
commit e4eee73145
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 174 additions and 0 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}
}

View File

@ -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
}
}

View File

@ -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();