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

package com.hypixel.hytale.server.npc.navigation;

import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.npc.movement.controllers.ProbeMoveData;
import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.logger.HytaleLogger;
import javax.annotation.Nonnull;
import com.hypixel.hytale.math.vector.Vector3d;

public class AStarWithTarget extends AStarBase
{
    @Nonnull
    protected Vector3d targetPosition;
    protected long targetPositionIndex;
    
    public AStarWithTarget() {
        this.targetPosition = new Vector3d();
    }
    
    @Nonnull
    public Vector3d getTargetPosition() {
        return this.targetPosition;
    }
    
    public long getTargetPositionIndex() {
        return this.targetPositionIndex;
    }
    
    @Nonnull
    @Override
    public AStarDebugWithTarget createDebugHelper(@Nonnull final HytaleLogger logger) {
        return new AStarDebugWithTarget(this, logger);
    }
    
    public Progress initComputePath(@Nonnull final Ref<EntityStore> ref, @Nonnull final Vector3d start, @Nonnull final Vector3d end, final AStarEvaluator evaluator, @Nonnull final MotionController motionController, @Nonnull final ProbeMoveData probeMoveData, @Nonnull final AStarNodePoolProvider nodePoolProvider, @Nonnull final ComponentAccessor<EntityStore> componentAccessor) {
        final Progress progress = super.initComputePath(ref, start, evaluator, motionController, probeMoveData, nodePoolProvider, componentAccessor);
        this.targetPosition.assign(end);
        this.targetPositionIndex = this.positionToIndex(this.targetPosition);
        return progress;
    }
    
    public float findClosestPath() {
        if (this.path != null) {
            return Float.MAX_VALUE;
        }
        final AStarNode node = this.findBestVisitedNode(AStarNode::getEstimateToGoal, (oldV, v) -> v < oldV, Float.MAX_VALUE);
        if (node == null) {
            return Float.MAX_VALUE;
        }
        this.buildPath(node);
        return node.getEstimateToGoal();
    }
}
