Protocol slots (1)
| ID | dec | State | Direction | Registry |
|---|
| 0x6A | 106 | PLAY | Clientbound | GamePacketTypes.CLIENTBOUND_SET_HEALTH: "set_health" |
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 (3)
| Field | Type |
|---|
health | float |
food | int |
saturation | float |
Stream codec
static final StreamCodec<FriendlyByteBuf, ClientboundSetHealthPacket> STREAM_CODEC = Packet.codec( ClientboundSetHealthPacket::write, ClientboundSetHealthPacket::new );
Modern packets serialize through StreamCodecs instead of read/write methods.
Handling
Resolved on the ClientGamePacketListener packet-listener interface by void handleSetHealth(ClientboundSetHealthPacket clientboundsethealthpacket). 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 |
|
| 8 | public class ClientboundSetHealthPacket implements Packet<ClientGamePacketListener> {
|
| 9 | public static final StreamCodec<FriendlyByteBuf, ClientboundSetHealthPacket> STREAM_CODEC = Packet.codec(
|
| 10 | ClientboundSetHealthPacket::write, ClientboundSetHealthPacket::new
|
| 11 | );
|
| 12 | private final float health;
|
| 13 | private final int food;
|
| 14 | private final float saturation;
|
| 15 |
|
| 16 | public ClientboundSetHealthPacket(final float health, final int food, final float saturation) {
|
| 17 | this.health = health;
|
| 18 | this.food = food;
|
| 19 | this.saturation = saturation;
|
| 20 | }
|
| 21 |
|
| 22 | private ClientboundSetHealthPacket(final FriendlyByteBuf input) {
|
| 23 | this.health = input.readFloat();
|
| 24 | this.food = input.readVarInt();
|
| 25 | this.saturation = input.readFloat();
|
| 26 | }
|
| 27 |
|
| 28 | private void write(final FriendlyByteBuf output) {
|
| 29 | output.writeFloat(this.health);
|
| 30 | output.writeVarInt(this.food);
|
| 31 | output.writeFloat(this.saturation);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public PacketType<ClientboundSetHealthPacket> type() {
|
| 36 | return GamePacketTypes.CLIENTBOUND_SET_HEALTH;
|
| 37 | }
|
| 38 |
|
| 39 | public void handle(final ClientGamePacketListener listener) {
|
| 40 | listener.handleSetHealth(this);
|
| 41 | }
|
| 42 |
|
| 43 | public float getHealth() {
|
| 44 | return this.health;
|
| 45 | }
|
| 46 |
|
| 47 | public int getFood() {
|
| 48 | return this.food;
|
| 49 | }
|
| 50 |
|
| 51 | public float getSaturation() {
|
| 52 | return this.saturation;
|
| 53 | }
|
| 54 | }
|
| 55 |
|