package net.minecraft.world.entity.ai.behavior;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.Mob;

public class LookAtTargetSink extends Behavior<Mob> {
    public LookAtTargetSink(final int integer1, final int integer2) {
        super(ImmutableMap.<MemoryModuleType<PositionWrapper>, MemoryStatus>of(MemoryModuleType.LOOK_TARGET, MemoryStatus.VALUE_PRESENT), integer1, integer2);
    }
    
    @Override
    protected boolean canStillUse(final ServerLevel xd, final Mob ala, final long long3) {
        return ala.getBrain().<PositionWrapper>getMemory(MemoryModuleType.LOOK_TARGET).filter(amz -> amz.isVisible(ala)).isPresent();
    }
    
    @Override
    protected void stop(final ServerLevel xd, final Mob ala, final long long3) {
        ala.getBrain().<PositionWrapper>eraseMemory(MemoryModuleType.LOOK_TARGET);
    }
    
    @Override
    protected void tick(final ServerLevel xd, final Mob ala, final long long3) {
        ala.getBrain().<PositionWrapper>getMemory(MemoryModuleType.LOOK_TARGET).ifPresent(amz -> ala.getLookControl().setLookAt(amz.getLookAtPos()));
    }
}
