ClientboundStopSoundPacket 0x79

ClientboundStopSoundPacket: Minecraft 26.3 packet (0x79 Play clientbound). Wire name 'stop_sound', fields: name, source, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x79121PLAYClientboundGamePacketTypes.CLIENTBOUND_STOP_SOUND: "stop_sound"

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)

FieldType
name@Nullable Identifier
source@Nullable SoundSource

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleStopSoundEvent(ClientboundStopSoundPacket clientboundstopsoundpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundStopSoundPacket.java75 lines · Minecraft 26.3 · verbatimSource page ↗
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.resources.Identifier;
8
import net.minecraft.sounds.SoundSource;
9
import org.jspecify.annotations.Nullable;
10
11
public class ClientboundStopSoundPacket implements Packet<ClientGamePacketListener> {
12
	public static final StreamCodec<FriendlyByteBuf, ClientboundStopSoundPacket> STREAM_CODEC = Packet.codec(
13
		ClientboundStopSoundPacket::write, ClientboundStopSoundPacket::new
14
	);
15
	private static final int HAS_SOURCE = 1;
16
	private static final int HAS_SOUND = 2;
17
	private final @Nullable Identifier name;
18
	private final @Nullable SoundSource source;
19
20
	public ClientboundStopSoundPacket(final @Nullable Identifier name, final @Nullable SoundSource source) {
21
		this.name = name;
22
		this.source = source;
23
	}
24
25
	private ClientboundStopSoundPacket(final FriendlyByteBuf input) {
26
		int flags = input.readByte();
27
		if ((flags & 1) > 0) {
28
			this.source = input.readEnum(SoundSource.class);
29
		} else {
30
			this.source = null;
31
		}
32
33
		if ((flags & 2) > 0) {
34
			this.name = input.readIdentifier();
35
		} else {
36
			this.name = null;
37
		}
38
	}
39
40
	private void write(final FriendlyByteBuf output) {
41
		if (this.source != null) {
42
			if (this.name != null) {
43
				output.writeByte(3);
44
				output.writeEnum(this.source);
45
				output.writeIdentifier(this.name);
46
			} else {
47
				output.writeByte(1);
48
				output.writeEnum(this.source);
49
			}
50
		} else if (this.name != null) {
51
			output.writeByte(2);
52
			output.writeIdentifier(this.name);
53
		} else {
54
			output.writeByte(0);
55
		}
56
	}
57
58
	@Override
59
	public PacketType<ClientboundStopSoundPacket> type() {
60
		return GamePacketTypes.CLIENTBOUND_STOP_SOUND;
61
	}
62
63
	public void handle(final ClientGamePacketListener listener) {
64
		listener.handleStopSoundEvent(this);
65
	}
66
67
	public @Nullable Identifier getName() {
68
		return this.name;
69
	}
70
71
	public @Nullable SoundSource getSource() {
72
		return this.source;
73
	}
74
}
75