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

The following examples show how to use net.minecraftforge.event.entity.living.LivingAttackEvent. 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: RewardForDamagingEntityImplementation.java    From malmo with MIT License 6 votes vote down vote up
@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());
                }
            }
        }
    }
}
 
Example #2
Source File: ItemCyberlimb.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleFallDamage(LivingAttackEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	if (e.worldObj.isRemote && (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 2)) || CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 3))) && event.getSource() == DamageSource.fall)
	{
		if (!didFall.contains(e.getEntityId()))
		{
			didFall.add(e.getEntityId());
		}
	}
}
 
Example #3
Source File: ItemLegUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onFallDamage(LivingAttackEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	ItemStack test = new ItemStack(this, 1, 1);
	if (event.getSource() == DamageSource.fall && event.getAmount() <= 6F && CyberwareAPI.isCyberwareInstalled(e, test))
	{
		event.setCanceled(true);
	}
}
 
Example #4
Source File: ModToolLeveling.java    From TinkersToolLeveling with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void onLivingHurt(LivingAttackEvent event) {
  // if it's cancelled it got handled by the battlesign (or something else. but it's a prerequisite.)
  if(!event.isCanceled()) {
    return;
  }
  if(event.getSource().isUnblockable() || !event.getSource().isProjectile() || event.getSource().getTrueSource() == null) {
    return;
  }
  // hit entity is a player?
  if(!(event.getEntity() instanceof EntityPlayer)) {
    return;
  }
  EntityPlayer player = (EntityPlayer) event.getEntity();
  // needs to be blocking with a battlesign
  if(!player.isActiveItemStackBlocking() || player.getActiveItemStack().getItem() != TinkerMeleeWeapons.battleSign) {
    return;
  }
  // broken battlesign.
  if(ToolHelper.isBroken(player.getActiveItemStack())) {
    return;
  }

  // at this point we duplicated all the logic if the battlesign should reflect a projectile.. bleh.
  int xp = Math.max(1, Math.round(event.getAmount()));
  addXp(player.getActiveItemStack(), xp, player);
}
 
Example #5
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@SubscribeEvent
public void livingAttack(LivingAttackEvent event) {
	if (event.source instanceof EntityDamageSourceIndirect) {
		EntityDamageSourceIndirect dmgSrc = (EntityDamageSourceIndirect) event.source;
		if (dmgSrc.getSourceOfDamage() instanceof EntityTippedArrow) {
			EntityTippedArrow tippedArrow = (EntityTippedArrow) dmgSrc.getSourceOfDamage();
			if (!tippedArrow.worldObj.isRemote)
				event.entityLiving.addPotionEffect(tippedArrow.getEffect());
		}
	}
}
 
Example #6
Source File: EntityLivingHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event)
{
	if(event.getSource().getDamageType() == "player" && event.getSource().getEntity() instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
		ItemStack is = player.getHeldItemMainhand();
		if(is.isEmpty())
			event.setCanceled(true);
	}
}
 
Example #7
Source File: EntityEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onAttackEntity(LivingAttackEvent event)
{
    // When a "passified" entity is attacked by another entity, remove the "passified" tag,
    // and restore the target AI tasks by re-adding all the AI tasks from a fresh clone
    if ((event.getEntity() instanceof EntityLiving) && event.getEntity().getEntityWorld().isRemote == false &&
        event.getSource() instanceof EntityDamageSource && event.getEntity().getTags().contains(ItemSyringe.TAG_PASSIFIED))
    {
        ItemSyringe.removePassifiedState((EntityLiving) event.getEntity());
    }
}
 
Example #8
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float damage) {
	return MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, damage));
}
 
Example #9
Source File: ItemBrainUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent(priority=EventPriority.HIGHEST)
public void handleHurt(LivingAttackEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 4)) && isMatrixWorking(e))
	{

		if (!e.worldObj.isRemote && event.getSource() instanceof EntityDamageSource)
		{
			Entity attacker = ((EntityDamageSource) event.getSource()).getSourceOfDamage();
			if (e instanceof EntityPlayer)
			{
				String str = e.getEntityId() + " " + e.ticksExisted + " " + attacker.getEntityId();
				if (lastHits.contains(str))
				{
					return;
				}
				else
				{
					lastHits.add(str);
				}
			}
			
			boolean armor = false;
			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;
					}
				}
				
				if (stack != null)
				{
					armor = true;
				}
				
			}
			

			if (!((float) e.hurtResistantTime > (float) e.maxHurtResistantTime / 2.0F))
               {
				Random random = e.getRNG();
				if (random.nextFloat() < (armor ? LibConstants.DODGE_ARMOR : LibConstants.DODGE_NO_ARMOR))
				{
					event.setCanceled(true);
					e.hurtResistantTime = e.maxHurtResistantTime;
					e.hurtTime = e.maxHurtTime = 10;
					ReflectionHelper.setPrivateValue(EntityLivingBase.class, e, 9999F, 46);
					
					CyberwarePacketHandler.INSTANCE.sendToAllAround(new DodgePacket(e.getEntityId()), new TargetPoint(e.worldObj.provider.getDimension(), e.posX, e.posY, e.posZ, 50));
				}
			}
		}
	}
}