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

import java.util.Optional;
import net.minecraft.world.entity.LivingEntity;
import java.util.List;
import net.minecraft.server.level.ServerLevel;
import com.google.common.collect.ImmutableSet;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import java.util.Set;
import net.minecraft.world.entity.AgableMob;

public class AdultSensor extends Sensor<AgableMob> {
    @Override
    public Set<MemoryModuleType<?>> requires() {
        return ImmutableSet.of(MemoryModuleType.NEAREST_VISIBLE_ADULT, (MemoryModuleType<AgableMob>)MemoryModuleType.VISIBLE_LIVING_ENTITIES);
    }
    
    @Override
    protected void doTick(final ServerLevel zd, final AgableMob aok) {
        aok.getBrain().<List<LivingEntity>>getMemory(MemoryModuleType.VISIBLE_LIVING_ENTITIES).ifPresent(list -> this.setNearestVisibleAdult(aok, list));
    }
    
    private void setNearestVisibleAdult(final AgableMob aok, final List<LivingEntity> list) {
        final Optional<AgableMob> optional4 = list.stream().filter(aoy -> aoy.getType() == aok.getType()).<AgableMob>map(aoy -> aoy).filter(aok -> !aok.isBaby()).findFirst();
        aok.getBrain().<AgableMob>setMemory(MemoryModuleType.NEAREST_VISIBLE_ADULT, optional4);
    }
}
