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

package com.hypixel.hytale.builtin.hytalegenerator.density.nodes;

import com.hypixel.hytale.math.vector.Vector3d;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.hypixel.hytale.builtin.hytalegenerator.density.Density;

public class AnchorDensity extends Density
{
    @Nullable
    private Density input;
    private final boolean isReversed;
    
    public AnchorDensity(final Density input, final boolean isReversed) {
        this.input = input;
        this.isReversed = isReversed;
    }
    
    @Override
    public double process(@Nonnull final Context context) {
        final Vector3d anchor = context.densityAnchor;
        if (anchor == null) {
            return this.input.process(context);
        }
        if (this.isReversed) {
            final Vector3d childPosition = new Vector3d(context.position.x + anchor.x, context.position.y + anchor.y, context.position.z + anchor.z);
            final Context childContext = new Context(context);
            childContext.position = childPosition;
            return this.input.process(childContext);
        }
        final Vector3d childPosition = new Vector3d(context.position.x - anchor.x, context.position.y - anchor.y, context.position.z - anchor.z);
        final Context childContext = new Context(context);
        childContext.position = childPosition;
        return this.input.process(childContext);
    }
    
    @Override
    public void setInputs(@Nonnull final Density[] inputs) {
        if (inputs.length == 0) {
            this.input = null;
        }
        this.input = inputs[0];
    }
}
