minecraft-src/net/minecraft/network/protocol/game/ServerboundEditBookPacket.java
2025-07-04 02:00:41 +03:00

40 lines
1.3 KiB
Java

package net.minecraft.network.protocol.game;
import java.util.List;
import java.util.Optional;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketType;
public record ServerboundEditBookPacket(int slot, List<String> pages, Optional<String> title) implements Packet<ServerGamePacketListener> {
public static final StreamCodec<FriendlyByteBuf, ServerboundEditBookPacket> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.VAR_INT,
ServerboundEditBookPacket::slot,
ByteBufCodecs.stringUtf8(1024).apply(ByteBufCodecs.list(100)),
ServerboundEditBookPacket::pages,
ByteBufCodecs.stringUtf8(32).apply(ByteBufCodecs::optional),
ServerboundEditBookPacket::title,
ServerboundEditBookPacket::new
);
public ServerboundEditBookPacket(int slot, List<String> pages, Optional<String> title) {
pages = List.copyOf(pages);
this.slot = slot;
this.pages = pages;
this.title = title;
}
@Override
public PacketType<ServerboundEditBookPacket> type() {
return GamePacketTypes.SERVERBOUND_EDIT_BOOK;
}
/**
* Passes this Packet on to the NetHandler for processing.
*/
public void handle(ServerGamePacketListener handler) {
handler.handleEditBook(this);
}
}