Java Code Examples for net.minecraftforge.event.entity.living.LivingHurtEvent#isCanceled()

The following examples show how to use net.minecraftforge.event.entity.living.LivingHurtEvent#isCanceled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemHeartUpgrade.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void handleHurt(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	if (!event.isCanceled() && CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 2)))
	{
		float damageAmount = event.getAmount();
		DamageSource damageSrc = event.getSource();

		damageAmount = applyArmorCalculations(e, damageSrc, damageAmount);
		damageAmount = applyPotionDamageCalculations(e, damageSrc, damageAmount);
		damageAmount = Math.max(damageAmount - e.getAbsorptionAmount(), 0.0F);
		
		damageMedkit.put(e.getEntityId(), damageAmount);
		timesMedkit.put(e.getEntityId(), e.ticksExisted);
	}
}
 
Example 2
Source File: ComponentAdrenaline.java    From Artifacts with MIT License 6 votes vote down vote up
@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));
				
			//}
		}
	}
}
 
Example 3
Source File: ItemMuscleUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void handleHurt(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();

	ItemStack test = new ItemStack(this, 1, 0);
	int rank = CyberwareAPI.getCyberwareRank(e, test);
	if (!event.isCanceled() && e instanceof EntityPlayer && (rank > 1) && EnableDisableHelper.isEnabled(CyberwareAPI.getCyberware(e, test)) && getLastBoostSpeed(e))
	{
		EntityPlayer p = (EntityPlayer) e;
		if (event.getSource() instanceof EntityDamageSource && !(event.getSource() instanceof EntityDamageSourceIndirect))
		{
			EntityDamageSource source = (EntityDamageSource) event.getSource();
			Entity attacker = source.getEntity();
			int lastAttacked = ReflectionHelper.getPrivateValue(CombatTracker.class, p.getCombatTracker(), 2);
			
			if (p.ticksExisted - lastAttacked > 120)
			{
				ItemStack weapon = p.getHeldItemMainhand();
				int loc = -1;
				if (weapon != null)
				{
					if (p.getItemInUseCount() > 0 || weapon.getItem() instanceof ItemSword || weapon.getItem().getAttributeModifiers(EntityEquipmentSlot.MAINHAND, weapon).containsKey(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()))
					{
						loc = p.inventory.currentItem;
					}
				}
				
				if (loc == -1)
				{
					double mostDamage = 0F;
					
					for (int i = 0; i < 10; i++)
					{
						if (i != p.inventory.currentItem)
						{
							ItemStack potentialWeapon = p.inventory.mainInventory[i];
							if (potentialWeapon != null)
							{
								Multimap<String, AttributeModifier> modifiers = potentialWeapon.getItem().getAttributeModifiers(EntityEquipmentSlot.MAINHAND, potentialWeapon);
								if (modifiers.containsKey(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()))
								{
									double damage = modifiers.get(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()).iterator().next().getAmount();
									
									if (damage > mostDamage || loc == -1)
									{
										mostDamage = damage;
										loc = i;
									}
								}
							}
						}
					}
				}
				
				if (loc != -1)
				{
					//System.out.println("LOC " + loc);

					p.inventory.currentItem = loc;

		
					CyberwarePacketHandler.INSTANCE.sendTo(new SwitchHeldItemAndRotationPacket(loc, p.getEntityId(), rank > 2 ? attacker.getEntityId() : -1), (EntityPlayerMP) p);
					
					WorldServer world = (WorldServer) p.worldObj;
					
					for (EntityPlayer trackingPlayer : world.getEntityTracker().getTrackingPlayers(p))
					{
						CyberwarePacketHandler.INSTANCE.sendTo(new SwitchHeldItemAndRotationPacket(loc, p.getEntityId(), rank > 2 ? attacker.getEntityId() : -1), (EntityPlayerMP) trackingPlayer);
					}
					
				}
			}

		}

	}
}