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

import net.minecraft.world.entity.Entity;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.npc.Villager;

public class VillagerCalmDown extends Behavior<Villager> {
    public VillagerCalmDown() {
        super(ImmutableMap.of());
    }
    
    @Override
    protected void start(final ServerLevel zd, final Villager bdp, final long long3) {
        final boolean boolean6 = VillagerPanicTrigger.isHurt(bdp) || VillagerPanicTrigger.hasHostile(bdp) || isCloseToEntityThatHurtMe(bdp);
        if (!boolean6) {
            bdp.getBrain().<DamageSource>eraseMemory(MemoryModuleType.HURT_BY);
            bdp.getBrain().<LivingEntity>eraseMemory(MemoryModuleType.HURT_BY_ENTITY);
            bdp.getBrain().updateActivityFromSchedule(zd.getDayTime(), zd.getGameTime());
        }
    }
    
    private static boolean isCloseToEntityThatHurtMe(final Villager bdp) {
        return bdp.getBrain().<LivingEntity>getMemory(MemoryModuleType.HURT_BY_ENTITY).filter(aoy -> aoy.distanceToSqr(bdp) <= 36.0).isPresent();
    }
}
