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

import net.minecraft.world.entity.Entity;
import java.util.Optional;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.EntityType;
import java.util.List;
import net.minecraft.core.Position;
import net.minecraft.core.GlobalPos;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import net.minecraft.world.entity.ai.memory.WalkTarget;
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.LivingEntity;

public class SocializeAtBell extends Behavior<LivingEntity> {
    public SocializeAtBell() {
        super(ImmutableMap.<MemoryModuleType<WalkTarget>, MemoryStatus>of(MemoryModuleType.WALK_TARGET, MemoryStatus.REGISTERED, (MemoryModuleType<WalkTarget>)MemoryModuleType.LOOK_TARGET, MemoryStatus.REGISTERED, (MemoryModuleType<WalkTarget>)MemoryModuleType.MEETING_POINT, MemoryStatus.VALUE_PRESENT, (MemoryModuleType<WalkTarget>)MemoryModuleType.VISIBLE_LIVING_ENTITIES, MemoryStatus.VALUE_PRESENT, (MemoryModuleType<WalkTarget>)MemoryModuleType.INTERACTION_TARGET, MemoryStatus.VALUE_ABSENT));
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel zd, final LivingEntity aoy) {
        final Brain<?> apr4 = aoy.getBrain();
        final Optional<GlobalPos> optional5 = apr4.<GlobalPos>getMemory(MemoryModuleType.MEETING_POINT);
        return zd.getRandom().nextInt(100) == 0 && optional5.isPresent() && zd.dimension() == optional5.get().dimension() && optional5.get().pos().closerThan(aoy.position(), 4.0) && apr4.<List<LivingEntity>>getMemory(MemoryModuleType.VISIBLE_LIVING_ENTITIES).get().stream().anyMatch(aoy -> EntityType.VILLAGER.equals(aoy.getType()));
    }
    
    @Override
    protected void start(final ServerLevel zd, final LivingEntity aoy, final long long3) {
        final Brain<?> apr6 = aoy.getBrain();
        final Brain brain;
        final MemoryModuleType walk_TARGET;
        final Object object;
        apr6.<List<LivingEntity>>getMemory(MemoryModuleType.VISIBLE_LIVING_ENTITIES).ifPresent(list -> list.stream().filter(aoy -> EntityType.VILLAGER.equals(aoy.getType())).filter(aoy2 -> aoy2.distanceToSqr(aoy) <= 32.0).findFirst().ifPresent(aoy -> {
            brain.setMemory(MemoryModuleType.INTERACTION_TARGET, aoy);
            brain.setMemory(MemoryModuleType.LOOK_TARGET, new EntityTracker(aoy, true));
            walk_TARGET = MemoryModuleType.WALK_TARGET;
            new WalkTarget(new EntityTracker(aoy, false), 0.3f, 1);
            brain.setMemory(walk_TARGET, object);
        }));
    }
}
