Java 类net.minecraftforge.event.entity.living.LivingHurtEvent 实例源码

项目:Soot    文件:Attributes.java   
@SubscribeEvent
public static void onHurtEvent(LivingHurtEvent event)
{
    EntityLivingBase entity = event.getEntityLiving();
    DamageSource damageSource = event.getSource();
    float damage = event.getAmount();
    if(entity != null)
    {
        IAttributeInstance damageRate = null;
        if(isPhysicalDamage(damageSource))
            damageRate = entity.getEntityAttribute(PHYSICAL_DAMAGE_RATE);
        if(damageSource.isFireDamage())
            damageRate = entity.getEntityAttribute(FIRE_DAMAGE_RATE);

        if(damageRate != null)
            damage *= damageRate.getAttributeValue();
    }
    event.setAmount(damage);
}
项目:harshencastle    文件:HandlerSoulHarsherSword.java   
@SubscribeEvent
public void attackEntity(LivingHurtEvent event)
{
    try
    {
        if((event.getSource() instanceof EntityDamageSource && ((EntityDamageSource)event.getSource()).getTrueSource() instanceof EntityLivingBase
                && (((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof BaseHarshenSword ||
                    ((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof HarshenProps)
               &&!(Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(3).getItem() == HarshenArmors.harshen_jaguar_armor_helmet
                && Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(2).getItem() == HarshenArmors.harshen_jaguar_armor_chestplate
                && Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(1).getItem() == HarshenArmors.harshen_jaguar_armor_leggings
                && Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(0).getItem() == HarshenArmors.harshen_jaguar_armor_boots)))
            event.getEntityLiving().addPotionEffect(new PotionEffect(MobEffects.WITHER, 150, 1));
    }
    catch (ClassCastException clazz){}
}
项目:harshencastle    文件:HandlerRaptorScythe.java   
@SubscribeEvent
public void attackEntity(LivingHurtEvent event)
{
    try
    {
        if((event.getSource() instanceof EntityDamageSource && ((EntityDamageSource)event.getSource()).getTrueSource() instanceof EntityLivingBase
                && (((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof RaptorScythe ||
                    ((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof HarshenProps)
               &&!(Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(3).getItem() == HarshenArmors.harshen_jaguar_armor_helmet
                && Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(2).getItem() == HarshenArmors.harshen_jaguar_armor_chestplate
                && Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(1).getItem() == HarshenArmors.harshen_jaguar_armor_leggings
                && Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(0).getItem() == HarshenArmors.harshen_jaguar_armor_boots)))
            event.getEntityLiving().addPotionEffect(new PotionEffect(MobEffects.WITHER, 150, 1));
    }
    catch (ClassCastException clazz){}
}
项目:Randores2    文件:LivingHurtListener.java   
@SubscribeEvent
public void onHurt(LivingHurtEvent ev) {
    DamageSource source = ev.getSource();
    Entity root = source.getImmediateSource();
    if (root instanceof EntityLivingBase) {
        EntityLivingBase cause = (EntityLivingBase) root;
        EntityLivingBase hurt = ev.getEntityLiving();

        EnumHand active = cause.getActiveHand();
        ItemStack stack = cause.getHeldItem(active);
        RandoresItemHelper.doEmpowered(stack, hurt, cause);

        if(stack.getItem() instanceof RandoresSledgehammer) {
            Vec3d vector = hurt.getPositionVector().subtract(cause.getPositionVector()).normalize().scale(2);
            hurt.addVelocity(vector.x, 0.5, vector.z);
        }
    }
}
项目:ExtraAcC    文件:DamageRecalc.java   
@SubscribeEvent
  public void recalc(LivingHurtEvent event) {
if (!(event.entity instanceof EntityPlayer)) {
    return;
}
EntityPlayer player = (EntityPlayer) event.entity;
if (!AbilityData.get(player).isSkillLearned(SkillAirControl.INSTANCE)) {
    return;
}
if (event.source.getDamageType().equals("inWall") || event.source.getDamageType().equals("drown")) {
    event.ammount *= 0.1;
} else if (event.source.getDamageType().equals("fall")) {
    event.ammount *= 0.25;
} else if (event.source.isProjectile() || event.source.getDamageType().equals("anvil")) {
    event.ammount *= 0.75;
}
  }
项目:connor41-etfuturum2    文件:ServerEventHandler.java   
@SubscribeEvent
public void entityHurtEvent(LivingHurtEvent event) {
    if (!EtFuturum.enableDmgIndicator)
        return;
    int amount = MathHelper.floor_float(Math.min(event.entityLiving.getHealth(), event.ammount) / 2F);
    if (amount <= 0)
        return;

    // If the attacker is a player spawn the hearts aligned and facing it
    if (event.source instanceof EntityDamageSource) {
        EntityDamageSource src = (EntityDamageSource) event.source;
        Entity attacker = src.getSourceOfDamage();
        if (attacker instanceof EntityPlayer && !(attacker instanceof FakePlayer)) {
            EntityPlayer player = (EntityPlayer) attacker;
            Vec3 look = player.getLookVec();
            look.rotateAroundY((float) Math.PI / 2);
            for (int i = 0; i < amount; i++) {
                double x = event.entityLiving.posX - amount * 0.35 * look.xCoord / 2 + i * 0.35 * look.xCoord;
                double y = event.entityLiving.posY + 1.5 + event.entityLiving.worldObj.rand.nextGaussian() * 0.05;
                double z = event.entityLiving.posZ - amount * 0.35 * look.zCoord / 2 + i * 0.35 * look.zCoord;
                EtFuturum.networkWrapper.sendToAllAround(new BlackHeartParticlesMessage(x, y, z), new TargetPoint(player.worldObj.provider.dimensionId, x, y, z, 64));
            }
        }
    }
}
项目:uniquecrops    文件:EmblemTransformation.java   
@SubscribeEvent
public void onHitEntity(LivingHurtEvent event) {

    if (event.getAmount() <= 0 || event.getEntityLiving() instanceof EntityPlayer) return;

    if (!(event.getSource().getSourceOfDamage() instanceof EntityPlayer)) return;

    ItemStack transformer = BaublesApi.getBaublesHandler((EntityPlayer)event.getSource().getSourceOfDamage()).getStackInSlot(6);
    if (transformer == null || (transformer != null && transformer.getItem() != this)) return;

    Random rand = new Random();
    if (rand.nextInt(100) != 0) return;

    EntityLivingBase elb = event.getEntityLiving();
    List<String> entities = new ArrayList<String>(EntityList.ENTITY_EGGS.keySet());
    String randomString = entities.get(rand.nextInt(entities.size()));
    Entity entity = EntityList.createEntityByName(randomString, elb.worldObj);
    if (!entity.isNonBoss()) return;
    entity.setPositionAndRotation(elb.posX, elb.posY, elb.posZ, elb.rotationYaw, elb.rotationPitch);

    elb.worldObj.spawnEntityInWorld(entity);
    elb.setDead();
}
项目:AdvancedCombat    文件:ArmorHandler.java   
/** Handle wearing obsidian armor */
private boolean obsidianArmor(LivingHurtEvent e) {
    EntityLivingBase hurt = e.getEntityLiving();

    // do things based on the armor status
    int armorCount = getWearingSetCount(hurt, ItemArmorObsidian.class);
    if(armorCount > 0) {

        // blast resistance II
        if(e.getSource().isExplosion()) {
            e.setAmount(e.getAmount() * (1 - armorCount / 4F));
        }

        return true;
    }
    return false;
}
项目:Overlord    文件:CommonEvents.java   
@SubscribeEvent
public static void livingHurt(LivingHurtEvent event) {
    if (!event.getEntity().world.isRemote)
        if(event.getSource().getTrueSource() instanceof EntityArmyMember) {
            if (event.getEntityLiving() instanceof EntityPlayerMP) {
                if (event.getSource().isProjectile()) {
                    if (event.getSource().getTrueSource() instanceof EntitySkeletonWarrior && ((EntitySkeletonWarrior) event.getSource().getTrueSource()).getOwnerId().equals(event.getEntityLiving().getUniqueID()))
                        CriterionRegistry.instance.SKELETON_STATUS_UPDATE.trigger((EntityPlayerMP) event.getEntityLiving(), event.getSource().getTrueSource(), Items.ARROW, 0);
                    else if (event.getSource().getTrueSource() instanceof EntityConvertedSkeleton && ((EntityConvertedSkeleton) event.getSource().getTrueSource()).getOwnerId().equals(event.getEntityLiving().getUniqueID()))
                        CriterionRegistry.instance.SKELETON_STATUS_UPDATE.trigger((EntityPlayerMP) event.getEntityLiving(), event.getSource().getTrueSource(), Items.ARROW, 1);
                }
                if(ConfigValues.FF && Alliances.getInstance().isAlliedTo(((EntityArmyMember) event.getSource().getTrueSource()).getOwnerId(), event.getEntityLiving().getUniqueID()))
                    event.setCanceled(true);
            } else if(ConfigValues.FF && event.getEntityLiving() instanceof EntityArmyMember && Alliances.getInstance().isAlliedTo(((EntityArmyMember) event.getSource().getTrueSource()).getOwnerId(), ((EntityArmyMember)event.getEntityLiving()).getOwnerId()))
                event.setCanceled(true);
        } else if (ConfigValues.FF && event.getSource().getTrueSource() instanceof EntityPlayer) {
            if(event.getEntityLiving() instanceof EntityPlayer && Alliances.getInstance().isAlliedTo(event.getSource().getTrueSource().getUniqueID(), event.getEntityLiving().getUniqueID()))
                event.setCanceled(true);
            else if(event.getEntityLiving() instanceof EntityArmyMember && Alliances.getInstance().isAlliedTo(event.getSource().getTrueSource().getUniqueID(), ((EntityArmyMember)event.getEntityLiving()).getOwnerId()))
                event.setCanceled(true);
        }
}
项目:4Space-5    文件:EventHandlerGC.java   
@SubscribeEvent
public void onEntityDamaged(LivingHurtEvent event)
{
    if (event.source.damageType.equals(DamageSource.onFire.damageType))
    {
        if (OxygenUtil.noAtmosphericCombustion(event.entityLiving.worldObj.provider))
        {
            if (OxygenUtil.isAABBInBreathableAirBlock(event.entityLiving.worldObj, event.entityLiving.boundingBox))
                return;

            if (event.entityLiving.worldObj instanceof WorldServer)
            {
                ((WorldServer) event.entityLiving.worldObj).func_147487_a("smoke", event.entityLiving.posX, event.entityLiving.posY + event.entityLiving.boundingBox.maxY - event.entityLiving.boundingBox.minY, event.entityLiving.posZ, 50, 0.0, 0.05, 0.0, 0.001);
            }

            event.entityLiving.extinguish();
        }
    }
}
项目:MidgarCrusade    文件:ForgeEventHooksHandler.java   
@SubscribeEvent
public void reflecteffect(LivingHurtEvent lde,EntityPlayerMP sender)
  {
    if ((Main.allowPFeather) && ((lde.entityLiving instanceof EntityPlayer)))
    {
      EntityPlayer ep = (EntityPlayer)lde.entityLiving;
    if (((EntityLivingBase) ep).isPotionActive(ItemRegistry1.customPotion2))
      {
        if (!ep.worldObj.isRemote)
        {
             lde.setCanceled(true);

          ep.worldObj.playSoundAtEntity(ep, "fireworks.launch", 5.0F, 1.0F);
          ep.worldObj.playSoundAtEntity(ep, "assets.speedboost", 0.4F, 0.3F);
          ((EntityLivingBase) ep).removePotionEffect(ItemRegistry1.customPotion2.id);
        }


      }
    }
  }
项目:ToroQuest    文件:ItemReinforcedDiamondArmor.java   
@SubscribeEvent
public void postInit(LivingHurtEvent e) {

    DamageSource source = e.getSource();

    Iterable<ItemStack> armorStacks = e.getEntityLiving().getArmorInventoryList();

    // boolean hasHeavyArmor = false;
    float reduction = 0;

    for (ItemStack armorStack : armorStacks) {
        if (isHeavyArmor(armorStack)) {
            if (source.isProjectile() || source.isExplosion()) {
                reduction += 0.2;
            }
        }
    }

    if (reduction > 0) {
        float newDamage = (1 - reduction) * e.getAmount();
        System.out.println("Heavy armor reduction: [" + reduction + "] IN[" + e.getAmount() + "] OUT[" + newDamage + "]");
        e.setAmount(newDamage);
    }
}
项目:3DManeuverGear    文件:EntityLivingHandler.java   
@SubscribeEvent
@SuppressWarnings("unused")
public void onPlayerFall(LivingHurtEvent event) {
    if(!(event.getEntity() instanceof EntityPlayer)) {
        return;
    }
    if(!event.getSource().damageType.equals(DamageSource.FALL.getDamageType())) {
        return;
    }
    EntityPlayer player = (EntityPlayer) event.getEntity();
    ItemStack boots = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
    if(boots != null && boots.getItem() == ItemRegistry.getInstance().itemFallBoots) {
        event.setAmount((1.0F-ConfigurationHandler.getInstance().bootFallDamageReduction)*event.getAmount());
    }

}
项目:TeleToro    文件:Teletory.java   
@SubscribeEvent
public void fallOutOfTeletory(LivingHurtEvent ev) {
    if (ev.getEntity().getEntityWorld().isRemote || !(ev.getEntity() instanceof EntityPlayerMP)) {
        return;
    }

    if (ev.getSource() != DamageSource.OUT_OF_WORLD) {
        return;
    }

    EntityPlayerMP thePlayer = (EntityPlayerMP) ev.getEntity();

    if (thePlayer.dimension != Teletory.DIMID) {
        return;
    }
    ev.setCanceled(true);
    changeEntityDimension(thePlayer, TeleportorType.FALL);
}
项目:Inhuman-Resources    文件:EventHandler.java   
@SubscribeEvent
public void onEntityAttacked(LivingHurtEvent event)
{
    Entity sourceEntity = event.getSource().getTrueSource();
    if (sourceEntity instanceof EntityLivingBase)
    {
        EntityLivingBase target = event.getEntityLiving();
        if (target == null)
            return;
        EntityLivingBase attacker = (EntityLivingBase) sourceEntity;
        ItemStack weapon = attacker.getHeldItemMainhand();
        ItemStack offhand = attacker.getHeldItemOffhand();
        if (offhand != null && offhand.getItem() instanceof IUpgradable)
            ((IUpgradable) weapon.getItem()).onAttackEntity(event, attacker, target, weapon, offhand);
        if (weapon != null && weapon.getItem() instanceof IUpgradable)
            ((IUpgradable) weapon.getItem()).onAttackEntity(event, attacker, target, weapon, offhand);
    }
}
项目:Lost-Eclipse-Outdated    文件:EventFlameCloak.java   
@SubscribeEvent
public void hasFlameCloak(LivingHurtEvent event)
{
    if (event.getEntityLiving() instanceof EntityPlayer && event.getSource().getSourceOfDamage() instanceof EntityLivingBase)
    {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        EntityLivingBase attacker = (EntityLivingBase) event.getSource().getSourceOfDamage();

        if (player != null && attacker != null)
        {
            IFlameCloak flameCloak = player.getCapability(CapabilityFlameCloak.FLAME_CLOAK_CAP, null);

            if (flameCloak != null && flameCloak.hasFlameCloak())
            {
                attacker.setFire(5);
            }
        }
    }
}
项目:Event-Tweaks    文件:MobEventHandler.java   
@SubscribeEvent
public void hurtEvents(LivingHurtEvent e) {
    if (!e.getEntity().getEntityWorld().isRemote) {
        DamageSource source = e.getSource();
        Entity entity = e.getEntity();

        if (entity == null || entity.isDead) {
            return;
        }

        if (source == DamageSource.drown && entity.isWet() && entity instanceof EntityPlayer && ConfigurationFile.hardcoreAir) {
            ((EntityPlayer) entity).setHealth(0.0f);
        } else if (source == DamageSource.starve && entity instanceof EntityPlayer && ConfigurationFile.hardcoreHunger) {
            ((EntityPlayer) entity).setHealth(0.0f);
        } else if (source.getEntity() instanceof EntityPlayer && ConfigurationFile.mobsRevengeMode) {
            if (!(entity instanceof EntityPlayer) && entity instanceof EntityLiving) {
                ((EntityLiving) entity).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 100, 1));
            }
        }
    }
}
项目:Coding    文件:DragonPlayerEventHandler.java   
@SubscribeEvent
    public void onLivingHurtEvent(LivingHurtEvent event) {
        if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer && DragonPlayer.get((EntityPlayer) event.entity).isDragon()) {
            if (event.source.equals(DamageSource.lava) || event.source.equals(DamageSource.onFire) || event.source.equals(DamageSource.inFire)) {
                event.setCanceled(true);
//              LogHelper.info("DragonPlayerEventHandler: onLivingHurtEvent, no damage from lava!");
            }
            // Damage yourself (probably an explosion)
            else if (BALANCE.DRAGON_PLAYER_ABILITIES.RECEIVE_EXPLODING_FIREBALL_DAMAGE == false && event.source.isExplosion()) {
                event.setCanceled(true);
            }
            else if (ItemDragonEgg.hasAbility((EntityPlayer) event.entity, Abilities.NOBLOCKDAMAGE) && event.source.equals(DamageSource.inWall)) {
                event.setCanceled(true);
            }
            else if (event.source.equals(DamageSource.fall)) {
                event.setCanceled(true);
            }
            // Prevent damage from entities that are picked up (that ride the dragon)
            else if (event.entity.riddenByEntity != null) {
                event.setCanceled(true);                
            }
        }
    }
项目:Kingdom-Keys-Re-Coded    文件:DriveFormLimit.java   
@SubscribeEvent
public static void getXP(LivingHurtEvent event) {
       if (event.getSource().getImmediateSource() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getSource().getImmediateSource();

           PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
           DriveStateCapability.IDriveState DRIVE = player.getCapability(ModCapabilities.DRIVE_STATE, null);

           if(DRIVE.getActiveDriveName().equals(Strings.Form_Limit)) {
            DRIVE.setDriveExp(DRIVE.getActiveDriveName(), DRIVE.getDriveExp(DRIVE.getActiveDriveName())+1);

            int[] costs = DriveFormRegistry.get(DRIVE.getActiveDriveName()).getExpCosts();
            int actualLevel = DRIVE.getDriveLevel(DRIVE.getActiveDriveName());
            int actualExp = DRIVE.getDriveExp(DRIVE.getActiveDriveName());

            if(costs.length == 7 && actualLevel < 7) {
                if (actualExp >= costs[actualLevel]){
                    System.out.println("LEVEL UP");
                    DRIVE.setDriveLevel(DRIVE.getActiveDriveName(),actualLevel+1); 
                    DRIVE.displayLevelUpMessage(player, DRIVE.getActiveDriveName());
                }
            }
            PacketDispatcher.sendTo(new SyncDriveData(DRIVE), (EntityPlayerMP) player);
           }
       }
}
项目:Kingdom-Keys-Re-Coded    文件:DriveFormValor.java   
@SubscribeEvent
public static void getXP(LivingHurtEvent event) {
       if (event.getSource().getImmediateSource() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getSource().getImmediateSource();

           PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
           DriveStateCapability.IDriveState DRIVE = player.getCapability(ModCapabilities.DRIVE_STATE, null);

        if(DRIVE.getActiveDriveName().equals(Strings.Form_Valor)) {
            DRIVE.setDriveExp(DRIVE.getActiveDriveName(), DRIVE.getDriveExp(DRIVE.getActiveDriveName())+1);

            int[] costs = DriveFormRegistry.get(DRIVE.getActiveDriveName()).getExpCosts();
            int actualLevel = DRIVE.getDriveLevel(DRIVE.getActiveDriveName());
            int actualExp = DRIVE.getDriveExp(DRIVE.getActiveDriveName());

            if(costs.length == 7 && actualLevel < 7) {
                if (actualExp >= costs[actualLevel]){
                    System.out.println("LEVEL UP");
                    DRIVE.setDriveLevel(DRIVE.getActiveDriveName(),actualLevel+1); 
                    DRIVE.displayLevelUpMessage(player, DRIVE.getActiveDriveName());
                }
            }
            PacketDispatcher.sendTo(new SyncDriveData(DRIVE), (EntityPlayerMP) player);
        }
       }
}
项目:Cyclic    文件:ItemSoulstone.java   
@SubscribeEvent
public void onPlayerHurt(LivingHurtEvent event) {
  if (event.getEntityLiving().getHealth() - event.getAmount() <= 0 && event.getEntityLiving() instanceof EntityPlayer) {
    EntityPlayer p = (EntityPlayer) event.getEntityLiving();
    for (int i = 0; i < p.inventory.getSizeInventory(); ++i) {
      ItemStack s = p.inventory.getStackInSlot(i);
      if (s.getItem() instanceof ItemSoulstone) {
        UtilChat.addChatMessage(p, event.getEntityLiving().getName() + UtilChat.lang("item.soulstone.used"));
        p.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
        UtilSound.playSound(p, SoundEvents.BLOCK_GLASS_BREAK);
        p.setHealth(6);// 3 hearts
        int time = Const.TICKS_PER_SEC * 30;
        p.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, time));
        time = Const.TICKS_PER_SEC * 60;//a full minute
        p.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, time));
        p.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, time, 4));
        //and bad luck lasts much longer
        time = Const.TICKS_PER_SEC * 60 * 10;
        p.addPotionEffect(new PotionEffect(MobEffects.UNLUCK, time));
        p.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, time, 1));
        event.setCanceled(true);
        break;
      }
    }
  }
}
项目:ComponentEquipment    文件:ArmorProtectionApplier.java   
@SubscribeEvent
public void onLivingHurt( LivingHurtEvent event )
{
    if ( event.source.isUnblockable() )
    {
        return;
    }

    /*
    event.entityLiving.damageArmor( event.ammount );

    int prot = Armor.getProtectionOf( event.entityLiving );
    int num = ( event.ammount * prot ) + event.entityLiving.carryoverDamage;
    */
    //for(int i=0;i<5;++i)System.out.println("");
}
项目:ComponentEquipment    文件:KnockbackEventHandler.java   
@SubscribeEvent
public void onEntityHurt( LivingHurtEvent event )
{
    EntityLivingBase entity = event.entityLiving;
    double resist = entity.getEntityAttribute( SharedMonsterAttributes.knockbackResistance ).getAttributeValue();
    /*
    for ( int i = 0; i < 5; ++i )
    {
        ItemStack stack = entity.getCurrentItemOrArmor( i );
        if ( stack == null )
        {
            continue;
        }

        stack.getAttributeModifiers();
    }
    */

    for ( Object o : entity.getAttributeMap().getAllAttributes() )
    {
        IAttributeInstance attr = (IAttributeInstance)o;
        // TODO: Reduce momentum instead of random avoidance
    }
    //entity.setVelocity( entity.motionX * resist, entity.motionY, entity.motionZ * resist );
}
项目:Et-Futurum    文件:ServerEventHandler.java   
@SubscribeEvent
public void entityHurtEvent(LivingHurtEvent event) {
    if (!EtFuturum.enableDmgIndicator)
        return;
    int amount = MathHelper.floor_float(Math.min(event.entityLiving.getHealth(), event.ammount) / 2F);
    if (amount <= 0)
        return;

    // If the attacker is a player spawn the hearts aligned and facing it
    if (event.source instanceof EntityDamageSource) {
        EntityDamageSource src = (EntityDamageSource) event.source;
        Entity attacker = src.getSourceOfDamage();
        if (attacker instanceof EntityPlayer && !(attacker instanceof FakePlayer)) {
            EntityPlayer player = (EntityPlayer) attacker;
            Vec3 look = player.getLookVec();
            look.rotateAroundY((float) Math.PI / 2);
            for (int i = 0; i < amount; i++) {
                double x = event.entityLiving.posX - amount * 0.35 * look.xCoord / 2 + i * 0.35 * look.xCoord;
                double y = event.entityLiving.posY + 1.5 + event.entityLiving.worldObj.rand.nextGaussian() * 0.05;
                double z = event.entityLiving.posZ - amount * 0.35 * look.zCoord / 2 + i * 0.35 * look.zCoord;
                EtFuturum.networkWrapper.sendToAllAround(new BlackHeartParticlesMessage(x, y, z), new TargetPoint(player.worldObj.provider.dimensionId, x, y, z, 64));
            }
        }
    }
}
项目:grapplemod    文件:LongFallBoots.java   
@SubscribeEvent
public void onLivingHurtEvent(LivingHurtEvent event) {
    if (event.getEntity() != null && event.getEntity() instanceof EntityPlayer)
    {
        EntityPlayer player = (EntityPlayer)event.getEntity();

        for (ItemStack armor : player.getArmorInventoryList()) {
            if (armor != null && armor.getItem() instanceof LongFallBoots)
            {
                if (event.getSource() == DamageSource.FLY_INTO_WALL) {
                    System.out.println("Flew into wall");
                    // this cancels the fall event so you take no damage
                    event.setCanceled(true);
                }
            }
        }
    }
}
项目:Minecraft-Modding    文件:ArmorHandler.java   
@SubscribeEvent
public void shieldAbsorbDamage(LivingHurtEvent event)
{
    if (!event.source.isUnblockable())
    {
        ScienceShield shield = ScienceShield.loadShieldForEntity(event.entityLiving);
        float dmgRemaining = shield.tryAbsorbDamage(event.ammount);
        if (dmgRemaining <= 0) {
            event.setCanceled(true);
        }
        else {
            event.ammount = dmgRemaining;
        }
        shield.save();
    }
}
项目:Gadomancy    文件:EventHandlerGolem.java   
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(LivingHurtEvent event) {
    if (!event.entity.worldObj.isRemote) {
        if(event.entity instanceof EntityGolemBase) {
            EntityGolemBase golem = (EntityGolemBase) event.entity;
            if(event.ammount > 0 && RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(golem)) {
                event.ammount = RegisteredGolemStuff.upgradeRunicShield.absorb(golem, event.ammount, event.source);
            }
        }

        /*if(event.source.getEntity() != null && event.source.getEntity() instanceof EntityGolemBase
                && ((EntityGolemBase) event.source.getEntity()).getGolemType()
                    == RegisteredGolemStuff.typeObsidian.getEnumEntry()) {
            event.entityLiving.addPotionEffect(new PotionEffect(Potion.wither.getId(), 3*20, 1));
        }*/
    }
}
项目:sprinkles_for_vanilla    文件:PlayerHandlers.java   
@SubscribeEvent
public void onHurt(LivingHurtEvent event)
{
    if (event.entity instanceof EntityPlayer && SprinklesForVanilla.isOnServer)
    {
        EntityPlayer player = (EntityPlayer) event.entity;
        if (player.getHealth() - event.ammount <= 0)
        {
            PlayerProperties props = (PlayerProperties) player.getExtendedProperties(ModInfo.MOD_NAME);
            props.health = player.getHealth();
            props.hunger = player.getFoodStats().getFoodLevel();
            props.experience = player.experience;
            props.experienceLevel = player.experienceLevel;
            props.experienceTotal = player.experienceTotal;
            playerMap.put(player.getPersistentID(), props);
        }
    }
}
项目:sprinkles_for_vanilla    文件:EntityHandlers.java   
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event)
{
    DamageSource source = event.source;
    if (source.damageType == "player" && SprinklesForVanilla.isOnServer && event.ammount > 0)
    {
        EntityPlayer player = (EntityPlayer)((EntityDamageSource)source).getEntity();
        if (player != null)
        {
            ItemStack heldItem = player.getCurrentEquippedItem();
            if (heldItem != null)
            {
                Multimap attribMap = heldItem.getAttributeModifiers();
                //If held item doesn't change the base damage
                if (!attribMap.containsKey(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()))
                {
                    event.ammount *= Settings.playerPunchDamageMultiplier[1];
                }
            }
            else
            {
                event.ammount *= Settings.playerPunchDamageMultiplier[1];
            }
        }
    }
}
项目:Blockbender    文件:PassiveListener.java   
@SubscribeEvent
public void onEntityDamage(LivingHurtEvent event) {
    /* Less fire damage */
    if (event.entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.entity;
        if (ElementManager.hasElement(player, ElementManager.FIRE)) {
            if (event.source == DamageSource.inFire || event.source == DamageSource.onFire) {
                if (player.getRNG().nextInt(3) == 0) {
                    event.ammount = 1;
                }
                else {
                    event.ammount = 0;
                }
            }
        }
    }
}
项目:GaiaMod    文件:GaiaModEventHandler.java   
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event) {
    EntityLivingBase attackedEntity = event.entityLiving;
    Entity attackerEntity = event.source.getEntity();

    if (event.source.getSourceOfDamage() instanceof EntityArrow
            && ((hasEquippedSet(attackerEntity, ModArmor.stormHelmet,
                    ModArmor.stormChest, ModArmor.stormLeggings,
                    ModArmor.stormBoots))
                    || (hasEquippedSet(attackerEntity,
                            ModArmor.chaosHelmet, ModArmor.chaosChest,
                            ModArmor.chaosLeggings, ModArmor.chaosBoots)) || (hasEquippedSet(
                        attackerEntity, ModArmor.orderHelmet,
                        ModArmor.orderChest, ModArmor.orderLeggings,
                        ModArmor.orderBoots)))) {
        double i = attackedEntity.posX;
        double j = attackedEntity.posY;
        double k = attackedEntity.posZ;

        EntityLightningBolt entityLightningBolt = new EntityLightningBolt(
                attackerEntity.worldObj, i, j, k);
        attackerEntity.worldObj.addWeatherEffect(entityLightningBolt);
    }
}
项目:ZeldaSwordSkills    文件:ZSSCombatEvents.java   
/**
 * Pre-event to handle shield blocking (only posted when not in BG2 battle mode)
 */
@SubscribeEvent(priority=EventPriority.NORMAL)
public void onPreHurt(LivingHurtEvent event) {
    if (event.entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.entity;
        ItemStack stack = player.getHeldItem();
        if (stack != null && stack.getItem() instanceof ItemZeldaShield && player.isUsingItem()) {
            ItemZeldaShield shield = (ItemZeldaShield) stack.getItem();
            if (ZSSPlayerInfo.get(player).canBlock() && shield.canBlockDamage(stack, event.source)) {
                Entity opponent = event.source.getEntity();
                if (opponent != null && TargetUtils.isTargetInFrontOf(opponent, player, 60)) {
                    event.ammount = shield.onBlock(player, stack, event.source, event.ammount);
                    event.setCanceled(event.ammount < 0.1F);
                }
            }
        }
    }
}
项目:ZeldaSwordSkills    文件:SwordBasic.java   
@Override
public void onHurtTarget(EntityPlayer player, LivingHurtEvent event) {
    if (!isLockedOn() || !isValidComboDamage(player, event.source)) { return; }
    if (combo == null || combo.isFinished()) {
        combo = new Combo(player, this, getMaxComboSize(), getComboTimeLimit());
    }
    float damage = DirtyEntityAccessor.getModifiedDamage(event.entityLiving, event.source, event.ammount);
    if (damage > 0) {
        if (!(event.source instanceof IComboDamageFull) || ((IComboDamageFull) event.source).increaseComboCount(player)) {
            combo.add(player, event.entityLiving, damage);
        } else {
            combo.addDamageOnly(player, damage, ((IComboDamageFull) event.source).applyDamageToPrevious(player));
        }
    }
    String sound = getComboDamageSound(player, event.source);
    if (sound != null) {
        WorldUtils.playSoundAtEntity(player, sound, 0.4F, 0.5F);
    }
}
项目:ModTutoriel17    文件:LivingEventHandler.java   
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event)
{
    ItemStack boots = event.entityLiving.getEquipmentInSlot(1);
    ItemStack leggings = event.entityLiving.getEquipmentInSlot(2);
    ItemStack chestPlate = event.entityLiving.getEquipmentInSlot(3);
    ItemStack helmet = event.entityLiving.getEquipmentInSlot(4);

    if(boots != null && boots.getItem() == ModTutoriel.bootsTuto && leggings != null && leggings.getItem() == ModTutoriel.leggingsTuto && chestPlate != null && chestPlate.getItem() == ModTutoriel.chestPlateTuto && helmet != null && helmet.getItem() == ModTutoriel.helmetTuto)
    {
        if(event.source.getEntity() != null && event.source.getEntity() instanceof EntityCreeper)
        {
            boots.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            leggings.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            chestPlate.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            helmet.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            event.ammount = 0F;
        }
        else if(event.source.getDamageType().equals("cactus"))
        {
            event.entityLiving.worldObj.newExplosion(event.entityLiving, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, event.ammount, true, true);
        }
    }
}
项目:GriefGuardian    文件:ClaimGuardEventHandler.java   
@SubscribeEvent
public void onEntityHurt(LivingHurtEvent event){
    if (event.entity.worldObj.isRemote)
        return;

    EntityPlayer player = null;
    if (event.source.getSourceOfDamage() != null && event.source.getSourceOfDamage() instanceof EntityPlayer){
        player = (EntityPlayer)event.source.getSourceOfDamage();
    }
    if (player == null)
        return;

    if (event.entity instanceof EntityPlayer)
        if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(player, PermissionsMutex.HARM_PLAYERS, event.entity.posX, event.entity.posY, event.entity.posZ))
            event.setCanceled(true);

    if (event.entity instanceof EntityCreature)
        if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(player, PermissionsMutex.HARM_CREATURES, event.entity.posX, event.entity.posY, event.entity.posZ))
            event.setCanceled(true);

    if (event.entity instanceof EntityMob)
        if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(player, PermissionsMutex.HARM_MONSTERS, event.entity.posX, event.entity.posY, event.entity.posZ))
            event.setCanceled(true);
}
项目:Morph    文件:EventHandler.java   
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event)
{
    if(event.source.getEntity() instanceof EntityPlayerMP && !(event.source instanceof EntityDamageSourceIndirect))
    {
        EntityPlayer player = (EntityPlayer)event.source.getEntity();
        MorphInfo info = Morph.proxy.tickHandlerServer.getPlayerMorphInfo(player);

        if(info != null && player.getCurrentEquippedItem() == null)
        {
            for(Ability ab : info.morphAbilities)
            {
                if(ab instanceof AbilityPotionEffect)
                {
                    AbilityPotionEffect abPot = (AbilityPotionEffect)ab;
                    event.entityLiving.addPotionEffect(new PotionEffect(abPot.potionId, abPot.duration, abPot.amplifier, abPot.ambient));
                }
            }
        }
    }
}
项目:Artifacts    文件:ComponentAdrenaline.java   
@Override
public void onTakeDamage(ItemStack itemStack, LivingHurtEvent event, boolean isWornArmor) {
    //System.out.println("Player has been damaged!");
    if(isWornArmor && !event.isCanceled()) {
        if(itemStack.stackTagCompound.getInteger("adrenDelay_armor") <= 0 && event.entity instanceof EntityPlayer) {
            //System.out.println("Attempting to apply potion effects to player.");
            EntityPlayer p = (EntityPlayer)event.entity;
            //if(p.getHealth() <= 4) {
                //System.out.println("Applying Potion Effects.");
                itemStack.stackTagCompound.setInteger("adrenDelay_armor", 300);

                p.addPotionEffect(new PotionEffect(1, 100, 1));
                p.addPotionEffect(new PotionEffect(5, 100, 1));
                p.addPotionEffect(new PotionEffect(11, 100, 2));

            //}
        }
    }
}
项目:Bewitchment    文件:ItemSilverArmor.java   
@SubscribeEvent
public void onEntityDamage(LivingHurtEvent event) {
    DamageSource source = event.getSource();

    Entity attacker = source.getTrueSource();
    if ((attacker instanceof EntityLivingBase) && ((EntityLivingBase) attacker).getCreatureAttribute() == EnumCreatureAttribute.UNDEAD) {
        event.setAmount(event.getAmount() * 0.95F);
    }
}
项目:Bewitchment    文件:ShellArmorBrew.java   
@Override
public void onHurt(LivingHurtEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
    Entity attacker = source.getImmediateSource();
    int redo = 5 - amplifier;
    if (attacker != null && (redo < 0 || attacker.world.rand.nextInt(redo) == 0)) {
        float damage = event.getAmount();
        attacker.attackEntityFrom(DamageSource.causeThornsDamage(affected), damage);
    }
}
项目:Bewitchment    文件:OvercoatBrew.java   
@Override
public void onHurt(LivingHurtEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
    Entity attacker = source.getImmediateSource();
    if (attacker != null) {
        event.setCanceled(true);
    }
}