WeightedListInt.java

net.minecraft.util.valueproviders.WeightedListInt

信息

  • 全限定名:net.minecraft.util.valueproviders.WeightedListInt
  • 类型:public class
  • 包:net.minecraft.util.valueproviders
  • 源码路径:src/main/java/net/minecraft/util/valueproviders/WeightedListInt.java
  • 起始行号:L9
  • 实现:IntProvider
  • 职责:

    TODO

字段/常量

  • MAP_CODEC

    • 类型: MapCodec<WeightedListInt>
    • 修饰符: public static final
    • 源码定位: L10
    • 说明:

      TODO

  • distribution

    • 类型: WeightedList<IntProvider>
    • 修饰符: private final
    • 源码定位: L13
    • 说明:

      TODO

  • minValue

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

      TODO

  • maxValue

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

      TODO

内部类/嵌套类型

构造器

public WeightedListInt(WeightedList<IntProvider> distribution) @ L17

  • 构造器名:WeightedListInt
  • 源码定位:L17
  • 修饰符:public

参数:

  • distribution: WeightedList

说明:

TODO

方法

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

public int sample(RandomSource random) @ L33

  • 方法名:sample
  • 源码定位:L33
  • 返回类型:int
  • 修饰符:public

参数:

  • random: RandomSource

说明:

TODO

public int minInclusive() @ L38

  • 方法名:minInclusive
  • 源码定位:L38
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public int maxInclusive() @ L43

  • 方法名:maxInclusive
  • 源码定位:L43
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public MapCodec<WeightedListInt> codec() @ L48

  • 方法名:codec
  • 源码定位:L48
  • 返回类型:MapCodec
  • 修饰符:public

参数:

说明:

TODO

代码

public class WeightedListInt implements IntProvider {
    public static final MapCodec<WeightedListInt> MAP_CODEC = RecordCodecBuilder.mapCodec(
        i -> i.group(WeightedList.nonEmptyCodec(IntProviders.CODEC).fieldOf("distribution").forGetter(c -> c.distribution)).apply(i, WeightedListInt::new)
    );
    private final WeightedList<IntProvider> distribution;
    private final int minValue;
    private final int maxValue;
 
    public WeightedListInt(WeightedList<IntProvider> distribution) {
        this.distribution = distribution;
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
 
        for (Weighted<IntProvider> value : distribution.unwrap()) {
            int entryMin = value.value().minInclusive();
            int entryMax = value.value().maxInclusive();
            min = Math.min(min, entryMin);
            max = Math.max(max, entryMax);
        }
 
        this.minValue = min;
        this.maxValue = max;
    }
 
    @Override
    public int sample(RandomSource random) {
        return this.distribution.getRandomOrThrow(random).sample(random);
    }
 
    @Override
    public int minInclusive() {
        return this.minValue;
    }
 
    @Override
    public int maxInclusive() {
        return this.maxValue;
    }
 
    @Override
    public MapCodec<WeightedListInt> codec() {
        return MAP_CODEC;
    }
}

引用的其他类

  • RandomSource

    • 引用位置: 参数
  • WeightedList

    • 引用位置: 参数/字段/方法调用
    • 关联成员: WeightedList.nonEmptyCodec()
  • IntProvider

    • 引用位置: 参数/字段/实现