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

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

public class ColumnFeatureConfiguration implements FeatureConfiguration {
    public static final Codec<ColumnFeatureConfiguration> CODEC;
    public final int minimumReach;
    public final int maximumReach;
    public final int minimumHeight;
    public final int maximumHeight;
    
    public ColumnFeatureConfiguration(final int integer1, final int integer2, final int integer3, final int integer4) {
        this.minimumReach = integer1;
        this.maximumReach = integer2;
        this.minimumHeight = integer3;
        this.maximumHeight = integer4;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Codec.INT.fieldOf("minimum_reach").forGetter(cnj -> cnj.minimumReach), (App)Codec.INT.fieldOf("maximum_reach").forGetter(cnj -> cnj.maximumReach), (App)Codec.INT.fieldOf("minimum_height").forGetter(cnj -> cnj.minimumHeight), (App)Codec.INT.fieldOf("maximum_height").forGetter(cnj -> cnj.maximumHeight)).apply(instance, ColumnFeatureConfiguration::new));
    }
    
    public static class Builder {
        private int minReach;
        private int maxReach;
        private int minHeight;
        private int maxHeight;
        
        public Builder horizontalReach(final int integer) {
            this.minReach = integer;
            this.maxReach = integer;
            return this;
        }
        
        public Builder horizontalReach(final int integer1, final int integer2) {
            this.minReach = integer1;
            this.maxReach = integer2;
            return this;
        }
        
        public Builder heightRange(final int integer1, final int integer2) {
            this.minHeight = integer1;
            this.maxHeight = integer2;
            return this;
        }
        
        public ColumnFeatureConfiguration build() {
            if (this.minHeight < 1) {
                throw new IllegalArgumentException("Minimum height cannot be less than 1");
            }
            if (this.minReach < 0) {
                throw new IllegalArgumentException("Minimum reach cannot be negative");
            }
            if (this.minReach > this.maxReach || this.minHeight > this.maxHeight) {
                throw new IllegalArgumentException("Minimum reach/height cannot be greater than maximum width/height");
            }
            return new ColumnFeatureConfiguration(this.minReach, this.maxReach, this.minHeight, this.maxHeight);
        }
    }
}
