ClientboundPlayerInfoUpdatePacket.java

net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket

信息

  • 全限定名:net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket
  • 类型:public class
  • 包:net.minecraft.network.protocol.game
  • 源码路径:src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
  • 起始行号:L26
  • 实现:Packet
  • 职责:

    TODO

字段/常量

  • STREAM_CODEC

    • 类型: StreamCodec<RegistryFriendlyByteBuf,ClientboundPlayerInfoUpdatePacket>
    • 修饰符: public static final
    • 源码定位: L27
    • 说明:

      TODO

  • actions

    • 类型: EnumSet<ClientboundPlayerInfoUpdatePacket.Action>
    • 修饰符: private final
    • 源码定位: L30
    • 说明:

      TODO

  • entries

    • 类型: List<ClientboundPlayerInfoUpdatePacket.Entry>
    • 修饰符: private final
    • 源码定位: L31
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket.Action

    • 类型: enum
    • 修饰符: public static
    • 源码定位: L107
    • 说明:

      TODO

  • net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket.Action.Reader

    • 类型: interface
    • 修饰符: public
    • 源码定位: L139
    • 说明:

      TODO

  • net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket.Action.Writer

    • 类型: interface
    • 修饰符: public
    • 源码定位: L143
    • 说明:

      TODO

  • net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket.Entry

    • 类型: record
    • 修饰符: public
    • 源码定位: L148
    • 说明:

      TODO

  • net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket.EntryBuilder

    • 类型: class
    • 修饰符: private static
    • 源码定位: L174
    • 说明:

      TODO

构造器

public ClientboundPlayerInfoUpdatePacket(EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions, Collection<ServerPlayer> players) @ L33

  • 构造器名:ClientboundPlayerInfoUpdatePacket
  • 源码定位:L33
  • 修饰符:public

参数:

  • actions: EnumSet<ClientboundPlayerInfoUpdatePacket.Action>
  • players: Collection

说明:

TODO

public ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action action, ServerPlayer player) @ L38

  • 构造器名:ClientboundPlayerInfoUpdatePacket
  • 源码定位:L38
  • 修饰符:public

参数:

  • action: ClientboundPlayerInfoUpdatePacket.Action
  • player: ServerPlayer

说明:

TODO

private ClientboundPlayerInfoUpdatePacket(RegistryFriendlyByteBuf input) @ L57

  • 构造器名:ClientboundPlayerInfoUpdatePacket
  • 源码定位:L57
  • 修饰符:private

参数:

  • input: RegistryFriendlyByteBuf

说明:

TODO

方法

下面的方法块按源码顺序生成。

public static ClientboundPlayerInfoUpdatePacket createPlayerInitializing(Collection<ServerPlayer> players) @ L43

  • 方法名:createPlayerInitializing
  • 源码定位:L43
  • 返回类型:ClientboundPlayerInfoUpdatePacket
  • 修饰符:public static

参数:

  • players: Collection

说明:

TODO

private void write(RegistryFriendlyByteBuf output) @ L70

  • 方法名:write
  • 源码定位:L70
  • 返回类型:void
  • 修饰符:private

参数:

  • output: RegistryFriendlyByteBuf

说明:

TODO

public PacketType<ClientboundPlayerInfoUpdatePacket> type() @ L81

  • 方法名:type
  • 源码定位:L81
  • 返回类型:PacketType
  • 修饰符:public

参数:

说明:

TODO

public void handle(ClientGamePacketListener listener) @ L86

  • 方法名:handle
  • 源码定位:L86
  • 返回类型:void
  • 修饰符:public

参数:

  • listener: ClientGamePacketListener

说明:

TODO

public EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions() @ L90

  • 方法名:actions
  • 源码定位:L90
  • 返回类型:EnumSet<ClientboundPlayerInfoUpdatePacket.Action>
  • 修饰符:public

参数:

说明:

TODO

public List<ClientboundPlayerInfoUpdatePacket.Entry> entries() @ L94

  • 方法名:entries
  • 源码定位:L94
  • 返回类型:List<ClientboundPlayerInfoUpdatePacket.Entry>
  • 修饰符:public

参数:

说明:

TODO

public List<ClientboundPlayerInfoUpdatePacket.Entry> newEntries() @ L98

  • 方法名:newEntries
  • 源码定位:L98
  • 返回类型:List<ClientboundPlayerInfoUpdatePacket.Entry>
  • 修饰符:public

参数:

说明:

TODO

public String toString() @ L102

  • 方法名:toString
  • 源码定位:L102
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

代码

public class ClientboundPlayerInfoUpdatePacket implements Packet<ClientGamePacketListener> {
    public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundPlayerInfoUpdatePacket> STREAM_CODEC = Packet.codec(
        ClientboundPlayerInfoUpdatePacket::write, ClientboundPlayerInfoUpdatePacket::new
    );
    private final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions;
    private final List<ClientboundPlayerInfoUpdatePacket.Entry> entries;
 
    public ClientboundPlayerInfoUpdatePacket(EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions, Collection<ServerPlayer> players) {
        this.actions = actions;
        this.entries = players.stream().map(ClientboundPlayerInfoUpdatePacket.Entry::new).toList();
    }
 
    public ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action action, ServerPlayer player) {
        this.actions = EnumSet.of(action);
        this.entries = List.of(new ClientboundPlayerInfoUpdatePacket.Entry(player));
    }
 
    public static ClientboundPlayerInfoUpdatePacket createPlayerInitializing(Collection<ServerPlayer> players) {
        EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions = EnumSet.of(
            ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER,
            ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT,
            ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE,
            ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED,
            ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY,
            ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME,
            ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT,
            ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LIST_ORDER
        );
        return new ClientboundPlayerInfoUpdatePacket(actions, players);
    }
 
    private ClientboundPlayerInfoUpdatePacket(RegistryFriendlyByteBuf input) {
        this.actions = input.readEnumSet(ClientboundPlayerInfoUpdatePacket.Action.class);
        this.entries = input.readList(buf -> {
            ClientboundPlayerInfoUpdatePacket.EntryBuilder builder = new ClientboundPlayerInfoUpdatePacket.EntryBuilder(buf.readUUID());
 
            for (ClientboundPlayerInfoUpdatePacket.Action action : this.actions) {
                action.reader.read(builder, (RegistryFriendlyByteBuf)buf);
            }
 
            return builder.build();
        });
    }
 
    private void write(RegistryFriendlyByteBuf output) {
        output.writeEnumSet(this.actions, ClientboundPlayerInfoUpdatePacket.Action.class);
        output.writeCollection(this.entries, (buf, entry) -> {
            buf.writeUUID(entry.profileId());
 
            for (ClientboundPlayerInfoUpdatePacket.Action action : this.actions) {
                action.writer.write((RegistryFriendlyByteBuf)buf, entry);
            }
        });
    }
 
    @Override
    public PacketType<ClientboundPlayerInfoUpdatePacket> type() {
        return GamePacketTypes.CLIENTBOUND_PLAYER_INFO_UPDATE;
    }
 
    public void handle(ClientGamePacketListener listener) {
        listener.handlePlayerInfoUpdate(this);
    }
 
    public EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions() {
        return this.actions;
    }
 
    public List<ClientboundPlayerInfoUpdatePacket.Entry> entries() {
        return this.entries;
    }
 
    public List<ClientboundPlayerInfoUpdatePacket.Entry> newEntries() {
        return this.actions.contains(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER) ? this.entries : List.of();
    }
 
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).add("actions", this.actions).add("entries", this.entries).toString();
    }
 
    public static enum Action {
        ADD_PLAYER((entry, input) -> {
            String name = ByteBufCodecs.PLAYER_NAME.decode(input);
            PropertyMap properties = ByteBufCodecs.GAME_PROFILE_PROPERTIES.decode(input);
            entry.profile = new GameProfile(entry.profileId, name, properties);
        }, (output, entry) -> {
            GameProfile profile = Objects.requireNonNull(entry.profile());
            ByteBufCodecs.PLAYER_NAME.encode(output, profile.name());
            ByteBufCodecs.GAME_PROFILE_PROPERTIES.encode(output, profile.properties());
        }),
        INITIALIZE_CHAT(
            (entry, input) -> entry.chatSession = input.readNullable(RemoteChatSession.Data::read),
            (output, entry) -> output.writeNullable(entry.chatSession, RemoteChatSession.Data::write)
        ),
        UPDATE_GAME_MODE((entry, input) -> entry.gameMode = GameType.byId(input.readVarInt()), (output, entry) -> output.writeVarInt(entry.gameMode().getId())),
        UPDATE_LISTED((entry, input) -> entry.listed = input.readBoolean(), (output, entry) -> output.writeBoolean(entry.listed())),
        UPDATE_LATENCY((entry, input) -> entry.latency = input.readVarInt(), (output, entry) -> output.writeVarInt(entry.latency())),
        UPDATE_DISPLAY_NAME(
            (entry, input) -> entry.displayName = FriendlyByteBuf.readNullable(input, ComponentSerialization.TRUSTED_STREAM_CODEC),
            (output, entry) -> FriendlyByteBuf.writeNullable(output, entry.displayName(), ComponentSerialization.TRUSTED_STREAM_CODEC)
        ),
        UPDATE_LIST_ORDER((entry, input) -> entry.listOrder = input.readVarInt(), (output, entry) -> output.writeVarInt(entry.listOrder)),
        UPDATE_HAT((entry, input) -> entry.showHat = input.readBoolean(), (output, entry) -> output.writeBoolean(entry.showHat));
 
        private final ClientboundPlayerInfoUpdatePacket.Action.Reader reader;
        private final ClientboundPlayerInfoUpdatePacket.Action.Writer writer;
 
        private Action(ClientboundPlayerInfoUpdatePacket.Action.Reader reader, ClientboundPlayerInfoUpdatePacket.Action.Writer writer) {
            this.reader = reader;
            this.writer = writer;
        }
 
        public interface Reader {
            void read(ClientboundPlayerInfoUpdatePacket.EntryBuilder entry, RegistryFriendlyByteBuf input);
        }
 
        public interface Writer {
            void write(RegistryFriendlyByteBuf output, ClientboundPlayerInfoUpdatePacket.Entry entry);
        }
    }
 
    public record Entry(
        UUID profileId,
        @Nullable GameProfile profile,
        boolean listed,
        int latency,
        GameType gameMode,
        @Nullable Component displayName,
        boolean showHat,
        int listOrder,
        RemoteChatSession.@Nullable Data chatSession
    ) {
        private Entry(ServerPlayer player) {
            this(
                player.getUUID(),
                player.getGameProfile(),
                true,
                player.connection.latency(),
                player.gameMode(),
                player.getTabListDisplayName(),
                player.isModelPartShown(PlayerModelPart.HAT),
                player.getTabListOrder(),
                Optionull.map(player.getChatSession(), RemoteChatSession::asData)
            );
        }
    }
 
    private static class EntryBuilder {
        private final UUID profileId;
        private @Nullable GameProfile profile;
        private boolean listed;
        private int latency;
        private GameType gameMode = GameType.DEFAULT_MODE;
        private @Nullable Component displayName;
        private boolean showHat;
        private int listOrder;
        private RemoteChatSession.@Nullable Data chatSession;
 
        private EntryBuilder(UUID profileId) {
            this.profileId = profileId;
        }
 
        private ClientboundPlayerInfoUpdatePacket.Entry build() {
            return new ClientboundPlayerInfoUpdatePacket.Entry(
                this.profileId, this.profile, this.listed, this.latency, this.gameMode, this.displayName, this.showHat, this.listOrder, this.chatSession
            );
        }
    }
}

引用的其他类