ClientboundStopSoundPacket .java

net.minecraft.network.protocol.game.ClientboundStopSoundPacket (class): members: HAS_SOURCE, HAS_SOUND, getSource, source, getName, name, handle, type.

net.minecraft.network.protocol.gameclass75 linescommon2.0 KB

Implements

API Surface (2)

PacketType<ClientboundStopSoundPacket> type()
void handle(final ClientGamePacketListener listener)

Fields & Constants (5)

STREAM_CODEC
HAS_SOURCE
HAS_SOUND
name
source

Same Package (197)

Full Source

ClientboundStopSoundPacket.java75 lines · Minecraft 26.3 · verbatim
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

Decompiled Minecraft 26.3 source of ClientboundStopSoundPacket (net/minecraft/network/protocol/game/ClientboundStopSoundPacket.java) with Mojang official mappings, stored verbatim on the site.