EnvironmentAttributeProbe.java
net.minecraft.world.attribute.EnvironmentAttributeProbe
信息
- 全限定名:net.minecraft.world.attribute.EnvironmentAttributeProbe
- 类型:public class
- 包:net.minecraft.world.attribute
- 源码路径:src/main/java/net/minecraft/world/attribute/EnvironmentAttributeProbe.java
- 起始行号:L11
- 职责:
TODO
字段/常量
-
valueProbes- 类型:
Map<EnvironmentAttribute<?>,EnvironmentAttributeProbe.ValueProbe<?>> - 修饰符:
private final - 源码定位:
L12 - 说明:
TODO
- 类型:
-
valueProbeFactory- 类型:
Function<EnvironmentAttribute<?>,EnvironmentAttributeProbe.ValueProbe<?>> - 修饰符:
private final - 源码定位:
L13 - 说明:
TODO
- 类型:
-
level- 类型:
Level - 修饰符:
private - 源码定位:
L16 - 说明:
TODO
- 类型:
-
position- 类型:
Vec3 - 修饰符:
private - 源码定位:
L17 - 说明:
TODO
- 类型:
-
biomeInterpolator- 类型:
SpatialAttributeInterpolator - 修饰符:
private final - 源码定位:
L18 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.world.attribute.EnvironmentAttributeProbe.ValueProbe- 类型:
class - 修饰符:
private - 源码定位:
L45 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public void reset() @ L20
- 方法名:reset
- 源码定位:L20
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void tick(Level level, Vec3 position) @ L27
- 方法名:tick
- 源码定位:L27
- 返回类型:void
- 修饰符:public
参数:
- level: Level
- position: Vec3
说明:
TODO
public <Value> Value getValue(EnvironmentAttribute<Value> attribute, float partialTicks) @ L39
- 方法名:getValue
- 源码定位:L39
- 返回类型:
Value - 修饰符:public
参数:
- attribute: EnvironmentAttribute
- partialTicks: float
说明:
TODO
代码
public class EnvironmentAttributeProbe {
private final Map<EnvironmentAttribute<?>, EnvironmentAttributeProbe.ValueProbe<?>> valueProbes = new Reference2ObjectOpenHashMap<>();
private final Function<EnvironmentAttribute<?>, EnvironmentAttributeProbe.ValueProbe<?>> valueProbeFactory = x$0 -> new EnvironmentAttributeProbe.ValueProbe<>(
x$0
);
private @Nullable Level level;
private @Nullable Vec3 position;
private final SpatialAttributeInterpolator biomeInterpolator = new SpatialAttributeInterpolator();
public void reset() {
this.level = null;
this.position = null;
this.biomeInterpolator.clear();
this.valueProbes.clear();
}
public void tick(Level level, Vec3 position) {
this.level = level;
this.position = position;
this.valueProbes.values().removeIf(EnvironmentAttributeProbe.ValueProbe::tick);
this.biomeInterpolator.clear();
GaussianSampler.sample(
position.scale(0.25),
level.getBiomeManager()::getNoiseBiomeAtQuart,
(weight, biome) -> this.biomeInterpolator.accumulate(weight, biome.value().getAttributes())
);
}
public <Value> Value getValue(EnvironmentAttribute<Value> attribute, float partialTicks) {
EnvironmentAttributeProbe.ValueProbe<Value> valueProbe = (EnvironmentAttributeProbe.ValueProbe<Value>)this.valueProbes
.computeIfAbsent(attribute, this.valueProbeFactory);
return valueProbe.get(attribute, partialTicks);
}
private class ValueProbe<Value> {
private Value lastValue;
private @Nullable Value newValue;
public ValueProbe(EnvironmentAttribute<Value> attribute) {
Objects.requireNonNull(EnvironmentAttributeProbe.this);
super();
Value value = this.getValueFromLevel(attribute);
this.lastValue = value;
this.newValue = value;
}
private Value getValueFromLevel(EnvironmentAttribute<Value> attribute) {
return EnvironmentAttributeProbe.this.level != null && EnvironmentAttributeProbe.this.position != null
? EnvironmentAttributeProbe.this.level
.environmentAttributes()
.getValue(attribute, EnvironmentAttributeProbe.this.position, EnvironmentAttributeProbe.this.biomeInterpolator)
: attribute.defaultValue();
}
public boolean tick() {
if (this.newValue == null) {
return true;
} else {
this.lastValue = this.newValue;
this.newValue = null;
return false;
}
}
public Value get(EnvironmentAttribute<Value> attribute, float partialTicks) {
if (this.newValue == null) {
this.newValue = this.getValueFromLevel(attribute);
}
return attribute.type().partialTickLerp().apply(partialTicks, this.lastValue, this.newValue);
}
}
}引用的其他类
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
GaussianSampler.sample()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
SpatialAttributeInterpolator()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置: