2025-11-24 22:52:51 +03:00

69 lines
2.3 KiB
Java

/*
* 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.RandomSource;
import net.minecraft.util.valueproviders.IntProvider;
import net.minecraft.util.valueproviders.IntProviderType;
public class BiasedToBottomInt
extends IntProvider {
public static final MapCodec<BiasedToBottomInt> 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, BiasedToBottomInt::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 BiasedToBottomInt(int minInclusive, int maxInclusive) {
this.minInclusive = minInclusive;
this.maxInclusive = maxInclusive;
}
public static BiasedToBottomInt of(int minInclusive, int maxInclusive) {
return new BiasedToBottomInt(minInclusive, maxInclusive);
}
@Override
public int sample(RandomSource random) {
return this.minInclusive + random.nextInt(random.nextInt(this.maxInclusive - this.minInclusive + 1) + 1);
}
@Override
public int getMinValue() {
return this.minInclusive;
}
@Override
public int getMaxValue() {
return this.maxInclusive;
}
@Override
public IntProviderType<?> getType() {
return IntProviderType.BIASED_TO_BOTTOM;
}
public String toString() {
return "[" + this.minInclusive + "-" + this.maxInclusive + "]";
}
}