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 java.util.Objects;
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 xd, final LivingEntity akz) {
        final Brain<?> alp4 = akz.getBrain();
        final Optional<GlobalPos> optional5 = alp4.<GlobalPos>getMemory(MemoryModuleType.MEETING_POINT);
        return xd.getRandom().nextInt(100) == 0 && optional5.isPresent() && Objects.equals(xd.getDimension().getType(), optional5.get().dimension()) && optional5.get().pos().closerThan(akz.position(), 4.0) && alp4.<List<LivingEntity>>getMemory(MemoryModuleType.VISIBLE_LIVING_ENTITIES).get().stream().anyMatch(akz -> EntityType.VILLAGER.equals(akz.getType()));
    }
    
    @Override
    protected void start(final ServerLevel xd, final LivingEntity akz, final long long3) {
        final Brain<?> alp6 = akz.getBrain();
        final Brain brain;
        final MemoryModuleType walk_TARGET;
        final Object object;
        alp6.<List<LivingEntity>>getMemory(MemoryModuleType.VISIBLE_LIVING_ENTITIES).ifPresent(list -> list.stream().filter(akz -> EntityType.VILLAGER.equals(akz.getType())).filter(akz2 -> akz2.distanceToSqr(akz) <= 32.0).findFirst().ifPresent(akz -> {
            brain.setMemory(MemoryModuleType.INTERACTION_TARGET, akz);
            brain.setMemory(MemoryModuleType.LOOK_TARGET, new EntityPosWrapper(akz));
            walk_TARGET = MemoryModuleType.WALK_TARGET;
            new WalkTarget(new EntityPosWrapper(akz), 0.3f, 1);
            brain.setMemory(walk_TARGET, object);
        }));
    }
}
