net.minecraftforge.event.entity.living.LivingHurtEvent Java Examples

The following examples show how to use net.minecraftforge.event.entity.living.LivingHurtEvent. 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: ItemReinforcedDiamondArmor.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void postInit(LivingHurtEvent e) {

	DamageSource source = e.getSource();

	Iterable<ItemStack> armorStacks = e.getEntityLiving().getArmorInventoryList();

	// boolean hasHeavyArmor = false;
	float reduction = 0;

	for (ItemStack armorStack : armorStacks) {
		if (isHeavyArmor(armorStack)) {
			if (source.isProjectile() || source.isExplosion()) {
				reduction += 0.2;
			}
		}
	}

	if (reduction > 0) {
		float newDamage = (1 - reduction) * e.getAmount();
		System.out.println("Heavy armor reduction: [" + reduction + "] IN[" + e.getAmount() + "] OUT[" + newDamage + "]");
		e.setAmount(newDamage);
	}
}
 
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: ServerEventHandler.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SubscribeEvent
public void entityHurtEvent(LivingHurtEvent event) {
	if (!EtFuturum.enableDmgIndicator)
		return;
	int amount = MathHelper.floor_float(Math.min(event.entityLiving.getHealth(), event.ammount) / 2F);
	if (amount <= 0)
		return;

	// If the attacker is a player spawn the hearts aligned and facing it
	if (event.source instanceof EntityDamageSource) {
		EntityDamageSource src = (EntityDamageSource) event.source;
		Entity attacker = src.getSourceOfDamage();
		if (attacker instanceof EntityPlayer && !(attacker instanceof FakePlayer)) {
			EntityPlayer player = (EntityPlayer) attacker;
			Vec3 look = player.getLookVec();
			look.rotateAroundY((float) Math.PI / 2);
			for (int i = 0; i < amount; i++) {
				double x = event.entityLiving.posX - amount * 0.35 * look.xCoord / 2 + i * 0.35 * look.xCoord;
				double y = event.entityLiving.posY + 1.5 + event.entityLiving.worldObj.rand.nextGaussian() * 0.05;
				double z = event.entityLiving.posZ - amount * 0.35 * look.zCoord / 2 + i * 0.35 * look.zCoord;
				EtFuturum.networkWrapper.sendToAllAround(new BlackHeartParticlesMessage(x, y, z), new TargetPoint(player.worldObj.provider.dimensionId, x, y, z, 64));
			}
		}
	}
}
 
Example #4
Source File: EventHandlerGolem.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(LivingHurtEvent event) {
    if (!event.entity.worldObj.isRemote) {
        if(event.entity instanceof EntityGolemBase) {
            EntityGolemBase golem = (EntityGolemBase) event.entity;
            if(event.ammount > 0 && RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(golem)) {
                event.ammount = RegisteredGolemStuff.upgradeRunicShield.absorb(golem, event.ammount, event.source);
            }
        }

        /*if(event.source.getEntity() != null && event.source.getEntity() instanceof EntityGolemBase
                && ((EntityGolemBase) event.source.getEntity()).getGolemType()
                    == RegisteredGolemStuff.typeObsidian.getEnumEntry()) {
            event.entityLiving.addPotionEffect(new PotionEffect(Potion.wither.getId(), 3*20, 1));
        }*/
    }
}
 
Example #5
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 #6
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 #7
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 #8
Source File: ComponentMedkit.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public void onTakeDamage(ItemStack itemStack, LivingHurtEvent event, boolean isWornArmor) {
	if(isWornArmor) {
		if(itemStack.stackTagCompound.getInteger("medkitDelay_armor") <= 0)
			itemStack.stackTagCompound.setInteger("medkitDelay_armor", 200);
	}
}
 
Example #9
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 #10
Source File: ModToolLeveling.java    From TinkersToolLeveling with MIT License 5 votes vote down vote up
@Override
public void onBlock(ItemStack tool, EntityPlayer player, LivingHurtEvent event) {
  if(player != null && !player.world.isRemote && player.getActiveItemStack() == tool) {
    int xp = Math.round(event.getAmount());
    addXp(tool, xp, player);
  }
}
 
Example #11
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 #12
Source File: EventHandlers.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private EntityLivingBase getAttacker(LivingHurtEvent event) {
	try {
		return (EntityLivingBase) event.getSource().getTrueSource();
	} catch (Exception e) {
		return null;
	}
}
 
Example #13
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 #14
Source File: ItemSwordOfPain.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private boolean thisToolWasUsed(LivingHurtEvent event) {
	if (event.getSource() == null || !(event.getSource().getTrueSource() instanceof EntityPlayer)) {
		return false;
	}
	EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
	return player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == INSTANCE;
}
 
Example #15
Source File: EventHandler.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void underworldTeleport(LivingHurtEvent event) {
	if (!(event.getEntity() instanceof EntityPlayer)) return;
	if (fallResetter.contains(event.getEntity().getUniqueID())) {
		if (event.getEntity().posY < 0 || event.getEntity().posY > event.getEntity().world.getHeight()) {
			event.setCanceled(true);
			return;
		}
		if (event.getSource() == DamageSource.FALL) {
			fallResetter.remove(event.getEntity().getUniqueID());
			event.setCanceled(true);
		}
	}
}
 
Example #16
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);
					}
					
				}
			}

		}

	}
}
 
Example #17
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static float onLivingHurt(LivingEntity entity, DamageSource src, float damage) {
	LivingHurtEvent event = new LivingHurtEvent(entity, src, damage);
	return MinecraftForge.EVENT_BUS.post(event) ? 0 : event.getAmount();
}
 
Example #18
Source File: ItemSwordOfPain.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private void alterDamage(LivingHurtEvent event) {
	float amount = event.getAmount();
	event.setAmount(amount * 2);
	event.getSource().getTrueSource().attackEntityFrom(event.getSource(), amount / 2);
}
 
Example #19
Source File: ComponentObscurity.java    From Artifacts with MIT License 4 votes vote down vote up
@Override
public void onTakeDamage(ItemStack itemStack, LivingHurtEvent event, boolean isWornArmor) {	
	if(isWornArmor) {
		hitEntity(itemStack, event.entityLiving, event.entityLiving);
	}
}
 
Example #20
Source File: ComponentBreathing.java    From Artifacts with MIT License 4 votes vote down vote up
@Override
public void onTakeDamage(ItemStack itemStack, LivingHurtEvent event, boolean isWornArmor) {
	if(isWornArmor && event.source == DamageSource.drown) {
		event.entityLiving.addPotionEffect(new PotionEffect(13, 40, 0));
	}
}
 
Example #21
Source File: ItemSwordOfPain.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onHurt(LivingHurtEvent event) {
	if (thisToolWasUsed(event)) {
		alterDamage(event);
	}
}
 
Example #22
Source File: IArtifactComponent.java    From Artifacts with MIT License 2 votes vote down vote up
/**
 * Called from a LivingHurtEvent handler.  Will only fire if the event.entity is of instance EntityPlayer
 * Using these requires an understanding of Shared Monster Attributes and using {@link ArtifactsAPI#OnHurtAttribute}<br/>
 * You will likely want to create unique components for behaviors that use this.
 * @param itemStack is the stack associated with the effect
 * @param event is the LivingHurtEvent
 * @param isWornArmor true if the item is equipped to the player's armor slots
 */
public void onTakeDamage(ItemStack itemStack, LivingHurtEvent event, boolean isWornArmor);
 
Example #23
Source File: BaseComponent.java    From Artifacts with MIT License 2 votes vote down vote up
@Override
public void onTakeDamage(ItemStack itemStack, LivingHurtEvent event, boolean isWornArmor) {
	
}