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

import java.util.Optional;
import java.util.List;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.entity.Entity;

public class EntityTracker implements PositionTracker {
    private final Entity entity;
    private final boolean trackEyeHeight;
    
    public EntityTracker(final Entity aom, final boolean boolean2) {
        this.entity = aom;
        this.trackEyeHeight = boolean2;
    }
    
    @Override
    public Vec3 currentPosition() {
        return this.trackEyeHeight ? this.entity.position().add(0.0, this.entity.getEyeHeight(), 0.0) : this.entity.position();
    }
    
    @Override
    public BlockPos currentBlockPosition() {
        return this.entity.blockPosition();
    }
    
    @Override
    public boolean isVisibleBy(final LivingEntity aoy) {
        if (this.entity instanceof LivingEntity) {
            final Optional<List<LivingEntity>> optional3 = aoy.getBrain().<List<LivingEntity>>getMemory(MemoryModuleType.VISIBLE_LIVING_ENTITIES);
            return this.entity.isAlive() && optional3.isPresent() && optional3.get().contains(this.entity);
        }
        return true;
    }
    
    @Override
    public String toString() {
        return "EntityTracker for " + this.entity;
    }
}
