當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。