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

import net.minecraft.world.level.GameRules;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import java.util.UUID;
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.Mob;

public class StopBeingAngryIfTargetDead<E extends Mob> extends Behavior<E> {
    public StopBeingAngryIfTargetDead() {
        super(ImmutableMap.<MemoryModuleType<UUID>, MemoryStatus>of(MemoryModuleType.ANGRY_AT, MemoryStatus.VALUE_PRESENT));
    }
    
    @Override
    protected void start(final ServerLevel zd, final E aoz, final long long3) {
        BehaviorUtils.getLivingEntityFromUUIDMemory(aoz, MemoryModuleType.ANGRY_AT).ifPresent(aoy -> {
            if (aoy.isDeadOrDying() && (aoy.getType() != EntityType.PLAYER || zd.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS))) {
                aoz.getBrain().<UUID>eraseMemory(MemoryModuleType.ANGRY_AT);
            }
        });
    }
}
