ClientboundSetObjectivePacket.java

net.minecraft.network.protocol.game.ClientboundSetObjectivePacket

信息

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

    TODO

字段/常量

  • STREAM_CODEC

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

      TODO

  • METHOD_ADD

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

      TODO

  • METHOD_REMOVE

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

      TODO

  • METHOD_CHANGE

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

      TODO

  • objectiveName

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

      TODO

  • displayName

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

      TODO

  • renderType

    • 类型: ObjectiveCriteria.RenderType
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • numberFormat

    • 类型: Optional<NumberFormat>
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • method

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

      TODO

内部类/嵌套类型

构造器

public ClientboundSetObjectivePacket(Objective objective, int method) @ L29

  • 构造器名:ClientboundSetObjectivePacket
  • 源码定位:L29
  • 修饰符:public

参数:

  • objective: Objective
  • method: int

说明:

TODO

private ClientboundSetObjectivePacket(RegistryFriendlyByteBuf input) @ L37

  • 构造器名:ClientboundSetObjectivePacket
  • 源码定位:L37
  • 修饰符:private

参数:

  • input: RegistryFriendlyByteBuf

说明:

TODO

方法

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

private void write(RegistryFriendlyByteBuf output) @ L51

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

参数:

  • output: RegistryFriendlyByteBuf

说明:

TODO

public PacketType<ClientboundSetObjectivePacket> type() @ L61

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

参数:

说明:

TODO

public void handle(ClientGamePacketListener listener) @ L66

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

参数:

  • listener: ClientGamePacketListener

说明:

TODO

public String getObjectiveName() @ L70

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

参数:

说明:

TODO

public Component getDisplayName() @ L74

  • 方法名:getDisplayName
  • 源码定位:L74
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

public int getMethod() @ L78

  • 方法名:getMethod
  • 源码定位:L78
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public ObjectiveCriteria.RenderType getRenderType() @ L82

  • 方法名:getRenderType
  • 源码定位:L82
  • 返回类型:ObjectiveCriteria.RenderType
  • 修饰符:public

参数:

说明:

TODO

public Optional<NumberFormat> getNumberFormat() @ L86

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

参数:

说明:

TODO

代码

public class ClientboundSetObjectivePacket implements Packet<ClientGamePacketListener> {
    public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSetObjectivePacket> STREAM_CODEC = Packet.codec(
        ClientboundSetObjectivePacket::write, ClientboundSetObjectivePacket::new
    );
    public static final int METHOD_ADD = 0;
    public static final int METHOD_REMOVE = 1;
    public static final int METHOD_CHANGE = 2;
    private final String objectiveName;
    private final Component displayName;
    private final ObjectiveCriteria.RenderType renderType;
    private final Optional<NumberFormat> numberFormat;
    private final int method;
 
    public ClientboundSetObjectivePacket(Objective objective, int method) {
        this.objectiveName = objective.getName();
        this.displayName = objective.getDisplayName();
        this.renderType = objective.getRenderType();
        this.numberFormat = Optional.ofNullable(objective.numberFormat());
        this.method = method;
    }
 
    private ClientboundSetObjectivePacket(RegistryFriendlyByteBuf input) {
        this.objectiveName = input.readUtf();
        this.method = input.readByte();
        if (this.method != 0 && this.method != 2) {
            this.displayName = CommonComponents.EMPTY;
            this.renderType = ObjectiveCriteria.RenderType.INTEGER;
            this.numberFormat = Optional.empty();
        } else {
            this.displayName = ComponentSerialization.TRUSTED_STREAM_CODEC.decode(input);
            this.renderType = input.readEnum(ObjectiveCriteria.RenderType.class);
            this.numberFormat = NumberFormatTypes.OPTIONAL_STREAM_CODEC.decode(input);
        }
    }
 
    private void write(RegistryFriendlyByteBuf output) {
        output.writeUtf(this.objectiveName);
        output.writeByte(this.method);
        if (this.method == 0 || this.method == 2) {
            ComponentSerialization.TRUSTED_STREAM_CODEC.encode(output, this.displayName);
            output.writeEnum(this.renderType);
            NumberFormatTypes.OPTIONAL_STREAM_CODEC.encode(output, this.numberFormat);
        }
    }
 
    @Override
    public PacketType<ClientboundSetObjectivePacket> type() {
        return GamePacketTypes.CLIENTBOUND_SET_OBJECTIVE;
    }
 
    public void handle(ClientGamePacketListener listener) {
        listener.handleAddObjective(this);
    }
 
    public String getObjectiveName() {
        return this.objectiveName;
    }
 
    public Component getDisplayName() {
        return this.displayName;
    }
 
    public int getMethod() {
        return this.method;
    }
 
    public ObjectiveCriteria.RenderType getRenderType() {
        return this.renderType;
    }
 
    public Optional<NumberFormat> getNumberFormat() {
        return this.numberFormat;
    }
}

引用的其他类