// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.worldgen.biome;

import javax.annotation.Nonnull;
import com.hypixel.hytale.server.worldgen.zone.ZoneGeneratorResult;
import com.hypixel.hytale.procedurallib.condition.IIntCondition;
import com.hypixel.hytale.procedurallib.condition.IDoubleThreshold;
import com.hypixel.hytale.procedurallib.property.NoiseProperty;

public class CustomBiomeGenerator
{
    protected final NoiseProperty noiseProperty;
    protected final IDoubleThreshold threshold;
    protected final IIntCondition biomeMask;
    protected final int priority;
    
    public CustomBiomeGenerator(final NoiseProperty noiseProperty, final IDoubleThreshold threshold, final IIntCondition biomeMask, final int priority) {
        this.noiseProperty = noiseProperty;
        this.threshold = threshold;
        this.biomeMask = biomeMask;
        this.priority = priority;
    }
    
    public boolean shouldGenerateAt(final int seed, final double x, final double z, @Nonnull final ZoneGeneratorResult zoneResult, @Nonnull final Biome customBiome) {
        final double noise = this.noiseProperty.get(seed, x, z);
        if (zoneResult.getBorderDistance() < customBiome.getFadeContainer().getMaskFadeSum()) {
            final double factor = customBiome.getFadeContainer().getMaskFactor(zoneResult);
            return this.isThreshold(noise, factor);
        }
        return this.isThreshold(noise);
    }
    
    public boolean isThreshold(final double d) {
        return this.threshold.eval(d);
    }
    
    public boolean isThreshold(final double d, final double factor) {
        return factor >= 1.0E-5 && this.threshold.eval(d, factor);
    }
    
    public boolean isValidParentBiome(final int index) {
        return this.biomeMask.eval(index);
    }
    
    public int getPriority() {
        return this.priority;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "CustomBiomeGenerator{noiseProperty=" + String.valueOf(this.noiseProperty) + ", threshold=" + String.valueOf(this.threshold) + ", biomeMask=" + String.valueOf(this.biomeMask) + ", priority=" + this.priority;
    }
}
