114 lines
3.5 KiB
Java
114 lines
3.5 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.mojang.serialization.Codec
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.world.attribute;
|
|
|
|
import com.mojang.serialization.Codec;
|
|
import java.util.Objects;
|
|
import net.minecraft.core.registries.BuiltInRegistries;
|
|
import net.minecraft.util.Util;
|
|
import net.minecraft.world.attribute.AttributeRange;
|
|
import net.minecraft.world.attribute.AttributeType;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
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> Builder<Value> builder(AttributeType<Value> type) {
|
|
return new Builder<Value>(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;
|
|
}
|
|
|
|
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 Builder<Value> defaultValue(Value defaultValue) {
|
|
this.defaultValue = defaultValue;
|
|
return this;
|
|
}
|
|
|
|
public Builder<Value> valueRange(AttributeRange<Value> valueRange) {
|
|
this.valueRange = valueRange;
|
|
return this;
|
|
}
|
|
|
|
public Builder<Value> syncable() {
|
|
this.isSyncable = true;
|
|
return this;
|
|
}
|
|
|
|
public Builder<Value> notPositional() {
|
|
this.isPositional = false;
|
|
return this;
|
|
}
|
|
|
|
public Builder<Value> spatiallyInterpolated() {
|
|
this.isSpatiallyInterpolated = true;
|
|
return this;
|
|
}
|
|
|
|
public EnvironmentAttribute<Value> build() {
|
|
return new EnvironmentAttribute<Value>(this.type, Objects.requireNonNull(this.defaultValue, "Missing default value"), this.valueRange, this.isSyncable, this.isPositional, this.isSpatiallyInterpolated);
|
|
}
|
|
}
|
|
}
|
|
|