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

import java.util.function.Function;
import com.mojang.datafixers.kinds.Applicative;
import net.minecraft.util.Codecs;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Codec;

public class StructureFeatureConfiguration {
    public static final Codec<StructureFeatureConfiguration> CODEC;
    private final int spacing;
    private final int separation;
    private final int salt;
    
    public StructureFeatureConfiguration(final int integer1, final int integer2, final int integer3) {
        this.spacing = integer1;
        this.separation = integer2;
        this.salt = integer3;
    }
    
    public int spacing() {
        return this.spacing;
    }
    
    public int separation() {
        return this.separation;
    }
    
    public int salt() {
        return this.salt;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Codecs.intRange(0, 4096).fieldOf("spacing").forGetter(cot -> cot.spacing), (App)Codecs.intRange(0, 4096).fieldOf("separation").forGetter(cot -> cot.separation), (App)Codecs.intRange(0, Integer.MAX_VALUE).fieldOf("salt").forGetter(cot -> cot.salt)).apply(instance, StructureFeatureConfiguration::new)).comapFlatMap(cot -> {
            if (cot.spacing <= cot.separation) {
                return DataResult.error("Spacing has to be smaller than separation");
            }
            else {
                return DataResult.success(cot);
            }
        }, (Function)Function.identity());
    }
}
