ClientboundSetPlayerTeamPacket.java

net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket

信息

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

    TODO

字段/常量

  • STREAM_CODEC

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

      TODO

  • METHOD_ADD

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L22
    • 说明:

      TODO

  • METHOD_REMOVE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L23
    • 说明:

      TODO

  • METHOD_CHANGE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L24
    • 说明:

      TODO

  • METHOD_JOIN

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L25
    • 说明:

      TODO

  • METHOD_LEAVE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L26
    • 说明:

      TODO

  • MAX_VISIBILITY_LENGTH

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

  • MAX_COLLISION_LENGTH

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L28
    • 说明:

      TODO

  • method

    • 类型: int
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

  • name

    • 类型: String
    • 修饰符: private final
    • 源码定位: L30
    • 说明:

      TODO

  • players

    • 类型: Collection<String>
    • 修饰符: private final
    • 源码定位: L31
    • 说明:

      TODO

  • parameters

    • 类型: Optional<ClientboundSetPlayerTeamPacket.Parameters>
    • 修饰符: private final
    • 源码定位: L32
    • 说明:

      TODO

内部类/嵌套类型

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

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

      TODO

  • net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket.Parameters

    • 类型: class
    • 修饰符: public static
    • 源码定位: L138
    • 说明:

      TODO

构造器

private ClientboundSetPlayerTeamPacket(String name, int method, Optional<ClientboundSetPlayerTeamPacket.Parameters> parameters, Collection<String> players) @ L34

  • 构造器名:ClientboundSetPlayerTeamPacket
  • 源码定位:L34
  • 修饰符:private

参数:

  • name: String
  • method: int
  • parameters: Optional<ClientboundSetPlayerTeamPacket.Parameters>
  • players: Collection

说明:

TODO

private ClientboundSetPlayerTeamPacket(RegistryFriendlyByteBuf input) @ L60

  • 构造器名:ClientboundSetPlayerTeamPacket
  • 源码定位:L60
  • 修饰符:private

参数:

  • input: RegistryFriendlyByteBuf

说明:

TODO

方法

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

public static ClientboundSetPlayerTeamPacket createAddOrModifyPacket(PlayerTeam team, boolean createNew) @ L41

  • 方法名:createAddOrModifyPacket
  • 源码定位:L41
  • 返回类型:ClientboundSetPlayerTeamPacket
  • 修饰符:public static

参数:

  • team: PlayerTeam
  • createNew: boolean

说明:

TODO

public static ClientboundSetPlayerTeamPacket createRemovePacket(PlayerTeam team) @ L50

  • 方法名:createRemovePacket
  • 源码定位:L50
  • 返回类型:ClientboundSetPlayerTeamPacket
  • 修饰符:public static

参数:

  • team: PlayerTeam

说明:

TODO

public static ClientboundSetPlayerTeamPacket createPlayerPacket(PlayerTeam team, String player, ClientboundSetPlayerTeamPacket.Action action) @ L54

  • 方法名:createPlayerPacket
  • 源码定位:L54
  • 返回类型:ClientboundSetPlayerTeamPacket
  • 修饰符:public static

参数:

  • team: PlayerTeam
  • player: String
  • action: ClientboundSetPlayerTeamPacket.Action

说明:

TODO

private void write(RegistryFriendlyByteBuf output) @ L76

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

参数:

  • output: RegistryFriendlyByteBuf

说明:

TODO

private static boolean shouldHavePlayerList(int method) @ L88

  • 方法名:shouldHavePlayerList
  • 源码定位:L88
  • 返回类型:boolean
  • 修饰符:private static

参数:

  • method: int

说明:

TODO

private static boolean shouldHaveParameters(int method) @ L92

  • 方法名:shouldHaveParameters
  • 源码定位:L92
  • 返回类型:boolean
  • 修饰符:private static

参数:

  • method: int

说明:

TODO

public ClientboundSetPlayerTeamPacket.Action getPlayerAction() @ L96

  • 方法名:getPlayerAction
  • 源码定位:L96
  • 返回类型:ClientboundSetPlayerTeamPacket.Action
  • 修饰符:public

参数:

说明:

TODO

public ClientboundSetPlayerTeamPacket.Action getTeamAction() @ L104

  • 方法名:getTeamAction
  • 源码定位:L104
  • 返回类型:ClientboundSetPlayerTeamPacket.Action
  • 修饰符:public

参数:

说明:

TODO

public PacketType<ClientboundSetPlayerTeamPacket> type() @ L112

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

参数:

说明:

TODO

public void handle(ClientGamePacketListener listener) @ L117

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

参数:

  • listener: ClientGamePacketListener

说明:

TODO

public String getName() @ L121

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

参数:

说明:

TODO

public Collection<String> getPlayers() @ L125

  • 方法名:getPlayers
  • 源码定位:L125
  • 返回类型:Collection
  • 修饰符:public

参数:

说明:

TODO

public Optional<ClientboundSetPlayerTeamPacket.Parameters> getParameters() @ L129

  • 方法名:getParameters
  • 源码定位:L129
  • 返回类型:Optional<ClientboundSetPlayerTeamPacket.Parameters>
  • 修饰符:public

参数:

说明:

TODO

代码

public class ClientboundSetPlayerTeamPacket implements Packet<ClientGamePacketListener> {
    public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSetPlayerTeamPacket> STREAM_CODEC = Packet.codec(
        ClientboundSetPlayerTeamPacket::write, ClientboundSetPlayerTeamPacket::new
    );
    private static final int METHOD_ADD = 0;
    private static final int METHOD_REMOVE = 1;
    private static final int METHOD_CHANGE = 2;
    private static final int METHOD_JOIN = 3;
    private static final int METHOD_LEAVE = 4;
    private static final int MAX_VISIBILITY_LENGTH = 40;
    private static final int MAX_COLLISION_LENGTH = 40;
    private final int method;
    private final String name;
    private final Collection<String> players;
    private final Optional<ClientboundSetPlayerTeamPacket.Parameters> parameters;
 
    private ClientboundSetPlayerTeamPacket(String name, int method, Optional<ClientboundSetPlayerTeamPacket.Parameters> parameters, Collection<String> players) {
        this.name = name;
        this.method = method;
        this.parameters = parameters;
        this.players = ImmutableList.copyOf(players);
    }
 
    public static ClientboundSetPlayerTeamPacket createAddOrModifyPacket(PlayerTeam team, boolean createNew) {
        return new ClientboundSetPlayerTeamPacket(
            team.getName(),
            createNew ? 0 : 2,
            Optional.of(new ClientboundSetPlayerTeamPacket.Parameters(team)),
            (Collection<String>)(createNew ? team.getPlayers() : ImmutableList.of())
        );
    }
 
    public static ClientboundSetPlayerTeamPacket createRemovePacket(PlayerTeam team) {
        return new ClientboundSetPlayerTeamPacket(team.getName(), 1, Optional.empty(), ImmutableList.of());
    }
 
    public static ClientboundSetPlayerTeamPacket createPlayerPacket(PlayerTeam team, String player, ClientboundSetPlayerTeamPacket.Action action) {
        return new ClientboundSetPlayerTeamPacket(
            team.getName(), action == ClientboundSetPlayerTeamPacket.Action.ADD ? 3 : 4, Optional.empty(), ImmutableList.of(player)
        );
    }
 
    private ClientboundSetPlayerTeamPacket(RegistryFriendlyByteBuf input) {
        this.name = input.readUtf();
        this.method = input.readByte();
        if (shouldHaveParameters(this.method)) {
            this.parameters = Optional.of(new ClientboundSetPlayerTeamPacket.Parameters(input));
        } else {
            this.parameters = Optional.empty();
        }
 
        if (shouldHavePlayerList(this.method)) {
            this.players = input.readList(FriendlyByteBuf::readUtf);
        } else {
            this.players = ImmutableList.of();
        }
    }
 
    private void write(RegistryFriendlyByteBuf output) {
        output.writeUtf(this.name);
        output.writeByte(this.method);
        if (shouldHaveParameters(this.method)) {
            this.parameters.orElseThrow(() -> new IllegalStateException("Parameters not present, but method is" + this.method)).write(output);
        }
 
        if (shouldHavePlayerList(this.method)) {
            output.writeCollection(this.players, FriendlyByteBuf::writeUtf);
        }
    }
 
    private static boolean shouldHavePlayerList(int method) {
        return method == 0 || method == 3 || method == 4;
    }
 
    private static boolean shouldHaveParameters(int method) {
        return method == 0 || method == 2;
    }
 
    public ClientboundSetPlayerTeamPacket.@Nullable Action getPlayerAction() {
        return switch (this.method) {
            case 0, 3 -> ClientboundSetPlayerTeamPacket.Action.ADD;
            default -> null;
            case 4 -> ClientboundSetPlayerTeamPacket.Action.REMOVE;
        };
    }
 
    public ClientboundSetPlayerTeamPacket.@Nullable Action getTeamAction() {
        return switch (this.method) {
            case 0 -> ClientboundSetPlayerTeamPacket.Action.ADD;
            case 1 -> ClientboundSetPlayerTeamPacket.Action.REMOVE;
            default -> null;
        };
    }
 
    @Override
    public PacketType<ClientboundSetPlayerTeamPacket> type() {
        return GamePacketTypes.CLIENTBOUND_SET_PLAYER_TEAM;
    }
 
    public void handle(ClientGamePacketListener listener) {
        listener.handleSetPlayerTeamPacket(this);
    }
 
    public String getName() {
        return this.name;
    }
 
    public Collection<String> getPlayers() {
        return this.players;
    }
 
    public Optional<ClientboundSetPlayerTeamPacket.Parameters> getParameters() {
        return this.parameters;
    }
 
    public static enum Action {
        ADD,
        REMOVE;
    }
 
    public static class Parameters {
        private final Component displayName;
        private final Component playerPrefix;
        private final Component playerSuffix;
        private final Team.Visibility nametagVisibility;
        private final Team.CollisionRule collisionRule;
        private final ChatFormatting color;
        private final int options;
 
        public Parameters(PlayerTeam team) {
            this.displayName = team.getDisplayName();
            this.options = team.packOptions();
            this.nametagVisibility = team.getNameTagVisibility();
            this.collisionRule = team.getCollisionRule();
            this.color = team.getColor();
            this.playerPrefix = team.getPlayerPrefix();
            this.playerSuffix = team.getPlayerSuffix();
        }
 
        public Parameters(RegistryFriendlyByteBuf input) {
            this.displayName = ComponentSerialization.TRUSTED_STREAM_CODEC.decode(input);
            this.options = input.readByte();
            this.nametagVisibility = Team.Visibility.STREAM_CODEC.decode(input);
            this.collisionRule = Team.CollisionRule.STREAM_CODEC.decode(input);
            this.color = input.readEnum(ChatFormatting.class);
            this.playerPrefix = ComponentSerialization.TRUSTED_STREAM_CODEC.decode(input);
            this.playerSuffix = ComponentSerialization.TRUSTED_STREAM_CODEC.decode(input);
        }
 
        public Component getDisplayName() {
            return this.displayName;
        }
 
        public int getOptions() {
            return this.options;
        }
 
        public ChatFormatting getColor() {
            return this.color;
        }
 
        public Team.Visibility getNametagVisibility() {
            return this.nametagVisibility;
        }
 
        public Team.CollisionRule getCollisionRule() {
            return this.collisionRule;
        }
 
        public Component getPlayerPrefix() {
            return this.playerPrefix;
        }
 
        public Component getPlayerSuffix() {
            return this.playerSuffix;
        }
 
        public void write(RegistryFriendlyByteBuf output) {
            ComponentSerialization.TRUSTED_STREAM_CODEC.encode(output, this.displayName);
            output.writeByte(this.options);
            Team.Visibility.STREAM_CODEC.encode(output, this.nametagVisibility);
            Team.CollisionRule.STREAM_CODEC.encode(output, this.collisionRule);
            output.writeEnum(this.color);
            ComponentSerialization.TRUSTED_STREAM_CODEC.encode(output, this.playerPrefix);
            ComponentSerialization.TRUSTED_STREAM_CODEC.encode(output, this.playerSuffix);
        }
    }
}

引用的其他类