ClientboundUpdateMobEffectPacket 0x87

ClientboundUpdateMobEffectPacket: Minecraft 26.3 packet (0x87 Play clientbound). Wire name 'update_mob_effect', fields: entityId, effect, blend, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x87135PLAYClientboundGamePacketTypes.CLIENTBOUND_UPDATE_MOB_EFFECT: "update_mob_effect"

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)

FieldType
entityIdint
effectMobEffectInstance
blendboolean

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundUpdateMobEffectPacket> STREAM_CODEC = Packet.codec( ClientboundUpdateMobEffectPacket::write, ClientboundUpdateMobEffectPacket::new );

Modern packets serialize through StreamCodecs instead of read/write methods.

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleUpdateMobEffect(ClientboundUpdateMobEffectPacket clientboundupdatemobeffectpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundUpdateMobEffectPacket.java107 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.core.Holder;
4
import net.minecraft.network.RegistryFriendlyByteBuf;
5
import net.minecraft.network.codec.StreamCodec;
6
import net.minecraft.network.protocol.Packet;
7
import net.minecraft.network.protocol.PacketType;
8
import net.minecraft.world.effect.MobEffect;
9
import net.minecraft.world.effect.MobEffectInstance;
10
11
public class ClientboundUpdateMobEffectPacket implements Packet<ClientGamePacketListener> {
12
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundUpdateMobEffectPacket> STREAM_CODEC = Packet.codec(
13
		ClientboundUpdateMobEffectPacket::write, ClientboundUpdateMobEffectPacket::new
14
	);
15
	private static final int FLAG_AMBIENT = 1;
16
	private static final int FLAG_VISIBLE = 2;
17
	private static final int FLAG_SHOW_ICON = 4;
18
	private static final int FLAG_BLEND = 8;
19
	private final int entityId;
20
	private final Holder<MobEffect> effect;
21
	private final int effectAmplifier;
22
	private final int effectDurationTicks;
23
	private final byte flags;
24
25
	public ClientboundUpdateMobEffectPacket(final int entityId, final MobEffectInstance effect, final boolean blend) {
26
		this.entityId = entityId;
27
		this.effect = effect.getEffect();
28
		this.effectAmplifier = effect.getAmplifier();
29
		this.effectDurationTicks = effect.getDuration();
30
		byte flags = 0;
31
		if (effect.isAmbient()) {
32
			flags = (byte)(flags | 1);
33
		}
34
35
		if (effect.isVisible()) {
36
			flags = (byte)(flags | 2);
37
		}
38
39
		if (effect.showIcon()) {
40
			flags = (byte)(flags | 4);
41
		}
42
43
		if (blend) {
44
			flags = (byte)(flags | 8);
45
		}
46
47
		this.flags = flags;
48
	}
49
50
	private ClientboundUpdateMobEffectPacket(final RegistryFriendlyByteBuf input) {
51
		this.entityId = input.readVarInt();
52
		this.effect = MobEffect.STREAM_CODEC.decode(input);
53
		this.effectAmplifier = input.readVarInt();
54
		this.effectDurationTicks = input.readVarInt();
55
		this.flags = input.readByte();
56
	}
57
58
	private void write(final RegistryFriendlyByteBuf output) {
59
		output.writeVarInt(this.entityId);
60
		MobEffect.STREAM_CODEC.encode(output, this.effect);
61
		output.writeVarInt(this.effectAmplifier);
62
		output.writeVarInt(this.effectDurationTicks);
63
		output.writeByte(this.flags);
64
	}
65
66
	@Override
67
	public PacketType<ClientboundUpdateMobEffectPacket> type() {
68
		return GamePacketTypes.CLIENTBOUND_UPDATE_MOB_EFFECT;
69
	}
70
71
	public void handle(final ClientGamePacketListener listener) {
72
		listener.handleUpdateMobEffect(this);
73
	}
74
75
	public int getEntityId() {
76
		return this.entityId;
77
	}
78
79
	public Holder<MobEffect> getEffect() {
80
		return this.effect;
81
	}
82
83
	public int getEffectAmplifier() {
84
		return this.effectAmplifier;
85
	}
86
87
	public int getEffectDurationTicks() {
88
		return this.effectDurationTicks;
89
	}
90
91
	public boolean isEffectVisible() {
92
		return (this.flags & 2) != 0;
93
	}
94
95
	public boolean isEffectAmbient() {
96
		return (this.flags & 1) != 0;
97
	}
98
99
	public boolean effectShowsIcon() {
100
		return (this.flags & 4) != 0;
101
	}
102
103
	public boolean shouldBlend() {
104
		return (this.flags & 8) != 0;
105
	}
106
}
107