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 TwoLayersFeatureSize extends FeatureSize {
    public static final Codec<TwoLayersFeatureSize> CODEC;
    private final int limit;
    private final int lowerSize;
    private final int upperSize;
    
    public TwoLayersFeatureSize(final int integer1, final int integer2, final int integer3) {
        this(integer1, integer2, integer3, OptionalInt.empty());
    }
    
    public TwoLayersFeatureSize(final int integer1, final int integer2, final int integer3, final OptionalInt optionalInt) {
        super(optionalInt);
        this.limit = integer1;
        this.lowerSize = integer2;
        this.upperSize = integer3;
    }
    
    @Override
    protected FeatureSizeType<?> type() {
        return FeatureSizeType.TWO_LAYERS_FEATURE_SIZE;
    }
    
    @Override
    public int getSizeAtHeight(final int integer1, final int integer2) {
        return (integer2 < this.limit) ? this.lowerSize : this.upperSize;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Codec.INT.fieldOf("limit").withDefault(1).forGetter(coz -> coz.limit), (App)Codec.INT.fieldOf("lower_size").withDefault(0).forGetter(coz -> coz.lowerSize), (App)Codec.INT.fieldOf("upper_size").withDefault(1).forGetter(coz -> coz.upperSize), (App)FeatureSize.<FeatureSize>minClippedHeightCodec()).apply(instance, TwoLayersFeatureSize::new));
    }
}
