ServerboundEditBookPacket 0x18

ServerboundEditBookPacket: Minecraft 26.3 packet (0x18 Play serverbound). Wire name 'edit_book', fields: slot, pages, title, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x1824PLAYServerboundGamePacketTypes.SERVERBOUND_EDIT_BOOK: "edit_book"

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

FieldType
slotint
pagesList<String>
titleOptional<String>

Fields are the components of the packet record.

Stream codec

static final StreamCodec<FriendlyByteBuf, ServerboundEditBookPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.VAR_INT, ServerboundEditBookPacket::slot, ByteBufCodecs.stringUtf8(1024).apply(

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleEditBook(ServerboundEditBookPacket serverboundeditbookpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundEditBookPacket.java35 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.List;
4
import java.util.Optional;
5
import net.minecraft.network.FriendlyByteBuf;
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
11
public record ServerboundEditBookPacket(int slot, List<String> pages, Optional<String> title) implements Packet<ServerGamePacketListener> {
12
	public static final StreamCodec<FriendlyByteBuf, ServerboundEditBookPacket> STREAM_CODEC = StreamCodec.composite(
13
		ByteBufCodecs.VAR_INT,
14
		ServerboundEditBookPacket::slot,
15
		ByteBufCodecs.stringUtf8(1024).apply(ByteBufCodecs.list(100)),
16
		ServerboundEditBookPacket::pages,
17
		ByteBufCodecs.stringUtf8(32).apply(ByteBufCodecs::optional),
18
		ServerboundEditBookPacket::title,
19
		ServerboundEditBookPacket::new
20
	);
21
22
	public ServerboundEditBookPacket {
23
		pages = List.copyOf(pages);
24
	}
25
26
	@Override
27
	public PacketType<ServerboundEditBookPacket> type() {
28
		return GamePacketTypes.SERVERBOUND_EDIT_BOOK;
29
	}
30
31
	public void handle(final ServerGamePacketListener listener) {
32
		listener.handleEditBook(this);
33
	}
34
}
35