Search in sources :

Example 1 with PacketSyncBludgeoning

use of com.lying.variousoddities.network.PacketSyncBludgeoning in project VariousOddities by Lyinginbedmon.

the class VOBusServer method onBludgeonedEvent.

/**
 * Prevents bludgeoning damage from affecting the entity's health instead of their bludgeoning value.
 * @param event
 */
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onBludgeonedEvent(LivingHurtEvent event) {
    if (!event.isCanceled() && event.getSource() == VODamageSource.BLUDGEON) {
        LivingEntity hurtEntity = event.getEntityLiving();
        LivingData data = LivingData.forEntity(hurtEntity);
        if (data != null) {
            data.setBludgeoning(data.getBludgeoning() + event.getAmount());
            if (hurtEntity.getType() == EntityType.PLAYER && !hurtEntity.getEntityWorld().isRemote)
                PacketHandler.sendTo((ServerPlayerEntity) hurtEntity, new PacketSyncBludgeoning(data.getBludgeoning()));
        }
        event.setCanceled(true);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PacketSyncBludgeoning(com.lying.variousoddities.network.PacketSyncBludgeoning) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) LivingData(com.lying.variousoddities.capabilities.LivingData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

LivingData (com.lying.variousoddities.capabilities.LivingData)1 PacketSyncBludgeoning (com.lying.variousoddities.network.PacketSyncBludgeoning)1 PacketSyncLivingData (com.lying.variousoddities.network.PacketSyncLivingData)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1