ServerboundSetGameRulePacket 0x3A

ServerboundSetGameRulePacket: Minecraft 26.3 packet (0x3A Play serverbound). Wire name 'set_game_rule', fields: entries, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3A58PLAYServerboundGamePacketTypes.SERVERBOUND_SET_GAME_RULE: "set_game_rule"

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

FieldType
entriesList<ServerboundSetGameRulePacket.Entry>

Fields are the components of the packet record.

Stream codec

static final StreamCodec<ByteBuf, ServerboundSetGameRulePacket> STREAM_CODEC = StreamCodec.composite( ServerboundSetGameRulePacket.Entry.STREAM_CODEC.apply(ByteBufCodecs.list()), ServerboundSetGameRul

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleSetGameRule(ServerboundSetGameRulePacket serverboundsetgamerulepacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundSetGameRulePacket.java37 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.List;
5
import net.minecraft.core.registries.Registries;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.network.protocol.Packet;
9
import net.minecraft.network.protocol.PacketType;
10
import net.minecraft.resources.ResourceKey;
11
import net.minecraft.world.level.gamerules.GameRule;
12
13
public record ServerboundSetGameRulePacket(List<ServerboundSetGameRulePacket.Entry> entries) implements Packet<ServerGamePacketListener> {
14
	public static final StreamCodec<ByteBuf, ServerboundSetGameRulePacket> STREAM_CODEC = StreamCodec.composite(
15
		ServerboundSetGameRulePacket.Entry.STREAM_CODEC.apply(ByteBufCodecs.list()), ServerboundSetGameRulePacket::entries, ServerboundSetGameRulePacket::new
16
	);
17
18
	@Override
19
	public PacketType<ServerboundSetGameRulePacket> type() {
20
		return GamePacketTypes.SERVERBOUND_SET_GAME_RULE;
21
	}
22
23
	public void handle(final ServerGamePacketListener listener) {
24
		listener.handleSetGameRule(this);
25
	}
26
27
	public record Entry(ResourceKey<GameRule<?>> gameRuleKey, String value) {
28
		public static final StreamCodec<ByteBuf, ServerboundSetGameRulePacket.Entry> STREAM_CODEC = StreamCodec.composite(
29
			ResourceKey.streamCodec(Registries.GAME_RULE),
30
			ServerboundSetGameRulePacket.Entry::gameRuleKey,
31
			ByteBufCodecs.STRING_UTF8,
32
			ServerboundSetGameRulePacket.Entry::value,
33
			ServerboundSetGameRulePacket.Entry::new
34
		);
35
	}
36
}
37