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

The following examples show how to use net.minecraftforge.event.entity.living.LivingHurtEvent. These examples are extracted from open source projects.
Example 1
Project: ToroQuest   File: ItemReinforcedDiamondArmor.java    License: 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
Project: Cyberware   File: ItemHeartUpgrade.java    License: 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 3
Project: Cyberware   File: EssentialsMissingHandler.java    License: 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 4
Project: Gadomancy   File: EventHandlerGolem.java    License: 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
Project: Et-Futurum   File: ServerEventHandler.java    License: 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 6
Project: Artifacts   File: ComponentAdrenaline.java    License: 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 7
Project: Wizardry   File: EventHandler.java    License: 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 8
Project: ToroQuest   File: ItemSwordOfPain.java    License: 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 9
Project: ToroQuest   File: EventHandlers.java    License: 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 10
Project: ToroQuest   File: EventHandlers.java    License: 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 11
Project: Cyberware   File: ItemBoneUpgrade.java    License: 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
Project: Cyberware   File: ItemSkinUpgrade.java    License: 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 13
Project: TinkersToolLeveling   File: ModToolLeveling.java    License: 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 14
Project: Survivalist   File: ItemBreakingTracker.java    License: 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 15
Project: Artifacts   File: ComponentMedkit.java    License: 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 16
Project: patchwork-api   File: EntityEvents.java    License: 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 17
Project: ToroQuest   File: ItemSwordOfPain.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onHurt(LivingHurtEvent event) {
	if (thisToolWasUsed(event)) {
		alterDamage(event);
	}
}
 
Example 18
Project: ToroQuest   File: ItemSwordOfPain.java    License: 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
Project: Cyberware   File: ItemMuscleUpgrade.java    License: 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 20
Project: Artifacts   File: ComponentObscurity.java    License: 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 21
Project: Artifacts   File: ComponentBreathing.java    License: 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 22
Project: Artifacts   File: IArtifactComponent.java    License: 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
Project: Artifacts   File: BaseComponent.java    License: MIT License 2 votes vote down vote up
@Override
public void onTakeDamage(ItemStack itemStack, LivingHurtEvent event, boolean isWornArmor) {
	
}