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

import net.minecraft.world.level.block.Blocks;
import com.mojang.datafixers.kinds.Applicative;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Vec3i;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.serialization.Codec;

public class ReplaceSpheroidConfiguration implements FeatureConfiguration {
    public static final Codec<ReplaceSpheroidConfiguration> CODEC;
    public final BlockState targetState;
    public final BlockState replaceState;
    public final Vec3i minimumReach;
    public final Vec3i maximumReach;
    
    public ReplaceSpheroidConfiguration(final BlockState cfj1, final BlockState cfj2, final Vec3i gr3, final Vec3i gr4) {
        this.targetState = cfj1;
        this.replaceState = cfj2;
        this.minimumReach = gr3;
        this.maximumReach = gr4;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)BlockState.CODEC.fieldOf("target").forGetter(coj -> coj.targetState), (App)BlockState.CODEC.fieldOf("state").forGetter(coj -> coj.replaceState), (App)Vec3i.CODEC.fieldOf("minimum_reach").forGetter(coj -> coj.minimumReach), (App)Vec3i.CODEC.fieldOf("maximum_reach").forGetter(coj -> coj.maximumReach)).apply(instance, ReplaceSpheroidConfiguration::new));
    }
    
    public static class Builder {
        private BlockState target;
        private BlockState state;
        private Vec3i minimumReach;
        private Vec3i maximumReach;
        
        public Builder() {
            this.target = Blocks.AIR.defaultBlockState();
            this.state = Blocks.AIR.defaultBlockState();
            this.minimumReach = Vec3i.ZERO;
            this.maximumReach = Vec3i.ZERO;
        }
        
        public Builder targetBlockState(final BlockState cfj) {
            this.target = cfj;
            return this;
        }
        
        public Builder replaceWithBlockState(final BlockState cfj) {
            this.state = cfj;
            return this;
        }
        
        public Builder minimumReach(final Vec3i gr) {
            this.minimumReach = gr;
            return this;
        }
        
        public Builder maximumReach(final Vec3i gr) {
            this.maximumReach = gr;
            return this;
        }
        
        public ReplaceSpheroidConfiguration build() {
            if (this.minimumReach.getX() < 0 || this.minimumReach.getY() < 0 || this.minimumReach.getZ() < 0) {
                throw new IllegalArgumentException("Minimum reach cannot be less than zero");
            }
            if (this.minimumReach.getX() > this.maximumReach.getX() || this.minimumReach.getY() > this.maximumReach.getY() || this.minimumReach.getZ() > this.maximumReach.getZ()) {
                throw new IllegalArgumentException("Maximum reach must be greater than minimum reach for each axis");
            }
            return new ReplaceSpheroidConfiguration(this.target, this.state, this.minimumReach, this.maximumReach);
        }
    }
}
