EnvironmentAttribute.java

net.minecraft.world.attribute.EnvironmentAttribute

信息

  • 全限定名:net.minecraft.world.attribute.EnvironmentAttribute
  • 类型:public class
  • 包:net.minecraft.world.attribute
  • 源码路径:src/main/java/net/minecraft/world/attribute/EnvironmentAttribute.java
  • 起始行号:L9
  • 职责:

    TODO

字段/常量

  • type

    • 类型: AttributeType<Value>
    • 修饰符: private final
    • 源码定位: L10
    • 说明:

      TODO

  • defaultValue

    • 类型: Value
    • 修饰符: private final
    • 源码定位: L11
    • 说明:

      TODO

  • valueRange

    • 类型: AttributeRange<Value>
    • 修饰符: private final
    • 源码定位: L12
    • 说明:

      TODO

  • isSyncable

    • 类型: boolean
    • 修饰符: private final
    • 源码定位: L13
    • 说明:

      TODO

  • isPositional

    • 类型: boolean
    • 修饰符: private final
    • 源码定位: L14
    • 说明:

      TODO

  • isSpatiallyInterpolated

    • 类型: boolean
    • 修饰符: private final
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.world.attribute.EnvironmentAttribute.Builder
    • 类型: class
    • 修饰符: public static
    • 源码定位: L70
    • 说明:

      TODO

构造器

private EnvironmentAttribute(AttributeType<Value> type, Value defaultValue, AttributeRange<Value> valueRange, boolean isSyncable, boolean isPositional, boolean isSpatiallyInterpolated) @ L17

  • 构造器名:EnvironmentAttribute
  • 源码定位:L17
  • 修饰符:private

参数:

  • type: AttributeType
  • defaultValue: Value
  • valueRange: AttributeRange
  • isSyncable: boolean
  • isPositional: boolean
  • isSpatiallyInterpolated: boolean

说明:

TODO

方法

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

public static <Value> EnvironmentAttribute.Builder<Value> builder(AttributeType<Value> type) @ L33

  • 方法名:builder
  • 源码定位:L33
  • 返回类型: EnvironmentAttribute.Builder
  • 修饰符:public static

参数:

  • type: AttributeType

说明:

TODO

public AttributeType<Value> type() @ L37

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

参数:

说明:

TODO

public Value defaultValue() @ L41

  • 方法名:defaultValue
  • 源码定位:L41
  • 返回类型:Value
  • 修饰符:public

参数:

说明:

TODO

public Codec<Value> valueCodec() @ L45

  • 方法名:valueCodec
  • 源码定位:L45
  • 返回类型:Codec
  • 修饰符:public

参数:

说明:

TODO

public Value sanitizeValue(Value value) @ L49

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

参数:

  • value: Value

说明:

TODO

public boolean isSyncable() @ L53

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

参数:

说明:

TODO

public boolean isPositional() @ L57

  • 方法名:isPositional
  • 源码定位:L57
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean isSpatiallyInterpolated() @ L61

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

参数:

说明:

TODO

public String toString() @ L65

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

参数:

说明:

TODO

代码

public class EnvironmentAttribute<Value> {
    private final AttributeType<Value> type;
    private final Value defaultValue;
    private final AttributeRange<Value> valueRange;
    private final boolean isSyncable;
    private final boolean isPositional;
    private final boolean isSpatiallyInterpolated;
 
    private EnvironmentAttribute(
        AttributeType<Value> type,
        Value defaultValue,
        AttributeRange<Value> valueRange,
        boolean isSyncable,
        boolean isPositional,
        boolean isSpatiallyInterpolated
    ) {
        this.type = type;
        this.defaultValue = defaultValue;
        this.valueRange = valueRange;
        this.isSyncable = isSyncable;
        this.isPositional = isPositional;
        this.isSpatiallyInterpolated = isSpatiallyInterpolated;
    }
 
    public static <Value> EnvironmentAttribute.Builder<Value> builder(AttributeType<Value> type) {
        return new EnvironmentAttribute.Builder<>(type);
    }
 
    public AttributeType<Value> type() {
        return this.type;
    }
 
    public Value defaultValue() {
        return this.defaultValue;
    }
 
    public Codec<Value> valueCodec() {
        return this.type.valueCodec().validate(this.valueRange::validate);
    }
 
    public Value sanitizeValue(Value value) {
        return this.valueRange.sanitize(value);
    }
 
    public boolean isSyncable() {
        return this.isSyncable;
    }
 
    public boolean isPositional() {
        return this.isPositional;
    }
 
    public boolean isSpatiallyInterpolated() {
        return this.isSpatiallyInterpolated;
    }
 
    @Override
    public String toString() {
        return Util.getRegisteredName(BuiltInRegistries.ENVIRONMENT_ATTRIBUTE, this);
    }
 
    public static class Builder<Value> {
        private final AttributeType<Value> type;
        private @Nullable Value defaultValue;
        private AttributeRange<Value> valueRange = AttributeRange.any();
        private boolean isSyncable = false;
        private boolean isPositional = true;
        private boolean isSpatiallyInterpolated = false;
 
        public Builder(AttributeType<Value> type) {
            this.type = type;
        }
 
        public EnvironmentAttribute.Builder<Value> defaultValue(Value defaultValue) {
            this.defaultValue = defaultValue;
            return this;
        }
 
        public EnvironmentAttribute.Builder<Value> valueRange(AttributeRange<Value> valueRange) {
            this.valueRange = valueRange;
            return this;
        }
 
        public EnvironmentAttribute.Builder<Value> syncable() {
            this.isSyncable = true;
            return this;
        }
 
        public EnvironmentAttribute.Builder<Value> notPositional() {
            this.isPositional = false;
            return this;
        }
 
        public EnvironmentAttribute.Builder<Value> spatiallyInterpolated() {
            this.isSpatiallyInterpolated = true;
            return this;
        }
 
        public EnvironmentAttribute<Value> build() {
            return new EnvironmentAttribute<>(
                this.type,
                Objects.requireNonNull(this.defaultValue, "Missing default value"),
                this.valueRange,
                this.isSyncable,
                this.isPositional,
                this.isSpatiallyInterpolated
            );
        }
    }
}

引用的其他类

  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.getRegisteredName()
  • AttributeRange

    • 引用位置: 参数/字段/方法调用
    • 关联成员: AttributeRange.any()
  • AttributeType

    • 引用位置: 参数/字段/返回值