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

import net.minecraft.server.level.ServerPlayer;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.ToDoubleFunction;
import java.util.Comparator;
import net.minecraft.world.entity.Entity;
import java.util.function.Predicate;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.player.Player;
import java.util.List;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;

public class PlayerSensor extends Sensor<LivingEntity> {
    @Override
    protected void doTick(final ServerLevel xd, final LivingEntity akz) {
        final List<Player> list4 = xd.players().stream().filter(EntitySelector.NO_SPECTATORS).filter(xe -> akz.distanceToSqr(xe) < 256.0).sorted(Comparator.comparingDouble(akz::distanceToSqr)).collect(Collectors.toList());
        final Brain<?> alp5 = akz.getBrain();
        alp5.<List<Player>>setMemory(MemoryModuleType.NEAREST_PLAYERS, list4);
        alp5.<Player>setMemory(MemoryModuleType.NEAREST_VISIBLE_PLAYER, list4.stream().filter(akz::canSee).findFirst());
    }
    
    @Override
    public Set<MemoryModuleType<?>> requires() {
        return ImmutableSet.of(MemoryModuleType.NEAREST_PLAYERS, (MemoryModuleType<List<Player>>)MemoryModuleType.NEAREST_VISIBLE_PLAYER);
    }
}
