Search in sources :

Example 1 with LivingWakeUpEvent

use of com.lying.variousoddities.api.event.LivingWakeUpEvent in project VariousOddities by Lyinginbedmon.

the class VOBusServer method onSleepingHurtEvent.

/**
 * If a sleeping mob is harmed, wake them up.
 * @param event
 */
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onSleepingHurtEvent(LivingHurtEvent event) {
    if (event.getAmount() > 0F && !event.isCanceled()) {
        LivingEntity hurtEntity = event.getEntityLiving();
        if (VOPotions.isSilenced(hurtEntity))
            return;
        wakeupEntitiesAround(hurtEntity);
        EffectInstance sleepEffect = hurtEntity.getActivePotionEffect(VOPotions.SLEEP);
        int tier = (sleepEffect == null || sleepEffect.getDuration() <= 0) ? -1 : sleepEffect.getAmplifier();
        if (PotionSleep.isSleeping(hurtEntity) && tier < 1)
            if (!MinecraftForge.EVENT_BUS.post(new LivingWakeUpEvent(hurtEntity, true)))
                hurtEntity.removePotionEffect(VOPotions.SLEEP);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) LivingWakeUpEvent(com.lying.variousoddities.api.event.LivingWakeUpEvent) EffectInstance(net.minecraft.potion.EffectInstance) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

LivingWakeUpEvent (com.lying.variousoddities.api.event.LivingWakeUpEvent)1 LivingEntity (net.minecraft.entity.LivingEntity)1 EffectInstance (net.minecraft.potion.EffectInstance)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1