Protocol slots (1)
| ID | dec | State | Direction | Registry |
|---|
| 0x02 | 2 | PLAY | Clientbound | GamePacketTypes.CLIENTBOUND_ANIMATE: "animate" |
Packet ids are positional: the id is the index of the addPacket call in the protocol builder (see ProtocolInfoBuilder.listPackets). Ids change between game versions.
Wire fields (2)
| Field | Type |
|---|
entity | Entity |
action | int |
Stream codec
static final StreamCodec<FriendlyByteBuf, ClientboundAnimatePacket> STREAM_CODEC = Packet.codec( ClientboundAnimatePacket::write, ClientboundAnimatePacket::new );
Modern packets serialize through StreamCodecs instead of read/write methods.
Handling
Resolved on the ClientGamePacketListener packet-listener interface by void handleAnimate(ClientboundAnimatePacket clientboundanimatepacket). The implementation in the game is ClientPacketListener.
Full Source
| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import net.minecraft.network.FriendlyByteBuf;
|
| 4 | import net.minecraft.network.codec.StreamCodec;
|
| 5 | import net.minecraft.network.protocol.Packet;
|
| 6 | import net.minecraft.network.protocol.PacketType;
|
| 7 | import net.minecraft.world.entity.Entity;
|
| 8 |
|
| 9 | public class ClientboundAnimatePacket implements Packet<ClientGamePacketListener> {
|
| 10 | public static final StreamCodec<FriendlyByteBuf, ClientboundAnimatePacket> STREAM_CODEC = Packet.codec(
|
| 11 | ClientboundAnimatePacket::write, ClientboundAnimatePacket::new
|
| 12 | );
|
| 13 | public static final int WAKE_UP = 0;
|
| 14 | public static final int CRITICAL_HIT = 1;
|
| 15 | public static final int MAGIC_CRITICAL_HIT = 2;
|
| 16 | private final int id;
|
| 17 | private final int action;
|
| 18 |
|
| 19 | public ClientboundAnimatePacket(final Entity entity, final int action) {
|
| 20 | this.id = entity.getId();
|
| 21 | this.action = action;
|
| 22 | }
|
| 23 |
|
| 24 | private ClientboundAnimatePacket(final FriendlyByteBuf input) {
|
| 25 | this.id = input.readVarInt();
|
| 26 | this.action = input.readUnsignedByte();
|
| 27 | }
|
| 28 |
|
| 29 | private void write(final FriendlyByteBuf output) {
|
| 30 | output.writeVarInt(this.id);
|
| 31 | output.writeByte(this.action);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public PacketType<ClientboundAnimatePacket> type() {
|
| 36 | return GamePacketTypes.CLIENTBOUND_ANIMATE;
|
| 37 | }
|
| 38 |
|
| 39 | public void handle(final ClientGamePacketListener listener) {
|
| 40 | listener.handleAnimate(this);
|
| 41 | }
|
| 42 |
|
| 43 | public int getId() {
|
| 44 | return this.id;
|
| 45 | }
|
| 46 |
|
| 47 | public int getAction() {
|
| 48 | return this.action;
|
| 49 | }
|
| 50 | }
|
| 51 |
|