minecraft-src/net/minecraft/world/level/levelgen/heightproviders/ConstantHeight.java
2025-07-04 01:41:11 +03:00

38 lines
1.1 KiB
Java

package net.minecraft.world.level.levelgen.heightproviders;
import com.mojang.serialization.MapCodec;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.WorldGenerationContext;
public class ConstantHeight extends HeightProvider {
public static final ConstantHeight ZERO = new ConstantHeight(VerticalAnchor.absolute(0));
public static final MapCodec<ConstantHeight> CODEC = VerticalAnchor.CODEC.fieldOf("value").xmap(ConstantHeight::new, ConstantHeight::getValue);
private final VerticalAnchor value;
public static ConstantHeight of(VerticalAnchor value) {
return new ConstantHeight(value);
}
private ConstantHeight(VerticalAnchor value) {
this.value = value;
}
public VerticalAnchor getValue() {
return this.value;
}
@Override
public int sample(RandomSource random, WorldGenerationContext context) {
return this.value.resolveY(context);
}
@Override
public HeightProviderType<?> getType() {
return HeightProviderType.CONSTANT;
}
public String toString() {
return this.value.toString();
}
}