ClampedNormalInt.java
net.minecraft.util.valueproviders.ClampedNormalInt
信息
- 全限定名:net.minecraft.util.valueproviders.ClampedNormalInt
- 类型:public record
- 包:net.minecraft.util.valueproviders
- 源码路径:src/main/java/net/minecraft/util/valueproviders/ClampedNormalInt.java
- 起始行号:L10
- 实现:IntProvider
- 职责:
TODO
字段/常量
MAP_CODEC- 类型:
MapCodec<ClampedNormalInt> - 修饰符:
public static final - 源码定位:
L11 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static ClampedNormalInt of(float mean, float deviation, int minInclusive, int maxInclusive) @ L26
- 方法名:of
- 源码定位:L26
- 返回类型:ClampedNormalInt
- 修饰符:public static
参数:
- mean: float
- deviation: float
- minInclusive: int
- maxInclusive: int
说明:
TODO
public int sample(RandomSource random) @ L30
- 方法名:sample
- 源码定位:L30
- 返回类型:int
- 修饰符:public
参数:
- random: RandomSource
说明:
TODO
public static int sample(RandomSource random, float mean, float deviation, float minInclusive, float maxInclusive) @ L35
- 方法名:sample
- 源码定位:L35
- 返回类型:int
- 修饰符:public static
参数:
- random: RandomSource
- mean: float
- deviation: float
- minInclusive: float
- maxInclusive: float
说明:
TODO
public MapCodec<ClampedNormalInt> codec() @ L39
- 方法名:codec
- 源码定位:L39
- 返回类型:MapCodec
- 修饰符:public
参数:
- 无
说明:
TODO
public String toString() @ L44
- 方法名:toString
- 源码定位:L44
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public record ClampedNormalInt(float mean, float deviation, int minInclusive, int maxInclusive) implements IntProvider {
public static final MapCodec<ClampedNormalInt> MAP_CODEC = RecordCodecBuilder.<ClampedNormalInt>mapCodec(
i -> i.group(
Codec.FLOAT.fieldOf("mean").forGetter(ClampedNormalInt::mean),
Codec.FLOAT.fieldOf("deviation").forGetter(ClampedNormalInt::deviation),
Codec.INT.fieldOf("min_inclusive").forGetter(ClampedNormalInt::minInclusive),
Codec.INT.fieldOf("max_inclusive").forGetter(ClampedNormalInt::maxInclusive)
)
.apply(i, ClampedNormalInt::new)
)
.validate(
c -> c.maxInclusive < c.minInclusive
? DataResult.error(() -> "Max must be larger than min: [" + c.minInclusive + ", " + c.maxInclusive + "]")
: DataResult.success(c)
);
public static ClampedNormalInt of(float mean, float deviation, int minInclusive, int maxInclusive) {
return new ClampedNormalInt(mean, deviation, minInclusive, maxInclusive);
}
@Override
public int sample(RandomSource random) {
return sample(random, this.mean, this.deviation, this.minInclusive, this.maxInclusive);
}
public static int sample(RandomSource random, float mean, float deviation, float minInclusive, float maxInclusive) {
return (int)Mth.clamp(Mth.normal(random, mean, deviation), minInclusive, maxInclusive);
}
@Override
public MapCodec<ClampedNormalInt> codec() {
return MAP_CODEC;
}
@Override
public String toString() {
return "normal(" + this.mean + ", " + this.deviation + ") in [" + this.minInclusive + "-" + this.maxInclusive + "]";
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Mth.clamp(), Mth.normal()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
实现
- 引用位置: