ClientboundUpdateAttributesPacket.java

net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket

信息

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

    TODO

字段/常量

  • STREAM_CODEC

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

      TODO

  • entityId

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

      TODO

  • attributes

    • 类型: List<ClientboundUpdateAttributesPacket.AttributeSnapshot>
    • 修饰符: private final
    • 源码定位: L28
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket.AttributeSnapshot
    • 类型: record
    • 修饰符: public
    • 源码定位: L61
    • 说明:

      TODO

构造器

public ClientboundUpdateAttributesPacket(int entityId, Collection<AttributeInstance> values) @ L30

  • 构造器名:ClientboundUpdateAttributesPacket
  • 源码定位:L30
  • 修饰符:public

参数:

  • entityId: int
  • values: Collection

说明:

TODO

private ClientboundUpdateAttributesPacket(int entityId, List<ClientboundUpdateAttributesPacket.AttributeSnapshot> attributes) @ L39

  • 构造器名:ClientboundUpdateAttributesPacket
  • 源码定位:L39
  • 修饰符:private

参数:

  • entityId: int
  • attributes: List<ClientboundUpdateAttributesPacket.AttributeSnapshot>

说明:

TODO

方法

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

public PacketType<ClientboundUpdateAttributesPacket> type() @ L44

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

参数:

说明:

TODO

public void handle(ClientGamePacketListener listener) @ L49

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

参数:

  • listener: ClientGamePacketListener

说明:

TODO

public int getEntityId() @ L53

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

参数:

说明:

TODO

public List<ClientboundUpdateAttributesPacket.AttributeSnapshot> getValues() @ L57

  • 方法名:getValues
  • 源码定位:L57
  • 返回类型:List<ClientboundUpdateAttributesPacket.AttributeSnapshot>
  • 修饰符:public

参数:

说明:

TODO

代码

public class ClientboundUpdateAttributesPacket implements Packet<ClientGamePacketListener> {
    public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundUpdateAttributesPacket> STREAM_CODEC = StreamCodec.composite(
        ByteBufCodecs.VAR_INT,
        ClientboundUpdateAttributesPacket::getEntityId,
        ClientboundUpdateAttributesPacket.AttributeSnapshot.STREAM_CODEC.apply(ByteBufCodecs.list()),
        ClientboundUpdateAttributesPacket::getValues,
        ClientboundUpdateAttributesPacket::new
    );
    private final int entityId;
    private final List<ClientboundUpdateAttributesPacket.AttributeSnapshot> attributes;
 
    public ClientboundUpdateAttributesPacket(int entityId, Collection<AttributeInstance> values) {
        this.entityId = entityId;
        this.attributes = Lists.newArrayList();
 
        for (AttributeInstance value : values) {
            this.attributes.add(new ClientboundUpdateAttributesPacket.AttributeSnapshot(value.getAttribute(), value.getBaseValue(), value.getModifiers()));
        }
    }
 
    private ClientboundUpdateAttributesPacket(int entityId, List<ClientboundUpdateAttributesPacket.AttributeSnapshot> attributes) {
        this.entityId = entityId;
        this.attributes = attributes;
    }
 
    @Override
    public PacketType<ClientboundUpdateAttributesPacket> type() {
        return GamePacketTypes.CLIENTBOUND_UPDATE_ATTRIBUTES;
    }
 
    public void handle(ClientGamePacketListener listener) {
        listener.handleUpdateAttributes(this);
    }
 
    public int getEntityId() {
        return this.entityId;
    }
 
    public List<ClientboundUpdateAttributesPacket.AttributeSnapshot> getValues() {
        return this.attributes;
    }
 
    public record AttributeSnapshot(Holder<Attribute> attribute, double base, Collection<AttributeModifier> modifiers) {
        public static final StreamCodec<ByteBuf, AttributeModifier> MODIFIER_STREAM_CODEC = StreamCodec.composite(
            Identifier.STREAM_CODEC,
            AttributeModifier::id,
            ByteBufCodecs.DOUBLE,
            AttributeModifier::amount,
            AttributeModifier.Operation.STREAM_CODEC,
            AttributeModifier::operation,
            AttributeModifier::new
        );
        public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundUpdateAttributesPacket.AttributeSnapshot> STREAM_CODEC = StreamCodec.composite(
            Attribute.STREAM_CODEC,
            ClientboundUpdateAttributesPacket.AttributeSnapshot::attribute,
            ByteBufCodecs.DOUBLE,
            ClientboundUpdateAttributesPacket.AttributeSnapshot::base,
            MODIFIER_STREAM_CODEC.apply(ByteBufCodecs.collection(ArrayList::new)),
            ClientboundUpdateAttributesPacket.AttributeSnapshot::modifiers,
            ClientboundUpdateAttributesPacket.AttributeSnapshot::new
        );
    }
}

引用的其他类