当前位置: 首页>>代码示例>>Java>>正文


Java LivingAttackEvent类代码示例

本文整理汇总了Java中net.minecraftforge.event.entity.living.LivingAttackEvent的典型用法代码示例。如果您正苦于以下问题:Java LivingAttackEvent类的具体用法?Java LivingAttackEvent怎么用?Java LivingAttackEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LivingAttackEvent类属于net.minecraftforge.event.entity.living包,在下文中一共展示了LivingAttackEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onLivingAttack

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
			}
		}
	}
}
 
开发者ID:TheXFactor117,项目名称:Loot-Slash-Conquer,代码行数:25,代码来源:EventLivingHurtAttack.java

示例2: onAttack

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:Um-Mitternacht,项目名称:Bewitchment,代码行数:23,代码来源:VolatileBrew.java

示例3: stopHurt

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
	}

}
 
开发者ID:rafradek,项目名称:Mods,代码行数:26,代码来源:TF2EventsCommon.java

示例4: onPlayerAttack

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:mchorse,项目名称:metamorph,代码行数:27,代码来源:MorphHandler.java

示例5: onLivingAttackEvent

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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());
                }
            }
        }
    }
}
 
开发者ID:Microsoft,项目名称:malmo,代码行数:25,代码来源:RewardForDamagingEntityImplementation.java

示例6: onLivingHurt

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:murapix,项目名称:Inhuman-Resources,代码行数:17,代码来源:PotionRedstoneNeedle.java

示例7: onLivingAttackCallback

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
		}
	}
}
 
开发者ID:NekoCaffeine,项目名称:Alchemy,代码行数:18,代码来源:ItemBeltGuard.java

示例8: attackEvent

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
        }
    }
}
 
开发者ID:MinecraftModDevelopmentMods,项目名称:MMDLib-old,代码行数:19,代码来源:ForgeEventHandler.java

示例9: onPlayerHurt

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:estebes,项目名称:Gravitation-Suite-Reloaded,代码行数:21,代码来源:ItemElectricArmor.java

示例10: onLivingAttack

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
				}
			}
		}
	}
}
 
开发者ID:The-Fireplace-Minecraft-Mods,项目名称:Wars-Mod,代码行数:20,代码来源:CommonEvents.java

示例11: onEntityAttacked

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
				}
			}
		}
	}
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:24,代码来源:ItemGasMask.java

示例12: onEntityAttacked

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
		}
	}
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:18,代码来源:ItemFreeRunners.java

示例13: attackedEntity

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
			}
		}
	}
}
 
开发者ID:Nincraft,项目名称:NincraftLib,代码行数:18,代码来源:DamageModifierHandler.java

示例14: entityAttacked

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
				}
			}
		}
	}
}
 
开发者ID:Nincodedo,项目名称:Nincrafty-Things,代码行数:22,代码来源:ArmorSetBonusHandler.java

示例15: onAttack

import net.minecraftforge.event.entity.living.LivingAttackEvent; //导入依赖的package包/类
@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);
			}
		}
	}
}
 
开发者ID:TheAwesomeGem,项目名称:MineFantasy,代码行数:24,代码来源:EventManagerMF.java


注:本文中的net.minecraftforge.event.entity.living.LivingAttackEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。