package net.minecraft.world.level.levelgen.feature.featuresize;

import com.mojang.datafixers.kinds.Applicative;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.OptionalInt;
import com.mojang.serialization.Codec;

public class ThreeLayersFeatureSize extends FeatureSize {
    public static final Codec<ThreeLayersFeatureSize> CODEC;
    private final int limit;
    private final int upperLimit;
    private final int lowerSize;
    private final int middleSize;
    private final int upperSize;
    
    public ThreeLayersFeatureSize(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final OptionalInt optionalInt) {
        super(optionalInt);
        this.limit = integer1;
        this.upperLimit = integer2;
        this.lowerSize = integer3;
        this.middleSize = integer4;
        this.upperSize = integer5;
    }
    
    @Override
    protected FeatureSizeType<?> type() {
        return FeatureSizeType.THREE_LAYERS_FEATURE_SIZE;
    }
    
    @Override
    public int getSizeAtHeight(final int integer1, final int integer2) {
        if (integer2 < this.limit) {
            return this.lowerSize;
        }
        if (integer2 >= integer1 - this.upperLimit) {
            return this.upperSize;
        }
        return this.middleSize;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Codec.INT.fieldOf("limit").withDefault(1).forGetter(coy -> coy.limit), (App)Codec.INT.fieldOf("upper_limit").withDefault(1).forGetter(coy -> coy.upperLimit), (App)Codec.INT.fieldOf("lower_size").withDefault(0).forGetter(coy -> coy.lowerSize), (App)Codec.INT.fieldOf("middle_size").withDefault(1).forGetter(coy -> coy.middleSize), (App)Codec.INT.fieldOf("upper_size").withDefault(1).forGetter(coy -> coy.upperSize), (App)FeatureSize.<FeatureSize>minClippedHeightCodec()).apply(instance, ThreeLayersFeatureSize::new));
    }
}
