ServerboundSetCreativeModeSlotPacket 0x39

ServerboundSetCreativeModeSlotPacket: Minecraft 26.3 packet (0x39 Play serverbound). Wire name 'set_creative_mode_slot', fields: slotNum, itemStack

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3957PLAYServerboundGamePacketTypes.SERVERBOUND_SET_CREATIVE_MODE_SLOT: "set_creative_mode_slot"

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
slotNumshort
itemStackItemStack

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ServerboundSetCreativeModeSlotPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.SHORT, ServerboundSetCreativeModeSlotPacket::slotNum, ItemSt

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleSetCreativeModeSlot(ServerboundSetCreativeModeSlotPacket serverboundsetcreativemodeslotpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundSetCreativeModeSlotPacket.java32 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.network.RegistryFriendlyByteBuf;
4
import net.minecraft.network.codec.ByteBufCodecs;
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.item.ItemStack;
9
10
public record ServerboundSetCreativeModeSlotPacket(short slotNum, ItemStack itemStack) implements Packet<ServerGamePacketListener> {
11
	public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundSetCreativeModeSlotPacket> STREAM_CODEC = StreamCodec.composite(
12
		ByteBufCodecs.SHORT,
13
		ServerboundSetCreativeModeSlotPacket::slotNum,
14
		ItemStack.validatedStreamCodec(ItemStack.OPTIONAL_UNTRUSTED_STREAM_CODEC),
15
		ServerboundSetCreativeModeSlotPacket::itemStack,
16
		ServerboundSetCreativeModeSlotPacket::new
17
	);
18
19
	public ServerboundSetCreativeModeSlotPacket(final int slotNum, final ItemStack itemStack) {
20
		this((short)slotNum, itemStack);
21
	}
22
23
	@Override
24
	public PacketType<ServerboundSetCreativeModeSlotPacket> type() {
25
		return GamePacketTypes.SERVERBOUND_SET_CREATIVE_MODE_SLOT;
26
	}
27
28
	public void handle(final ServerGamePacketListener listener) {
29
		listener.handleSetCreativeModeSlot(this);
30
	}
31
}
32