Entity Animation (1.9)

This commit is contained in:
Bixilon 2020-07-02 20:38:55 +02:00
parent 8527f15a98
commit 5f0cc569d4
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -13,14 +13,17 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play; package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.game.datatypes.MapSet;
import de.bixilon.minosoft.game.datatypes.VersionValueMap;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler; import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketEntityAnimation implements ClientboundPacket { public class PacketEntityAnimation implements ClientboundPacket {
int entityId; int entityId;
Animations animation; EntityAnimations animation;
@Override @Override
public boolean read(InPacketBuffer buffer) { public boolean read(InPacketBuffer buffer) {
@ -29,7 +32,7 @@ public class PacketEntityAnimation implements ClientboundPacket {
case VERSION_1_8: case VERSION_1_8:
case VERSION_1_9_4: case VERSION_1_9_4:
entityId = buffer.readVarInt(); entityId = buffer.readVarInt();
animation = Animations.byId(buffer.readByte()); animation = EntityAnimations.byId(buffer.readByte(), buffer.getVersion());
return true; return true;
} }
@ -46,34 +49,39 @@ public class PacketEntityAnimation implements ClientboundPacket {
h.handle(this); h.handle(this);
} }
public enum Animations { public enum EntityAnimations {
SWING_ARM(0), SWING_RIGHT_ARM(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 0)}),
DAMAGE_ANIMATION(1), TAKE_DAMAGE(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 1)}),
LEAVE_BED(2), LEAVE_BED(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 2)}),
EAT_FOOD(3), EAT_FOOD(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 3), new MapSet<>(ProtocolVersion.VERSION_1_9_4, -1)}),
CRITICAL_EFFECT(4), SWING_LEFT_ARM(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_9_4, 3)}),
MAGIC_CRITICAL_EFFECT(5), CRITICAL_EFFECT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 4)}),
TO_DO_1(102), // name currently unknown //ToDo MAGIC_CRITICAL_EFFECT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 5)}),
SNEAK(104), UNKNOWN_1(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 102), new MapSet<>(ProtocolVersion.VERSION_1_8, -1)}), // name currently unknown //ToDo
UN_SNEAK(105); SNEAK(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 104), new MapSet<>(ProtocolVersion.VERSION_1_8, -1)}),
UN_SNEAK(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 105), new MapSet<>(ProtocolVersion.VERSION_1_8, -1)});
final int id; final VersionValueMap<Integer> valueMap;
Animations(int id) { EntityAnimations(MapSet<ProtocolVersion, Integer>[] values) {
this.id = id; valueMap = new VersionValueMap<>(values, true);
} }
public static Animations byId(int id) { public static EntityAnimations byId(int id, ProtocolVersion version) {
for (Animations a : values()) { for (EntityAnimations animation : values()) {
if (a.getId() == id) { if (animation.getId(version) == id) {
return a; return animation;
} }
} }
return null; return null;
} }
public int getId() { public int getId(ProtocolVersion version) {
return id; Integer ret = valueMap.get(version);
if (ret == null) {
return -2;
}
return ret;
} }
} }
} }