/* * 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 ClampedNormalInt extends IntProvider { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)Codec.FLOAT.fieldOf("mean").forGetter(c -> Float.valueOf(c.mean)), (App)Codec.FLOAT.fieldOf("deviation").forGetter(c -> Float.valueOf(c.deviation)), (App)Codec.INT.fieldOf("min_inclusive").forGetter(c -> c.minInclusive), (App)Codec.INT.fieldOf("max_inclusive").forGetter(c -> c.maxInclusive)).apply((Applicative)i, ClampedNormalInt::new)).validate(c -> { if (c.maxInclusive < c.minInclusive) { return DataResult.error(() -> "Max must be larger than min: [" + c.minInclusive + ", " + c.maxInclusive + "]"); } return DataResult.success((Object)c); }); private final float mean; private final float deviation; private final int minInclusive; private final int maxInclusive; public static ClampedNormalInt of(float mean, float deviation, int min_inclusive, int max_inclusive) { return new ClampedNormalInt(mean, deviation, min_inclusive, max_inclusive); } private ClampedNormalInt(float mean, float deviation, int minInclusive, int maxInclusive) { this.mean = mean; this.deviation = deviation; this.minInclusive = minInclusive; this.maxInclusive = maxInclusive; } @Override public int sample(RandomSource random) { return ClampedNormalInt.sample(random, this.mean, this.deviation, this.minInclusive, this.maxInclusive); } public static int sample(RandomSource random, float mean, float deviation, float min_inclusive, float max_inclusive) { return (int)Mth.clamp(Mth.normal(random, mean, deviation), min_inclusive, max_inclusive); } @Override public int getMinValue() { return this.minInclusive; } @Override public int getMaxValue() { return this.maxInclusive; } @Override public IntProviderType getType() { return IntProviderType.CLAMPED_NORMAL; } public String toString() { return "normal(" + this.mean + ", " + this.deviation + ") in [" + this.minInclusive + "-" + this.maxInclusive + "]"; } }