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

项目:Loot-Slash-Conquer    文件:EventLivingHurtAttack.java   
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onLivingAttack(LivingAttackEvent event)
{
    /*
     * Player attacks a monster OR another player
     */
    if (event.getSource().getTrueSource() instanceof EntityPlayer && !event.getSource().getTrueSource().getEntityWorld().isRemote)
    {
        EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
        EntityLivingBase enemy = event.getEntityLiving();
        ItemStack stack = player.inventory.getCurrentItem();
        PlayerInformation playerInfo = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null);

        if (playerInfo != null && stack != null && stack.getItem() instanceof ItemSword && !(stack.getItem() instanceof ItemLEAdvancedMelee))
        {
            NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);

            if (playerInfo.getPlayerLevel() >= nbt.getInteger("Level"))
            {
                useWeaponAttributes(event.getAmount(), player, enemy, stack, nbt);
            }
        }
    }
}
项目:Bewitchment    文件:VolatileBrew.java   
@Override
public void onAttack(LivingAttackEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
    if (amplifier >= 3) {
        if (!source.isExplosion()) {
            BrewStorageHandler.removeActiveBrew(affected, this);
            affected.world.createExplosion(source.getImmediateSource(), affected.posX, affected.posY + 1.2D, affected.posZ, amplifier + 3, true);

        }
    }

    if (amplifier == 2) {
        if (!source.isExplosion()) {
            BrewStorageHandler.removeActiveBrew(affected, this);
            affected.world.createExplosion(source.getImmediateSource(), affected.posX, affected.posY + 0.7D, affected.posZ, amplifier + 2, true);

        }
    }
    if (!source.isExplosion()) {
        BrewStorageHandler.removeActiveBrew(affected, this);
        affected.world.createExplosion(source.getImmediateSource(), affected.posX, affected.posY + 0.5D, affected.posZ, amplifier + 1, true);
    }
}
项目:Mods    文件:TF2EventsCommon.java   
@SubscribeEvent
public void stopHurt(LivingAttackEvent event) {
    if (event.getSource().getTrueSource() != null && event.getSource().getTrueSource() instanceof EntityLivingBase &&
            (event.getSource().damageType.equals("mob") || event.getSource().damageType.equals("player"))) {
        EntityLivingBase damageSource = (EntityLivingBase) event.getSource().getTrueSource();
        if (!TF2Util.canInteract(damageSource)) {
            event.setCanceled(true);
        }
        if (damageSource.hasCapability(TF2weapons.WEAPONS_CAP, null) && WeaponsCapability.get(damageSource).isDisguised()) {
            disguise(damageSource, false);
        }
    }

    if (!event.isCanceled() && event.getAmount() > 0) {
        /*
         * if(event.getEntity().getEntityData().getByte("IsCloaked")!=0){
         * event.getEntity().getEntityData().setInteger("VisTicks",
         * Math.min(10,event.getEntity().getEntityData().getInteger(
         * "VisTicks"))); event.getEntity().setInvisible(false);
         * //System.out.println("notInvisible"); }
         */
        event.getEntityLiving().getEntityData().setInteger("lasthit", event.getEntityLiving().ticksExisted);
    }

}
项目:metamorph    文件:MorphHandler.java   
/**
 * When player is morphed, he can deal an damage or effect onto the enemy. 
 * 
 * For example, if player is morphed into the wither skeleton, he also 
 * grants a target wither potion effect. Pretty realistic, however I don't 
 * really know what that does. 
 */
@SubscribeEvent
public void onPlayerAttack(LivingAttackEvent event)
{
    Entity source = event.getSource().getEntity();
    Entity target = event.getEntity();

    if (source instanceof EntityPlayer)
    {
        EntityPlayer player = (EntityPlayer) source;
        IMorphing capability = Morphing.get(player);

        if (capability == null || !capability.isMorphed())
        {
            return;
        }

        capability.getCurrentMorph().attack(target, player);
    }
}
项目:malmo    文件:RewardForDamagingEntityImplementation.java   
@SubscribeEvent
public void onLivingAttackEvent(LivingAttackEvent event)
{
    if (event.getEntity() == null || event.getSource().getEntity() != Minecraft.getMinecraft().player)
        return;
    synchronized (this.damages)
    {
        for (MobWithReward mob : this.params.getMob())
        {
            // Have we caught one of these mobs?
            for (EntityTypes et : mob.getType())
            {
                String mobName = et.value();
                if (event.getEntity().getName().equals(mobName))
                {
                    if (this.damages.containsKey(mob))
                        this.damages.put(mob, this.damages.get(mob) + event.getAmount());
                    else
                        this.damages.put(mob, event.getAmount());
                }
            }
        }
    }
}
项目:Inhuman-Resources    文件:PotionRedstoneNeedle.java   
@SubscribeEvent
public void onLivingHurt(LivingAttackEvent event)
{
    if (event.getSource() == null)
        return;
    if (event.getSource().getTrueSource() == null)
        return;
    if (event.getSource().getTrueSource() instanceof EntityLivingBase)
    {
        PotionEffect effect = ((EntityLivingBase) event.getSource().getTrueSource()).getActivePotionEffect(PotionRegistry.REDSTONE_NEEDLE);
        if (effect == null)
            return;
        if (effect.getAmplifier() >= 4)
            event.setCanceled(true);
    }
}
项目:Alchemy    文件:ItemBeltGuard.java   
@SubscribeEvent(priority = EventPriority.BOTTOM)
public void onLivingAttackCallback(LivingAttackEvent event) {
    if (Always.isServer()) {
        EntityLivingBase living = event.getEntityLiving(), attacker = event.getSource().getTrueSource() instanceof EntityLivingBase ?
                (EntityLivingBase) event.getSource().getTrueSource() : null;
        if (isEquipmented(living) && !(living instanceof EntityPlayer && ((EntityPlayer) living).isCreative())) {
            living.getCombatTracker().lastDamageTime = living.ticksExisted;
            if (living instanceof EntityPlayerMP && !(living instanceof FakePlayer))
                AlchemyNetworkHandler.network_wrapper.sendTo(new MessageGuardCallback(-1), (EntityPlayerMP) living);
        }
        if (attacker != null && isEquipmented(attacker)) {
            attacker.setLastAttackedEntity(living);
            if (living instanceof EntityPlayerMP && !(living instanceof FakePlayer))
                AlchemyNetworkHandler.network_wrapper.sendTo(new MessageGuardCallback(living.getEntityId()), (EntityPlayerMP) attacker);
        }
    }
}
项目:MMDLib-old    文件:ForgeEventHandler.java   
@SubscribeEvent
public void attackEvent (LivingAttackEvent e) {
    if (e.getEntityLiving().getActiveItemStack() == null)
        return;
    final ItemStack stack = e.getEntityLiving().getActiveItemStack();
    if (stack.getItem() instanceof ItemCustomShield && e.getAmount() > 0.0f) {
        final int i = 1 + MathHelper.floor(e.getAmount());
        stack.damageItem(i, e.getEntityLiving());
        if (stack.stackSize <= 0) {
            final EnumHand enumhand = e.getEntityLiving().getActiveHand();
            if (e.getEntityLiving() instanceof EntityPlayer)
                ForgeEventFactory.onPlayerDestroyItem((EntityPlayer) e.getEntityLiving(), stack, enumhand);
            e.getEntityLiving().setItemStackToSlot(enumhand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND, null);
            if (e.getEntityLiving().getEntityWorld().isRemote)
                e.getEntityLiving().playSound(SoundEvents.BLOCK_ANVIL_BREAK, 0.8F, 0.8F + e.getEntityLiving().getEntityWorld().rand.nextFloat() * 0.4F);
        }
    }
}
项目:Gravitation-Suite-Reloaded    文件:ItemElectricArmor.java   
@SubscribeEvent
public void onPlayerHurt(LivingAttackEvent event) {
    if(FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        return;
    }

    if(!(event.entity instanceof EntityPlayer)) {
        return;
    }

    EntityPlayer player = (EntityPlayer)event.entity;
    ItemStack itemstack = player.inventory.armorItemInSlot(2);
    if(itemstack == null || event.source.equals(DamageSource.outOfWorld)) {
        event.setCanceled(false);
        return;
    }
    if(ElectricItem.manager.canUse(itemstack, 1000.0D)) {
        event.setCanceled(true);
    }
}
项目:Wars-Mod    文件:CommonEvents.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent evt) {
    if (evt.getEntity() instanceof EntityPlayer && evt.getSource() instanceof EntityDamageSource) {
        EntityDamageSource source = (EntityDamageSource) evt.getSource();
        if (source.getEntity() instanceof EntityPlayer) {
            EntityPlayer attacker = (EntityPlayer) source.getEntity();
            EntityPlayer damagee = (EntityPlayer) evt.getEntity();

            ItemStack attackerBoots = attacker.inventory.armorItemInSlot(0);
            ItemStack damageeBoots = damagee.inventory.armorItemInSlot(0);
            if (attackerBoots != null && damageeBoots != null && attackerBoots == damageeBoots) {
                Item id = damageeBoots.getItem();
                if (id == WarsItems.redBoots || id == WarsItems.greenBoots || id == WarsItems.blueBoots || id == WarsItems.yellowBoots) {
                    evt.setCanceled(true);
                }
            }
        }
    }
}
项目:vsminecraft    文件:ItemGasMask.java   
@SubscribeEvent
public void onEntityAttacked(LivingAttackEvent event)
{
    EntityLivingBase base = event.entityLiving;

    if(base.getEquipmentInSlot(4) != null && base.getEquipmentInSlot(4).getItem() instanceof ItemGasMask)
    {
        ItemGasMask mask = (ItemGasMask)base.getEquipmentInSlot(4).getItem();

        if(base.getEquipmentInSlot(3) != null && base.getEquipmentInSlot(3).getItem() instanceof ItemScubaTank)
        {
            ItemScubaTank tank = (ItemScubaTank)base.getEquipmentInSlot(3).getItem();

            if(tank.getFlowing(base.getEquipmentInSlot(3)) && tank.getGas(base.getEquipmentInSlot(3)) != null)
            {
                if(event.source == DamageSource.magic)
                {
                    event.setCanceled(true);
                }
            }
        }
    }
}
项目:vsminecraft    文件:ItemFreeRunners.java   
@SubscribeEvent
public void onEntityAttacked(LivingAttackEvent event)
{
    EntityLivingBase base = event.entityLiving;

    if(base.getEquipmentInSlot(1) != null && base.getEquipmentInSlot(1).getItem() instanceof ItemFreeRunners)
    {
        ItemStack stack = base.getEquipmentInSlot(1);
        ItemFreeRunners boots = (ItemFreeRunners)stack.getItem();

        if(boots.getEnergy(stack) > 0 && event.source == DamageSource.fall)
        {
            boots.setEnergy(stack, boots.getEnergy(stack)-event.ammount*50);
            event.setCanceled(true);
        }
    }
}
项目:NincraftLib    文件:DamageModifierHandler.java   
@SubscribeEvent
public void attackedEntity(LivingAttackEvent event) {
    if (event.getSource().getEntity() instanceof EntityPlayerMP && event.getSource().damageType.equals("player")
            && Settings.Silly.moonPhasesOPPlzNerf) {
        EntityPlayerMP player = (EntityPlayerMP) event.getSource().getEntity();
        if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof IMoonDamage
                && event.getEntityLiving().getHealth() > 0) {
            event.setCanceled(true);
            if (!player.worldObj.isRemote) {
                event.getEntity().attackEntityFrom(new MoonModifierDamageSource("moonModifier", player),
                        getMoonDamage(player.worldObj.getCurrentMoonPhaseFactor(), event.getAmount()));
                int itemDamage = player.getHeldItemMainhand().getItemDamage() + 1;
                player.getHeldItemMainhand().getItem().setDamage(player.getHeldItemMainhand(), itemDamage);
            }
        }
    }
}
项目:Nincrafty-Things    文件:ArmorSetBonusHandler.java   
@SubscribeEvent
public void entityAttacked(LivingAttackEvent event) {
    if (event.source.getEntity() instanceof EntityPlayerMP) {
        EntityPlayerMP player = (EntityPlayerMP) event.source.getEntity();
        if (!player.isEntityEqual(event.entity) && isWearingNincodiumArmorSet(player)
                && isHealingChanceSuccessful(player)) {
            EntityPlayerMP closestPlayer = getClosestPlayerToEntityWithLeastHealth(player,
                    Settings.Armor.nincodiumArmorHealingRadius);

            if (closestPlayer != null && event.entityLiving.getHealth() > 0
                    && closestPlayer.getHealth() < closestPlayer.getMaxHealth()) {
                float healed = event.ammount * Settings.Armor.nincodiumArmorHealingPercentage;
                closestPlayer.setHealth(closestPlayer.getHealth() + (healed));
                if (!closestPlayer.worldObj.isRemote) {
                    closestPlayer.worldObj.playSoundEffect(closestPlayer.posX, closestPlayer.posY,
                            closestPlayer.posZ, Names.Sounds.HEALING, 1, 2);
                }
            }
        }
    }
}
项目:MineFantasy    文件:EventManagerMF.java   
@ForgeSubscribe
public void onAttack(LivingAttackEvent event)
{
    Entity source = event.source.getSourceOfDamage();

    if(source != null && source instanceof EntityLiving && !event.source.isProjectile())
    {
        EntityLiving attacker = (EntityLiving)source;

        PotionEffect affliction = attacker.getActivePotionEffect(Potion.confusion);

        if(affliction != null)
        {
            Random rand = attacker.getRNG();
            int tier = affliction.getAmplifier();

            if(rand.nextInt(5) <= tier)
            {
                event.setCanceled(true);
            }
        }
    }
}
项目:sprinkles_for_vanilla    文件:EntityHandlers.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event)
{
    if (stoppedDamageSources.keySet().contains(event.source.damageType) && SprinklesForVanilla.isOnServer)
    {
        int value = stoppedDamageSources.get(event.source.damageType);
        switch(value)
        {
            case 1:
                if (!(event.entity instanceof EntityPlayer))
                    break;
            case 2:
                event.setCanceled(true);
                break;
            default:
                LogHelper.warn("Found incorrect value in stoppedDamageSources: " + event.source.damageType + ", " + value);
                break;
        }
    }
}
项目:FlowstoneEnergy    文件:EnchantRandTeleHandler.java   
@SubscribeEvent
public void RandomTeleport(LivingAttackEvent event) {
    if (event.source.getEntity() instanceof EntityPlayer) {
        EntityPlayer attacker = (EntityPlayer) event.source.getEntity();
        Entity defender = event.entity;
        World world = event.entity.worldObj;
        if (world.isRemote)
            return;
        if (event.source.getEntity() == null)
            return;
        if (!(event.source.getEntity() instanceof EntityPlayer))
            return;
        if (attacker.getHeldItem() == null)
            return;
        if (!attacker.getHeldItem().isItemEnchanted())
            ;
        if (!(EnchantmentHelper.getEnchantments(attacker.getHeldItem()).containsKey(EnchantRegistry.randTeleEnchant.effectId)))
            return;
        teleport(world, defender);
    }
}
项目:ShadowsOfPhysis    文件:ArtifactEventHandler.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event) {
    if (event.entity.worldObj.isRemote) { return; }

    Entity damagesource = event.source.getSourceOfDamage();
    EntityLivingBase damager = null;
    if (damagesource instanceof EntityLivingBase) {
        damager = (EntityLivingBase)damagesource;
    }

    if (damager != null) {
        if (damager instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer)damager;

            if (player.getHeldItem() != null) {
                doTriggerOnDealDamage(player.getHeldItem(), event.entityLiving, player);
            }
        } else {
            ItemStack stack = damager.getEquipmentInSlot(0);
            if (stack != null) {
                doTriggerOnDealDamage(stack, event.entityLiving, damager);
            }
        }
    }
}
项目:GaiaMod    文件:GaiaModEventHandler.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event) {
    EntityLivingBase entityLiving = event.entityLiving;

    if ((event.source != null && event.source == DamageSource.lava
            || event.source == DamageSource.inFire || event.source == DamageSource.onFire)
            && (hasEquippedSet(entityLiving, ModArmor.fireHelmet,
                    ModArmor.fireChest, ModArmor.fireLeggings,
                    ModArmor.fireBoots)
                    || hasEquippedSet(entityLiving, ModArmor.chaosHelmet,
                            ModArmor.chaosChest, ModArmor.chaosLeggings,
                            ModArmor.chaosBoots) || hasEquippedSet(
                        entityLiving, ModArmor.orderHelmet,
                        ModArmor.orderChest, ModArmor.orderLeggings,
                        ModArmor.orderBoots))) {
        event.setCanceled(true);
        entityLiving.extinguish();
    }
}
项目:HardModeTweaks    文件:MobsTweaksManager.java   
@SubscribeEvent
public void onLivingAttackEvent(LivingAttackEvent event) {
    if (spidersApplySlowness) {
        if (event.getSource().getDamageType().equals("mob")
                && event.getSource().getEntity() instanceof EntitySpider) {
            event.getEntityLiving()
                    .addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 200, 1));
        }
    }

    if (replaceCaveSpiderPoison) {
        if (event.getSource().getDamageType().equals("mob")
                && event.getSource().getEntity() instanceof EntityCaveSpider) {
            poisonedEntities.add(event.getEntityLiving());
        }
    }
}
项目:ProgressiveDifficulty    文件:EventHandler.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event){
    if(DifficultyManager.enabled) {
        Entity causeMob = event.getSource().getTrueSource();
        if (causeMob instanceof EntityLiving
                && event.getEntity() instanceof EntityPlayer
                && MobNBTHandler.isModifiedMob((EntityLiving) causeMob)) {
            Map<String, Integer> changes = MobNBTHandler.getChangeMap((EntityLiving) causeMob);
            String regionName = MobNBTHandler.getEntityRegion((EntityLiving) causeMob);
            Region mobRegion = DifficultyManager.getRegionByName(regionName);
            String mobId = EntityList.getEntityString(causeMob);
            for (String change : changes.keySet()) {
                try {
                    DifficultyModifier modifier = mobRegion.getModifierForMobById(mobId, change);
                    if (modifier != null) {
                        modifier.handleDamageEvent(event);
                    }
                } catch (Exception e) {
                    LOG.warn("Error applying modifier at onLivingAttack.  Mob was " + causeMob.getName() + ", Modifier was " + change + ".  Please report to Progressive Difficulty Developer!");
                    LOG.warn("\tCaught Exception had message " + e.getMessage());
                }
            }
        } else if (event.getSource().getImmediateSource() instanceof PotionCloudModifier.PlayerEffectingOnlyEntityAreaEffectCloud
                && !(event.getEntity() instanceof EntityPlayer)) {
            event.setCanceled(true);
        }
    }
}
项目:ProgressiveDifficulty    文件:OnHitEffectModifier.java   
@Override
public void handleDamageEvent(LivingAttackEvent event) {
    super.handleDamageEvent(event);
    if(!(event.getEntity() instanceof EntityLivingBase))
        return;
    EntityLivingBase hitEntity = (EntityLivingBase)event.getEntity();
    EntityLiving cause = (EntityLiving)event.getSource().getTrueSource();
    int level = MobNBTHandler.getModifierLevel(cause,identifier);
    hitEntity.addPotionEffect(new PotionEffect(effect, duration,level,false,false));
}
项目:ProgressiveDifficulty    文件:VampiricModifier.java   
@Override
public void handleDamageEvent(LivingAttackEvent event){
    EntityLiving attackingMob = (EntityLiving)event.getSource().getTrueSource();
    int level = MobNBTHandler.getModifierLevel(attackingMob,IDENTIFIER);
    float damage = event.getAmount();
    float healDamage = damage * 0.2f * level;
    attackingMob.heal(healDamage);
}
项目:connor41-etfuturum2    文件:ServerEventHandler.java   
@SubscribeEvent
public void livingAttack(LivingAttackEvent event) {
    if (event.source instanceof EntityDamageSourceIndirect) {
        EntityDamageSourceIndirect dmgSrc = (EntityDamageSourceIndirect) event.source;
        if (dmgSrc.getSourceOfDamage() instanceof EntityTippedArrow) {
            EntityTippedArrow tippedArrow = (EntityTippedArrow) dmgSrc.getSourceOfDamage();
            if (!tippedArrow.worldObj.isRemote)
                event.entityLiving.addPotionEffect(tippedArrow.getEffect());
        }
    }
}
项目:Thermionics    文件:Thermionics.java   
@SubscribeEvent(priority=EventPriority.LOWEST)
public void onEntityAttack(LivingAttackEvent e) {
    if (e.getEntity().getEntityWorld().isRemote) return;

    Entity attacker = e.getSource().getTrueSource();

    if (attacker==null) return; //It's probably just some bat dying in lava
    if (attacker.hasCapability(CAPABILITY_WEAPONSKILL, EnumFacing.UP)) {
        IWeaponSkillInfo skillInfo = attacker.getCapability(CAPABILITY_WEAPONSKILL, EnumFacing.UP);
        if (skillInfo.getCooldown()<=0) {
            //Search for activations
            if (attacker instanceof EntityLivingBase) {

                //Tool activations
                if (e.getSource().damageType.equals("player")) {
                    ItemStack weapon = ((EntityLivingBase)attacker).getHeldItem(((EntityLivingBase) attacker).getActiveHand());
                    if (weapon.getItem() instanceof ISkillActivating) {
                        int activated = ((ISkillActivating) weapon.getItem()).activateSkill(skillInfo, (EntityLivingBase)attacker, weapon, e.getSource(), (EntityLiving) e.getEntityLiving());
                        if (activated>0) {
                            // TODO: Stats? Advancements?
                            skillInfo.setCooldown(activated);
                        }
                    }
                }
            }
        }
    }

    //TODO: Check the defender for armor WeaponSkills
}
项目:uniquecrops    文件:EmblemDefense.java   
@SubscribeEvent
public void autoShield(LivingAttackEvent event) {

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

    ItemStack shield = ((EntityPlayer)event.getEntityLiving()).getHeldItemOffhand();
    ItemStack emblem = BaublesApi.getBaublesHandler((EntityPlayer)event.getEntityLiving()).getStackInSlot(6);
    if (shield == null || emblem == null) return;
    if (emblem.getItem() != this || !(shield.getItem() instanceof ItemShield)) return;

    shield.attemptDamageItem(1, event.getEntityLiving().worldObj.rand);
    event.setCanceled(true);
}
项目:BetterBeginningsReborn    文件:ItemWickerShield.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent e)
{
    EntityLivingBase attacked = e.getEntityLiving();
    EntityLivingBase attacker = attacked.getAttackingEntity();
    if(attacker == null) return;
    damageShield(attacked, attacker, e.getAmount());
    doAxeStuff(attacked, attacker);
}
项目:AdvancedCombat    文件:CustomShieldHandler.java   
/** Damage the advanced shield correctly, as vanilla code only works for the vanilla shield */
@SubscribeEvent
public void onShieldedAttack(LivingAttackEvent e) {
    EntityLivingBase guy = e.getEntityLiving();
    if(!guy.world.isRemote && guy instanceof EntityPlayer) {
        if(e.getAmount() > 0.0F && !guy.getActiveItemStack().isEmpty() && guy.getActiveItemStack().getItem() instanceof ItemShieldAdvanced) {
            if(this.canBlockDamageSource((EntityPlayer)guy, e.getSource())) {
                this.damageShield((EntityPlayer)guy, e.getAmount());
            }
        }
    }
}
项目:ExPetrum    文件:ExPHandlerServer.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event)
{
    if (event.getSource() != null && event.getSource().getTrueSource() != null)
    {
        if (event.getSource().getTrueSource() instanceof EntityLivingBase && ((EntityLivingBase)event.getSource().getTrueSource()).isPotionActive(ExPPotions.stunned))
        {
            event.setCanceled(true);
        }
    }
}
项目:Possessed    文件:ServerEventHandler.java   
@SubscribeEvent
public void onAttack(LivingAttackEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        PossessivePlayer possessivePlayer = PossessHandler.get(player);
        if (possessivePlayer != null) {
            if (event.getSource().isFireDamage()) {
                event.setCanceled(true);
            } else {
                possessivePlayer.getPossessing().attackEntityFrom(event.getSource(), event.getAmount());
                event.setCanceled(true);
                if (!player.capabilities.isCreativeMode && !event.getSource().canHarmInCreative() && possessivePlayer.getPossessing().hurtTime <= 0) {
                    this.playPossessedHurtAnimation(player);
                }
            }
        }
    } else {
        EntityPlayer possessor = PossessHandler.getPossesor(event.getEntityLiving());
        if (possessor != null) {
            if (possessor.capabilities.isCreativeMode && !event.getSource().canHarmInCreative()) {
                event.setCanceled(true);
            } else if (possessor.hurtTime <= 0) {
                this.playPossessedHurtAnimation(possessor);
            }
        }
    }
}
项目:BetterWithAddons    文件:AssortedHandler.java   
@SubscribeEvent
public void livingAttacked(LivingAttackEvent event) {
    if (!event.getEntityLiving().world.isRemote) {
        if (!event.isCanceled() && event.getAmount() > 0) {
            EntityLivingBase living = event.getEntityLiving();

            if (living.isPotionActive(ModPotions.cannonball) && (event.getSource().isExplosion() || event.getSource() == DamageSource.FALL)) {
                if (event.getSource() == DamageSource.FALL) //No you don't get to have superbuffs that make you immune to creepers and falldamage.
                    living.removePotionEffect(ModPotions.cannonball);
                event.setCanceled(true);
            }
        }
    }
}
项目:CrystalMod    文件:ArmorEventHandler.java   
@SubscribeEvent
public void onPlayerDamaged(LivingAttackEvent event){
    event.getEntityLiving().getEntityWorld();
    EntityLivingBase attacked = event.getEntityLiving();
    DamageSource source = event.getSource();
    int pureCount = getArmorCount(attacked, "pure");
    if(getArmorCount(attacked, "red") == 4 || pureCount == 4){
        if(source == DamageSource.HOT_FLOOR){
            event.setCanceled(true);
        }
    }
    if(getArmorCount(attacked, "dark") == 4 || pureCount == 4){
        if(source.getSourceOfDamage() !=null){
            Entity toAttack = source.getSourceOfDamage();
            toAttack.attackEntityFrom(DamageSource.causeThornsDamage(attacked), EnchantmentThorns.getDamage(5, EntityUtil.rand));
            if(toAttack instanceof EntityLivingBase){
                EntityLivingBase living = (EntityLivingBase)toAttack;
                if(EntityUtil.rand.nextInt(10) == 0){
                    living.addPotionEffect(new PotionEffect(MobEffects.WITHER, MathHelper.getInt(EntityUtil.rand, 20*3, 20*6), 0));
                }
            }
        }
    }

    /*if(source == DamageSource.FALL){
        BlockPos pos = new BlockPos(attacked).down();
        IBlockState state = world.getBlockState(pos);
        if (state.getBlock() instanceof BlockLiquid && attacked.posY > pos.getY() + 0.9 && !(world.getBlockState(pos.up()).getBlock().getMaterial(world.getBlockState(pos.up())) == Material.WATER))
        {
            if(UpgradeItemRecipe.isWaterWalking(attacked.getItemStackFromSlot(EntityEquipmentSlot.FEET))){
                world.playSound(null, pos, SoundEvents.ENTITY_PLAYER_SPLASH, SoundCategory.PLAYERS, 1.0F, 1.0F);
                event.setCanceled(true);
            }
        }
    }*/
}
项目:CrystalMod    文件:EventHandler.java   
@SubscribeEvent
public void onAttacked(LivingAttackEvent event) {
    if(event.getSource() != null) {
        Entity attacker = event.getSource().getEntity();
        if(attacker != null && attacker instanceof EntityMinionWarrior && attacker.getRidingEntity() == event.getEntityLiving())
            event.setCanceled(true);
    }
}
项目:Aether-Legacy    文件:PlayerAetherEvents.java   
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event)
{
    if (event.getEntityLiving() instanceof EntityPlayer)
    {
        PlayerAether playerAether = PlayerAether.get((EntityPlayer) event.getEntityLiving());

        if (playerAether != null)
        {
            event.setCanceled(playerAether.onPlayerAttacked(event.getSource()));
        }
    }
}
项目:Inhuman-Resources    文件:PotionStun.java   
@SubscribeEvent
public void onLivingHurt(LivingAttackEvent event)
{
    if (event.getSource() == null) return;
    if (event.getSource().getTrueSource() == null) return;
    if (event.getSource().getTrueSource() instanceof EntityLivingBase)
    {
        PotionEffect effect = ((EntityLivingBase) event.getSource().getTrueSource()).getActivePotionEffect(PotionRegistry.STUN);
        if (effect == null) return;
        event.setCanceled(true);
    }
}
项目:Alchemy    文件:ItemBeltGuard.java   
@SubscribeEvent(priority = EventPriority.HIGH)
public void onLivingAttack(LivingAttackEvent event) {
    if (Always.isServer() && isEquipmented(event.getEntityLiving()) && isCDOver(event.getEntityLiving())) {
        AlchemyEventSystem.markEventCanceled(event);
        EntityLivingBase source = event.getSource().getTrueSource() instanceof EntityLivingBase ? (EntityLivingBase) event.getSource().getTrueSource() : null;
        if (source != null)
            source.attackEntityFrom(AlchemyDamageSourceLoader.dead_magic, event.getAmount());
        EntityLivingBase living = event.getEntityLiving();
        living.getCombatTracker().lastDamageTime = living.ticksExisted;
        if (living instanceof EntityPlayerMP && !(living instanceof FakePlayer))
            AlchemyNetworkHandler.network_wrapper.sendTo(new MessageGuardCallback(-1), (EntityPlayerMP) living);
    }
}
项目:geomastery    文件:PlayerEvents.java   
/** Alters behaviour when the player takes damage. */
@SubscribeEvent
public void playerAttacked(LivingAttackEvent event) {

    if (!(event.getEntity() instanceof EntityPlayer)) {

        return;
    }

    EntityPlayer player = (EntityPlayer) event.getEntity();
    DamageSource source = event.getSource();

    // Copy vanilla shield functionality to allow for custom shields
    if (!source.isUnblockable() && player.isActiveItemStackBlocking() &&
            player.getActiveItemStack().getItem() instanceof ItemShield) {

        Vec3d sourceVec = source.getDamageLocation();

        if (sourceVec != null) {

            Vec3d playerVec = player.getLook(1.0F);
            Vec3d attackVec = sourceVec.subtractReverse(new
                    Vec3d(player.posX, player.posY,
                    player.posZ)).normalize();
            attackVec = new Vec3d(attackVec.xCoord,
                    0.0D, attackVec.zCoord);

            if (attackVec.dotProduct(playerVec) < 0.0D &&
                    event.getAmount() >= 3) {

                player.getActiveItemStack().damageItem(1 +
                        MathHelper.floor(event.getAmount()), player);
            }
        }
    }
}
项目:EvilOcean    文件:EventWaterDrown.java   
@SubscribeEvent
public boolean onLivingAttackEvent(LivingAttackEvent event) {
    if ((event.entityLiving instanceof EntityPlayer) && (event.source == DamageSource.drown)) {
        event.entityLiving.setHealth(0.5F);
        return true;
    }
    return false;
}
项目:Fallout_Equestria    文件:CommonEventHandler.java   
@SubscribeEvent
public void onDamageRender(LivingAttackEvent e) {
    if (e.getEntityLiving() instanceof EntityPlayer) {
        if (e.getSource() == DamageSource.MAGIC) {
            e.setCanceled(false);
            return;
        }
    }
}
项目:TinkersToolLeveling    文件:ModToolLeveling.java   
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void onLivingHurt(LivingAttackEvent event) {
  // if it's cancelled it got handled by the battlesign (or something else. but it's a prerequisite.)
  if(!event.isCanceled()) {
    return;
  }
  if(event.getSource().isUnblockable() || !event.getSource().isProjectile() || event.getSource().getTrueSource() == null) {
    return;
  }
  // hit entity is a player?
  if(!(event.getEntity() instanceof EntityPlayer)) {
    return;
  }
  EntityPlayer player = (EntityPlayer) event.getEntity();
  // needs to be blocking with a battlesign
  if(!player.isActiveItemStackBlocking() || player.getActiveItemStack().getItem() != TinkerMeleeWeapons.battleSign) {
    return;
  }
  // broken battlesign.
  if(ToolHelper.isBroken(player.getActiveItemStack())) {
    return;
  }

  // at this point we duplicated all the logic if the battlesign should reflect a projectile.. bleh.
  int xp = Math.max(1, Math.round(event.getAmount()));
  addXp(player.getActiveItemStack(), xp, player);
}