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

The following examples show how to use net.minecraftforge.event.entity.living.LivingHurtEvent#getEntityLiving() . 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: EssentialsMissingHandler.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleMissingSkin(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	if (CyberwareAPI.hasCapability(e))
	{
		ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
		
		if (!cyberware.hasEssential(EnumSlot.SKIN))
		{
	
			if (!event.getSource().isUnblockable() || event.getSource() == DamageSource.fall)
			{
				event.setAmount(event.getAmount() * 3F);
			}
		}
	}
}
 
Example 3
Source File: EventHandlers.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void toroDontLikeYouHurtingCows(LivingHurtEvent event) {
	EntityLivingBase victim = event.getEntityLiving();
	EntityLivingBase attacker = getAttacker(event);

	if (victim == null || attacker == null || !(victim instanceof EntityCow)) {
		return;
	}

	List<EntityToro> nearbyToros = victim.getEntityWorld().getEntitiesWithinAABB(EntityToro.class,
			victim.getEntityBoundingBox().expand(40.0D, 10.0D, 40.0D));
	for (EntityToro toro : nearbyToros) {
		toro.setAttackTarget(attacker);
	}
}
 
Example 4
Source File: ItemBoneUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleFallDamage(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 1)))
	{

		if (event.getSource() == DamageSource.fall)
		{
			event.setAmount(event.getAmount() * .3333F);
		}
		
	}
}
 
Example 5
Source File: ItemSkinUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleHurt(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();

	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 1)))
	{
		if (event.getSource() instanceof EntityDamageSource && !(event.getSource() instanceof EntityDamageSourceIndirect))
		{
			for (ItemStack stack : e.getArmorInventoryList())
			{
				if (stack != null && stack.getItem() instanceof ItemArmor)
				{
					if (((ItemArmor) stack.getItem()).getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.CHEST) > 4)
					{
						return;
					}
				}
				else if (stack != null && stack.getItem() instanceof ISpecialArmor)
				{
					if (((ISpecialArmor) stack.getItem()).getProperties(e, stack, event.getSource(), event.getAmount(), 1).AbsorbRatio * 25D > 4)
					{
						return;
					}
				}
			}
			
			Random random = e.getRNG();
			Entity attacker = ((EntityDamageSource) event.getSource()).getSourceOfDamage();
			int level = 2;
			if (EnchantmentThorns.shouldHit(3, random))
			{
				if (attacker != null)
				{
					attacker.attackEntityFrom(DamageSource.causeThornsDamage(e), (float) EnchantmentThorns.getDamage(2, random));
				}
			}
		}
	}
}
 
Example 6
Source File: ItemBreakingTracker.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent ev)
{
    if (!ConfigManager.SERVER.enableScraping.get())
        return;
    if (ev.getEntity().world.isRemote)
        return;

    if (ev.getEntity() instanceof PlayerEntity)
    {
        PlayerEntity player = (PlayerEntity) ev.getEntityLiving();

        ItemBreakingTracker.get(player).ifPresent(ItemBreakingTracker::before);
    }
}
 
Example 7
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);
					}
					
				}
			}

		}

	}
}