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