ClientboundSetScorePacket 0x70

ClientboundSetScorePacket: Minecraft 26.3 packet (0x70 Play clientbound). Wire name 'set_score', fields: owner, objectiveName, score, display

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x70112PLAYClientboundGamePacketTypes.CLIENTBOUND_SET_SCORE: "set_score"

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 (5)

FieldType
ownerString
objectiveNameString
scoreint
displayOptional<Component>
numberFormatOptional<NumberFormat>

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSetScorePacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.STRING_UTF8, ClientboundSetScorePacket::owner, ByteBufCodecs.STRING_UTF

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleSetScore(ClientboundSetScorePacket clientboundsetscorepacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundSetScorePacket.java39 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.Optional;
4
import net.minecraft.network.RegistryFriendlyByteBuf;
5
import net.minecraft.network.chat.Component;
6
import net.minecraft.network.chat.ComponentSerialization;
7
import net.minecraft.network.chat.numbers.NumberFormat;
8
import net.minecraft.network.chat.numbers.NumberFormatTypes;
9
import net.minecraft.network.codec.ByteBufCodecs;
10
import net.minecraft.network.codec.StreamCodec;
11
import net.minecraft.network.protocol.Packet;
12
import net.minecraft.network.protocol.PacketType;
13
14
public record ClientboundSetScorePacket(String owner, String objectiveName, int score, Optional<Component> display, Optional<NumberFormat> numberFormat)
15
	implements Packet<ClientGamePacketListener> {
16
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSetScorePacket> STREAM_CODEC = StreamCodec.composite(
17
		ByteBufCodecs.STRING_UTF8,
18
		ClientboundSetScorePacket::owner,
19
		ByteBufCodecs.STRING_UTF8,
20
		ClientboundSetScorePacket::objectiveName,
21
		ByteBufCodecs.VAR_INT,
22
		ClientboundSetScorePacket::score,
23
		ComponentSerialization.TRUSTED_OPTIONAL_STREAM_CODEC,
24
		ClientboundSetScorePacket::display,
25
		NumberFormatTypes.OPTIONAL_STREAM_CODEC,
26
		ClientboundSetScorePacket::numberFormat,
27
		ClientboundSetScorePacket::new
28
	);
29
30
	@Override
31
	public PacketType<ClientboundSetScorePacket> type() {
32
		return GamePacketTypes.CLIENTBOUND_SET_SCORE;
33
	}
34
35
	public void handle(final ClientGamePacketListener listener) {
36
		listener.handleSetScore(this);
37
	}
38
}
39