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

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

import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.npc.sensorinfo.parameterproviders.ParameterProvider;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;

public class EntityPositionProvider extends PositionProvider
{
    @Nullable
    private Ref<EntityStore> target;
    
    public EntityPositionProvider() {
    }
    
    public EntityPositionProvider(final ParameterProvider parameterProvider) {
        super(parameterProvider);
    }
    
    @Override
    public void clear() {
        super.clear();
        this.target = null;
    }
    
    @Override
    public Ref<EntityStore> setTarget(@Nullable final Ref<EntityStore> ref, @Nonnull final ComponentAccessor<EntityStore> componentAccessor) {
        return this.target = super.setTarget(ref, componentAccessor);
    }
    
    @Nullable
    @Override
    public Ref<EntityStore> getTarget() {
        if (this.target == null) {
            return null;
        }
        final Store<EntityStore> store = this.target.getStore();
        if (!this.target.isValid() || store.getArchetype(this.target).contains(DeathComponent.getComponentType())) {
            this.clear();
        }
        return this.target;
    }
    
    @Override
    public boolean hasPosition() {
        return this.getTarget() != null;
    }
}
