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

import com.google.common.collect.ImmutableSet;
import java.util.Set;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;

public class HurtBySensor extends Sensor<LivingEntity> {
    @Override
    protected void doTick(final ServerLevel xd, final LivingEntity akz) {
        final Brain<?> alp4 = akz.getBrain();
        if (akz.getLastDamageSource() != null) {
            alp4.<DamageSource>setMemory(MemoryModuleType.HURT_BY, akz.getLastDamageSource());
            final Entity akq5 = alp4.<DamageSource>getMemory(MemoryModuleType.HURT_BY).get().getEntity();
            if (akq5 instanceof LivingEntity) {
                alp4.<LivingEntity>setMemory(MemoryModuleType.HURT_BY_ENTITY, (LivingEntity)akq5);
            }
        }
        else {
            alp4.<DamageSource>eraseMemory(MemoryModuleType.HURT_BY);
        }
    }
    
    @Override
    public Set<MemoryModuleType<?>> requires() {
        return ImmutableSet.of(MemoryModuleType.HURT_BY, (MemoryModuleType<DamageSource>)MemoryModuleType.HURT_BY_ENTITY);
    }
}
