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

77 lines
2.6 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.FloatProvider;
import net.minecraft.util.valueproviders.FloatProviderType;
public class TrapezoidFloat
extends FloatProvider {
public static final MapCodec<TrapezoidFloat> CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)Codec.FLOAT.fieldOf("min").forGetter(t -> Float.valueOf(t.min)), (App)Codec.FLOAT.fieldOf("max").forGetter(t -> Float.valueOf(t.max)), (App)Codec.FLOAT.fieldOf("plateau").forGetter(t -> Float.valueOf(t.plateau))).apply((Applicative)i, TrapezoidFloat::new)).validate(c -> {
if (c.max < c.min) {
return DataResult.error(() -> "Max must be larger than min: [" + c.min + ", " + c.max + "]");
}
if (c.plateau > c.max - c.min) {
return DataResult.error(() -> "Plateau can at most be the full span: [" + c.min + ", " + c.max + "]");
}
return DataResult.success((Object)c);
});
private final float min;
private final float max;
private final float plateau;
public static TrapezoidFloat of(float min, float max, float plateau) {
return new TrapezoidFloat(min, max, plateau);
}
private TrapezoidFloat(float min, float max, float plateau) {
this.min = min;
this.max = max;
this.plateau = plateau;
}
@Override
public float sample(RandomSource random) {
float range = this.max - this.min;
float plateauStart = (range - this.plateau) / 2.0f;
float plateauEnd = range - plateauStart;
return this.min + random.nextFloat() * plateauEnd + random.nextFloat() * plateauStart;
}
@Override
public float getMinValue() {
return this.min;
}
@Override
public float getMaxValue() {
return this.max;
}
@Override
public FloatProviderType<?> getType() {
return FloatProviderType.TRAPEZOID;
}
public String toString() {
return "trapezoid(" + this.plateau + ") in [" + this.min + "-" + this.max + "]";
}
}