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

import com.google.common.collect.Lists;
import net.minecraft.world.entity.EntityType;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Predicate;
import net.minecraft.server.level.ServerLevel;
import java.util.List;
import com.google.common.collect.ImmutableSet;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import java.util.Set;
import net.minecraft.world.entity.LivingEntity;

public class VillagerBabiesSensor extends Sensor<LivingEntity> {
    @Override
    public Set<MemoryModuleType<?>> requires() {
        return ImmutableSet.of(MemoryModuleType.VISIBLE_VILLAGER_BABIES);
    }
    
    @Override
    protected void doTick(final ServerLevel xd, final LivingEntity akz) {
        akz.getBrain().<List<LivingEntity>>setMemory(MemoryModuleType.VISIBLE_VILLAGER_BABIES, this.getNearestVillagerBabies(akz));
    }
    
    private List<LivingEntity> getNearestVillagerBabies(final LivingEntity akz) {
        return this.getVisibleEntities(akz).stream().filter(this::isVillagerBaby).collect(Collectors.toList());
    }
    
    private boolean isVillagerBaby(final LivingEntity akz) {
        return akz.getType() == EntityType.VILLAGER && akz.isBaby();
    }
    
    private List<LivingEntity> getVisibleEntities(final LivingEntity akz) {
        return akz.getBrain().<List<LivingEntity>>getMemory(MemoryModuleType.VISIBLE_LIVING_ENTITIES).orElse(Lists.newArrayList());
    }
}
