/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.Codec * com.mojang.serialization.DataResult * com.mojang.serialization.MapCodec * com.mojang.serialization.codecs.RecordCodecBuilder */ package net.minecraft.util.valueproviders; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.util.Mth; import net.minecraft.util.RandomSource; import net.minecraft.util.valueproviders.IntProvider; import net.minecraft.util.valueproviders.IntProviderType; public class UniformInt extends IntProvider { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)Codec.INT.fieldOf("min_inclusive").forGetter(u -> u.minInclusive), (App)Codec.INT.fieldOf("max_inclusive").forGetter(u -> u.maxInclusive)).apply((Applicative)i, UniformInt::new)).validate(u -> { if (u.maxInclusive < u.minInclusive) { return DataResult.error(() -> "Max must be at least min, min_inclusive: " + u.minInclusive + ", max_inclusive: " + u.maxInclusive); } return DataResult.success((Object)u); }); private final int minInclusive; private final int maxInclusive; private UniformInt(int minInclusive, int maxInclusive) { this.minInclusive = minInclusive; this.maxInclusive = maxInclusive; } public static UniformInt of(int minInclusive, int maxInclusive) { return new UniformInt(minInclusive, maxInclusive); } @Override public int sample(RandomSource random) { return Mth.randomBetweenInclusive(random, this.minInclusive, this.maxInclusive); } @Override public int getMinValue() { return this.minInclusive; } @Override public int getMaxValue() { return this.maxInclusive; } @Override public IntProviderType getType() { return IntProviderType.UNIFORM; } public String toString() { return "[" + this.minInclusive + "-" + this.maxInclusive + "]"; } }