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

The following are top voted examples for showing how to use net.minecraftforge.event.entity.living.LivingHurtEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Soot   File: Attributes.java   View source code 6 votes vote down vote up
@SubscribeEvent
public static void onHurtEvent(LivingHurtEvent event)
{
    EntityLivingBase entity = event.getEntityLiving();
    DamageSource damageSource = event.getSource();
    float damage = event.getAmount();
    if(entity != null)
    {
        IAttributeInstance damageRate = null;
        if(isPhysicalDamage(damageSource))
            damageRate = entity.getEntityAttribute(PHYSICAL_DAMAGE_RATE);
        if(damageSource.isFireDamage())
            damageRate = entity.getEntityAttribute(FIRE_DAMAGE_RATE);

        if(damageRate != null)
            damage *= damageRate.getAttributeValue();
    }
    event.setAmount(damage);
}
 
Example 2
Project: harshencastle   File: HandlerSoulHarsherSword.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void attackEntity(LivingHurtEvent event)
{
	try
	{
		if((event.getSource() instanceof EntityDamageSource && ((EntityDamageSource)event.getSource()).getTrueSource() instanceof EntityLivingBase
				&& (((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof BaseHarshenSword ||
					((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof HarshenProps)
			   &&!(Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(3).getItem() == HarshenArmors.harshen_jaguar_armor_helmet
				&& Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(2).getItem() == HarshenArmors.harshen_jaguar_armor_chestplate
				&& Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(1).getItem() == HarshenArmors.harshen_jaguar_armor_leggings
				&& Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(0).getItem() == HarshenArmors.harshen_jaguar_armor_boots)))
			event.getEntityLiving().addPotionEffect(new PotionEffect(MobEffects.WITHER, 150, 1));
	}
	catch (ClassCastException clazz){}
}
 
Example 3
Project: harshencastle   File: HandlerRaptorScythe.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void attackEntity(LivingHurtEvent event)
{
	try
	{
		if((event.getSource() instanceof EntityDamageSource && ((EntityDamageSource)event.getSource()).getTrueSource() instanceof EntityLivingBase
				&& (((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof RaptorScythe ||
					((EntityLivingBase)((EntityDamageSource)event.getSource()).getTrueSource()).getHeldItemMainhand().getItem() instanceof HarshenProps)
			   &&!(Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(3).getItem() == HarshenArmors.harshen_jaguar_armor_helmet
				&& Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(2).getItem() == HarshenArmors.harshen_jaguar_armor_chestplate
				&& Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(1).getItem() == HarshenArmors.harshen_jaguar_armor_leggings
				&& Lists.newArrayList(event.getEntityLiving().getArmorInventoryList().iterator()).get(0).getItem() == HarshenArmors.harshen_jaguar_armor_boots)))
			event.getEntityLiving().addPotionEffect(new PotionEffect(MobEffects.WITHER, 150, 1));
	}
	catch (ClassCastException clazz){}
}
 
Example 4
Project: Randores2   File: LivingHurtListener.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onHurt(LivingHurtEvent ev) {
    DamageSource source = ev.getSource();
    Entity root = source.getImmediateSource();
    if (root instanceof EntityLivingBase) {
        EntityLivingBase cause = (EntityLivingBase) root;
        EntityLivingBase hurt = ev.getEntityLiving();

        EnumHand active = cause.getActiveHand();
        ItemStack stack = cause.getHeldItem(active);
        RandoresItemHelper.doEmpowered(stack, hurt, cause);

        if(stack.getItem() instanceof RandoresSledgehammer) {
            Vec3d vector = hurt.getPositionVector().subtract(cause.getPositionVector()).normalize().scale(2);
            hurt.addVelocity(vector.x, 0.5, vector.z);
        }
    }
}
 
Example 5
Project: ExtraAcC   File: DamageRecalc.java   View source code 6 votes vote down vote up
@SubscribeEvent
  public void recalc(LivingHurtEvent event) {
if (!(event.entity instanceof EntityPlayer)) {
	return;
}
EntityPlayer player = (EntityPlayer) event.entity;
if (!AbilityData.get(player).isSkillLearned(SkillAirControl.INSTANCE)) {
	return;
}
if (event.source.getDamageType().equals("inWall") || event.source.getDamageType().equals("drown")) {
	event.ammount *= 0.1;
} else if (event.source.getDamageType().equals("fall")) {
	event.ammount *= 0.25;
} else if (event.source.isProjectile() || event.source.getDamageType().equals("anvil")) {
	event.ammount *= 0.75;
}
  }
 
Example 6
Project: connor41-etfuturum2   File: ServerEventHandler.java   View source code 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 7
Project: uniquecrops   File: EmblemTransformation.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onHitEntity(LivingHurtEvent event) {
	
	if (event.getAmount() <= 0 || event.getEntityLiving() instanceof EntityPlayer) return;
	
	if (!(event.getSource().getSourceOfDamage() instanceof EntityPlayer)) return;
	
	ItemStack transformer = BaublesApi.getBaublesHandler((EntityPlayer)event.getSource().getSourceOfDamage()).getStackInSlot(6);
	if (transformer == null || (transformer != null && transformer.getItem() != this)) return;
	
	Random rand = new Random();
	if (rand.nextInt(100) != 0) return;
	
	EntityLivingBase elb = event.getEntityLiving();
	List<String> entities = new ArrayList<String>(EntityList.ENTITY_EGGS.keySet());
	String randomString = entities.get(rand.nextInt(entities.size()));
	Entity entity = EntityList.createEntityByName(randomString, elb.worldObj);
	if (!entity.isNonBoss()) return;
	entity.setPositionAndRotation(elb.posX, elb.posY, elb.posZ, elb.rotationYaw, elb.rotationPitch);
	
	elb.worldObj.spawnEntityInWorld(entity);
	elb.setDead();
}
 
Example 8
Project: AdvancedCombat   File: ArmorHandler.java   View source code 6 votes vote down vote up
/** Handle wearing obsidian armor */
private boolean obsidianArmor(LivingHurtEvent e) {
	EntityLivingBase hurt = e.getEntityLiving();

	// do things based on the armor status
	int armorCount = getWearingSetCount(hurt, ItemArmorObsidian.class);
	if(armorCount > 0) {
		
		// blast resistance II
		if(e.getSource().isExplosion()) {
			e.setAmount(e.getAmount() * (1 - armorCount / 4F));
		}
		
		return true;
	}
	return false;
}
 
Example 9
Project: Overlord   File: CommonEvents.java   View source code 6 votes vote down vote up
@SubscribeEvent
public static void livingHurt(LivingHurtEvent event) {
	if (!event.getEntity().world.isRemote)
		if(event.getSource().getTrueSource() instanceof EntityArmyMember) {
			if (event.getEntityLiving() instanceof EntityPlayerMP) {
				if (event.getSource().isProjectile()) {
					if (event.getSource().getTrueSource() instanceof EntitySkeletonWarrior && ((EntitySkeletonWarrior) event.getSource().getTrueSource()).getOwnerId().equals(event.getEntityLiving().getUniqueID()))
						CriterionRegistry.instance.SKELETON_STATUS_UPDATE.trigger((EntityPlayerMP) event.getEntityLiving(), event.getSource().getTrueSource(), Items.ARROW, 0);
					else if (event.getSource().getTrueSource() instanceof EntityConvertedSkeleton && ((EntityConvertedSkeleton) event.getSource().getTrueSource()).getOwnerId().equals(event.getEntityLiving().getUniqueID()))
						CriterionRegistry.instance.SKELETON_STATUS_UPDATE.trigger((EntityPlayerMP) event.getEntityLiving(), event.getSource().getTrueSource(), Items.ARROW, 1);
				}
				if(ConfigValues.FF && Alliances.getInstance().isAlliedTo(((EntityArmyMember) event.getSource().getTrueSource()).getOwnerId(), event.getEntityLiving().getUniqueID()))
					event.setCanceled(true);
			} else if(ConfigValues.FF && event.getEntityLiving() instanceof EntityArmyMember && Alliances.getInstance().isAlliedTo(((EntityArmyMember) event.getSource().getTrueSource()).getOwnerId(), ((EntityArmyMember)event.getEntityLiving()).getOwnerId()))
				event.setCanceled(true);
		} else if (ConfigValues.FF && event.getSource().getTrueSource() instanceof EntityPlayer) {
			if(event.getEntityLiving() instanceof EntityPlayer && Alliances.getInstance().isAlliedTo(event.getSource().getTrueSource().getUniqueID(), event.getEntityLiving().getUniqueID()))
				event.setCanceled(true);
			else if(event.getEntityLiving() instanceof EntityArmyMember && Alliances.getInstance().isAlliedTo(event.getSource().getTrueSource().getUniqueID(), ((EntityArmyMember)event.getEntityLiving()).getOwnerId()))
				event.setCanceled(true);
		}
}
 
Example 10
Project: 4Space-5   File: EventHandlerGC.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onEntityDamaged(LivingHurtEvent event)
{
    if (event.source.damageType.equals(DamageSource.onFire.damageType))
    {
        if (OxygenUtil.noAtmosphericCombustion(event.entityLiving.worldObj.provider))
        {
	        if (OxygenUtil.isAABBInBreathableAirBlock(event.entityLiving.worldObj, event.entityLiving.boundingBox))
	        	return;

            if (event.entityLiving.worldObj instanceof WorldServer)
            {
                ((WorldServer) event.entityLiving.worldObj).func_147487_a("smoke", event.entityLiving.posX, event.entityLiving.posY + event.entityLiving.boundingBox.maxY - event.entityLiving.boundingBox.minY, event.entityLiving.posZ, 50, 0.0, 0.05, 0.0, 0.001);
            }

            event.entityLiving.extinguish();
        }
    }
}
 
Example 11
Project: MidgarCrusade   File: ForgeEventHooksHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void reflecteffect(LivingHurtEvent lde,EntityPlayerMP sender)
  {
    if ((Main.allowPFeather) && ((lde.entityLiving instanceof EntityPlayer)))
    {
      EntityPlayer ep = (EntityPlayer)lde.entityLiving;
  	if (((EntityLivingBase) ep).isPotionActive(ItemRegistry1.customPotion2))
      {
        if (!ep.worldObj.isRemote)
        {
        	 lde.setCanceled(true);
        	 
          ep.worldObj.playSoundAtEntity(ep, "fireworks.launch", 5.0F, 1.0F);
          ep.worldObj.playSoundAtEntity(ep, "assets.speedboost", 0.4F, 0.3F);
          ((EntityLivingBase) ep).removePotionEffect(ItemRegistry1.customPotion2.id);
        }
       
       
      }
    }
  }
 
Example 12
Project: ToroQuest   File: ItemReinforcedDiamondArmor.java   View source code 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 13
Project: 3DManeuverGear   File: EntityLivingHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
@SuppressWarnings("unused")
public void onPlayerFall(LivingHurtEvent event) {
    if(!(event.getEntity() instanceof EntityPlayer)) {
        return;
    }
    if(!event.getSource().damageType.equals(DamageSource.FALL.getDamageType())) {
        return;
    }
    EntityPlayer player = (EntityPlayer) event.getEntity();
    ItemStack boots = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
    if(boots != null && boots.getItem() == ItemRegistry.getInstance().itemFallBoots) {
        event.setAmount((1.0F-ConfigurationHandler.getInstance().bootFallDamageReduction)*event.getAmount());
    }

}
 
Example 14
Project: TeleToro   File: Teletory.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void fallOutOfTeletory(LivingHurtEvent ev) {
	if (ev.getEntity().getEntityWorld().isRemote || !(ev.getEntity() instanceof EntityPlayerMP)) {
		return;
	}

	if (ev.getSource() != DamageSource.OUT_OF_WORLD) {
		return;
	}

	EntityPlayerMP thePlayer = (EntityPlayerMP) ev.getEntity();

	if (thePlayer.dimension != Teletory.DIMID) {
		return;
	}
	ev.setCanceled(true);
	changeEntityDimension(thePlayer, TeleportorType.FALL);
}
 
Example 15
Project: Inhuman-Resources   File: EventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onEntityAttacked(LivingHurtEvent event)
{
	Entity sourceEntity = event.getSource().getTrueSource();
	if (sourceEntity instanceof EntityLivingBase)
	{
		EntityLivingBase target = event.getEntityLiving();
		if (target == null)
			return;
		EntityLivingBase attacker = (EntityLivingBase) sourceEntity;
		ItemStack weapon = attacker.getHeldItemMainhand();
		ItemStack offhand = attacker.getHeldItemOffhand();
		if (offhand != null && offhand.getItem() instanceof IUpgradable)
			((IUpgradable) weapon.getItem()).onAttackEntity(event, attacker, target, weapon, offhand);
		if (weapon != null && weapon.getItem() instanceof IUpgradable)
			((IUpgradable) weapon.getItem()).onAttackEntity(event, attacker, target, weapon, offhand);
	}
}
 
Example 16
Project: Lost-Eclipse-Outdated   File: EventFlameCloak.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void hasFlameCloak(LivingHurtEvent event)
{
	if (event.getEntityLiving() instanceof EntityPlayer && event.getSource().getSourceOfDamage() instanceof EntityLivingBase)
	{
		EntityPlayer player = (EntityPlayer) event.getEntityLiving();
		EntityLivingBase attacker = (EntityLivingBase) event.getSource().getSourceOfDamage();
		
		if (player != null && attacker != null)
		{
			IFlameCloak flameCloak = player.getCapability(CapabilityFlameCloak.FLAME_CLOAK_CAP, null);
			
			if (flameCloak != null && flameCloak.hasFlameCloak())
			{
				attacker.setFire(5);
			}
		}
	}
}
 
Example 17
Project: Event-Tweaks   File: MobEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void hurtEvents(LivingHurtEvent e) {
    if (!e.getEntity().getEntityWorld().isRemote) {
        DamageSource source = e.getSource();
        Entity entity = e.getEntity();

        if (entity == null || entity.isDead) {
            return;
        }

        if (source == DamageSource.drown && entity.isWet() && entity instanceof EntityPlayer && ConfigurationFile.hardcoreAir) {
            ((EntityPlayer) entity).setHealth(0.0f);
        } else if (source == DamageSource.starve && entity instanceof EntityPlayer && ConfigurationFile.hardcoreHunger) {
            ((EntityPlayer) entity).setHealth(0.0f);
        } else if (source.getEntity() instanceof EntityPlayer && ConfigurationFile.mobsRevengeMode) {
            if (!(entity instanceof EntityPlayer) && entity instanceof EntityLiving) {
                ((EntityLiving) entity).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 100, 1));
            }
        }
    }
}
 
Example 18
Project: Coding   File: DragonPlayerEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
	public void onLivingHurtEvent(LivingHurtEvent event) {
		if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer && DragonPlayer.get((EntityPlayer) event.entity).isDragon()) {
			if (event.source.equals(DamageSource.lava) || event.source.equals(DamageSource.onFire) || event.source.equals(DamageSource.inFire)) {
				event.setCanceled(true);
//				LogHelper.info("DragonPlayerEventHandler: onLivingHurtEvent, no damage from lava!");
			}
			// Damage yourself (probably an explosion)
			else if (BALANCE.DRAGON_PLAYER_ABILITIES.RECEIVE_EXPLODING_FIREBALL_DAMAGE == false && event.source.isExplosion()) {
				event.setCanceled(true);
			}
			else if (ItemDragonEgg.hasAbility((EntityPlayer) event.entity, Abilities.NOBLOCKDAMAGE) && event.source.equals(DamageSource.inWall)) {
				event.setCanceled(true);
	        }
			else if (event.source.equals(DamageSource.fall)) {
				event.setCanceled(true);
			}
			// Prevent damage from entities that are picked up (that ride the dragon)
			else if (event.entity.riddenByEntity != null) {
				event.setCanceled(true);				
			}
		}
	}
 
Example 19
Project: Kingdom-Keys-Re-Coded   File: DriveFormLimit.java   View source code 6 votes vote down vote up
@SubscribeEvent
public static void getXP(LivingHurtEvent event) {
       if (event.getSource().getImmediateSource() instanceof EntityPlayer) {
       	EntityPlayer player = (EntityPlayer) event.getSource().getImmediateSource();
       	
           PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
           DriveStateCapability.IDriveState DRIVE = player.getCapability(ModCapabilities.DRIVE_STATE, null);

           if(DRIVE.getActiveDriveName().equals(Strings.Form_Limit)) {
           	DRIVE.setDriveExp(DRIVE.getActiveDriveName(), DRIVE.getDriveExp(DRIVE.getActiveDriveName())+1);
           
            int[] costs = DriveFormRegistry.get(DRIVE.getActiveDriveName()).getExpCosts();
            int actualLevel = DRIVE.getDriveLevel(DRIVE.getActiveDriveName());
            int actualExp = DRIVE.getDriveExp(DRIVE.getActiveDriveName());
           
            if(costs.length == 7 && actualLevel < 7) {
            	if (actualExp >= costs[actualLevel]){
            		System.out.println("LEVEL UP");
            		DRIVE.setDriveLevel(DRIVE.getActiveDriveName(),actualLevel+1); 
                    DRIVE.displayLevelUpMessage(player, DRIVE.getActiveDriveName());
            	}
            }
            PacketDispatcher.sendTo(new SyncDriveData(DRIVE), (EntityPlayerMP) player);
           }
       }
}
 
Example 20
Project: Kingdom-Keys-Re-Coded   File: DriveFormValor.java   View source code 6 votes vote down vote up
@SubscribeEvent
public static void getXP(LivingHurtEvent event) {
       if (event.getSource().getImmediateSource() instanceof EntityPlayer) {
       	EntityPlayer player = (EntityPlayer) event.getSource().getImmediateSource();
       	
           PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
           DriveStateCapability.IDriveState DRIVE = player.getCapability(ModCapabilities.DRIVE_STATE, null);

       	if(DRIVE.getActiveDriveName().equals(Strings.Form_Valor)) {
       		DRIVE.setDriveExp(DRIVE.getActiveDriveName(), DRIVE.getDriveExp(DRIVE.getActiveDriveName())+1);
            
            int[] costs = DriveFormRegistry.get(DRIVE.getActiveDriveName()).getExpCosts();
            int actualLevel = DRIVE.getDriveLevel(DRIVE.getActiveDriveName());
            int actualExp = DRIVE.getDriveExp(DRIVE.getActiveDriveName());
           
            if(costs.length == 7 && actualLevel < 7) {
            	if (actualExp >= costs[actualLevel]){
            		System.out.println("LEVEL UP");
            		DRIVE.setDriveLevel(DRIVE.getActiveDriveName(),actualLevel+1); 
                    DRIVE.displayLevelUpMessage(player, DRIVE.getActiveDriveName());
            	}
            }
            PacketDispatcher.sendTo(new SyncDriveData(DRIVE), (EntityPlayerMP) player);
       	}
       }
}
 
Example 21
Project: Cyclic   File: ItemSoulstone.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onPlayerHurt(LivingHurtEvent event) {
  if (event.getEntityLiving().getHealth() - event.getAmount() <= 0 && event.getEntityLiving() instanceof EntityPlayer) {
    EntityPlayer p = (EntityPlayer) event.getEntityLiving();
    for (int i = 0; i < p.inventory.getSizeInventory(); ++i) {
      ItemStack s = p.inventory.getStackInSlot(i);
      if (s.getItem() instanceof ItemSoulstone) {
        UtilChat.addChatMessage(p, event.getEntityLiving().getName() + UtilChat.lang("item.soulstone.used"));
        p.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
        UtilSound.playSound(p, SoundEvents.BLOCK_GLASS_BREAK);
        p.setHealth(6);// 3 hearts
        int time = Const.TICKS_PER_SEC * 30;
        p.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, time));
        time = Const.TICKS_PER_SEC * 60;//a full minute
        p.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, time));
        p.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, time, 4));
        //and bad luck lasts much longer
        time = Const.TICKS_PER_SEC * 60 * 10;
        p.addPotionEffect(new PotionEffect(MobEffects.UNLUCK, time));
        p.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, time, 1));
        event.setCanceled(true);
        break;
      }
    }
  }
}
 
Example 22
Project: ComponentEquipment   File: ArmorProtectionApplier.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLivingHurt( LivingHurtEvent event )
{
	if ( event.source.isUnblockable() )
	{
		return;
	}
	
	/*
	event.entityLiving.damageArmor( event.ammount );
	
	int prot = Armor.getProtectionOf( event.entityLiving );
	int num = ( event.ammount * prot ) + event.entityLiving.carryoverDamage;
	*/
	//for(int i=0;i<5;++i)System.out.println("");
}
 
Example 23
Project: ComponentEquipment   File: KnockbackEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onEntityHurt( LivingHurtEvent event )
{
	EntityLivingBase entity = event.entityLiving;
	double resist = entity.getEntityAttribute( SharedMonsterAttributes.knockbackResistance ).getAttributeValue();
	/*
	for ( int i = 0; i < 5; ++i )
	{
		ItemStack stack = entity.getCurrentItemOrArmor( i );
		if ( stack == null )
		{
			continue;
		}
		
		stack.getAttributeModifiers();
	}
	*/
	
	for ( Object o : entity.getAttributeMap().getAllAttributes() )
	{
		IAttributeInstance attr = (IAttributeInstance)o;
		// TODO: Reduce momentum instead of random avoidance
	}
	//entity.setVelocity( entity.motionX * resist, entity.motionY, entity.motionZ * resist );
}
 
Example 24
Project: Et-Futurum   File: ServerEventHandler.java   View source code 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 25
Project: grapplemod   File: LongFallBoots.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLivingHurtEvent(LivingHurtEvent event) {
	if (event.getEntity() != null && event.getEntity() instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer)event.getEntity();
		
		for (ItemStack armor : player.getArmorInventoryList()) {
		    if (armor != null && armor.getItem() instanceof LongFallBoots)
		    {
		    	if (event.getSource() == DamageSource.FLY_INTO_WALL) {
		    		System.out.println("Flew into wall");
					// this cancels the fall event so you take no damage
					event.setCanceled(true);
		    	}
		    }
		}
	}
}
 
Example 26
Project: Minecraft-Modding   File: ArmorHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void shieldAbsorbDamage(LivingHurtEvent event)
{
	if (!event.source.isUnblockable())
	{
		ScienceShield shield = ScienceShield.loadShieldForEntity(event.entityLiving);
		float dmgRemaining = shield.tryAbsorbDamage(event.ammount);
		if (dmgRemaining <= 0) {
			event.setCanceled(true);
		}
		else {
			event.ammount = dmgRemaining;
		}
		shield.save();
	}
}
 
Example 27
Project: Gadomancy   File: EventHandlerGolem.java   View source code 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 28
Project: sprinkles_for_vanilla   File: PlayerHandlers.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onHurt(LivingHurtEvent event)
{
    if (event.entity instanceof EntityPlayer && SprinklesForVanilla.isOnServer)
    {
        EntityPlayer player = (EntityPlayer) event.entity;
        if (player.getHealth() - event.ammount <= 0)
        {
            PlayerProperties props = (PlayerProperties) player.getExtendedProperties(ModInfo.MOD_NAME);
            props.health = player.getHealth();
            props.hunger = player.getFoodStats().getFoodLevel();
            props.experience = player.experience;
            props.experienceLevel = player.experienceLevel;
            props.experienceTotal = player.experienceTotal;
            playerMap.put(player.getPersistentID(), props);
        }
    }
}
 
Example 29
Project: sprinkles_for_vanilla   File: EntityHandlers.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event)
{
    DamageSource source = event.source;
    if (source.damageType == "player" && SprinklesForVanilla.isOnServer && event.ammount > 0)
    {
        EntityPlayer player = (EntityPlayer)((EntityDamageSource)source).getEntity();
        if (player != null)
        {
            ItemStack heldItem = player.getCurrentEquippedItem();
            if (heldItem != null)
            {
                Multimap attribMap = heldItem.getAttributeModifiers();
                //If held item doesn't change the base damage
                if (!attribMap.containsKey(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()))
                {
                    event.ammount *= Settings.playerPunchDamageMultiplier[1];
                }
            }
            else
            {
                event.ammount *= Settings.playerPunchDamageMultiplier[1];
            }
        }
    }
}
 
Example 30
Project: Blockbender   File: PassiveListener.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onEntityDamage(LivingHurtEvent event) {
	/* Less fire damage */
	if (event.entity instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) event.entity;
		if (ElementManager.hasElement(player, ElementManager.FIRE)) {
			if (event.source == DamageSource.inFire || event.source == DamageSource.onFire) {
				if (player.getRNG().nextInt(3) == 0) {
					event.ammount = 1;
				}
				else {
					event.ammount = 0;
				}
			}
		}
	}
}
 
Example 31
Project: GaiaMod   File: GaiaModEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event) {
	EntityLivingBase attackedEntity = event.entityLiving;
	Entity attackerEntity = event.source.getEntity();

	if (event.source.getSourceOfDamage() instanceof EntityArrow
			&& ((hasEquippedSet(attackerEntity, ModArmor.stormHelmet,
					ModArmor.stormChest, ModArmor.stormLeggings,
					ModArmor.stormBoots))
					|| (hasEquippedSet(attackerEntity,
							ModArmor.chaosHelmet, ModArmor.chaosChest,
							ModArmor.chaosLeggings, ModArmor.chaosBoots)) || (hasEquippedSet(
						attackerEntity, ModArmor.orderHelmet,
						ModArmor.orderChest, ModArmor.orderLeggings,
						ModArmor.orderBoots)))) {
		double i = attackedEntity.posX;
		double j = attackedEntity.posY;
		double k = attackedEntity.posZ;

		EntityLightningBolt entityLightningBolt = new EntityLightningBolt(
				attackerEntity.worldObj, i, j, k);
		attackerEntity.worldObj.addWeatherEffect(entityLightningBolt);
	}
}
 
Example 32
Project: ZeldaSwordSkills   File: ZSSCombatEvents.java   View source code 6 votes vote down vote up
/**
 * Pre-event to handle shield blocking (only posted when not in BG2 battle mode)
 */
@SubscribeEvent(priority=EventPriority.NORMAL)
public void onPreHurt(LivingHurtEvent event) {
	if (event.entity instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) event.entity;
		ItemStack stack = player.getHeldItem();
		if (stack != null && stack.getItem() instanceof ItemZeldaShield && player.isUsingItem()) {
			ItemZeldaShield shield = (ItemZeldaShield) stack.getItem();
			if (ZSSPlayerInfo.get(player).canBlock() && shield.canBlockDamage(stack, event.source)) {
				Entity opponent = event.source.getEntity();
				if (opponent != null && TargetUtils.isTargetInFrontOf(opponent, player, 60)) {
					event.ammount = shield.onBlock(player, stack, event.source, event.ammount);
					event.setCanceled(event.ammount < 0.1F);
				}
			}
		}
	}
}
 
Example 33
Project: ZeldaSwordSkills   File: SwordBasic.java   View source code 6 votes vote down vote up
@Override
public void onHurtTarget(EntityPlayer player, LivingHurtEvent event) {
	if (!isLockedOn() || !isValidComboDamage(player, event.source)) { return; }
	if (combo == null || combo.isFinished()) {
		combo = new Combo(player, this, getMaxComboSize(), getComboTimeLimit());
	}
	float damage = DirtyEntityAccessor.getModifiedDamage(event.entityLiving, event.source, event.ammount);
	if (damage > 0) {
		if (!(event.source instanceof IComboDamageFull) || ((IComboDamageFull) event.source).increaseComboCount(player)) {
			combo.add(player, event.entityLiving, damage);
		} else {
			combo.addDamageOnly(player, damage, ((IComboDamageFull) event.source).applyDamageToPrevious(player));
		}
	}
	String sound = getComboDamageSound(player, event.source);
	if (sound != null) {
		WorldUtils.playSoundAtEntity(player, sound, 0.4F, 0.5F);
	}
}
 
Example 34
Project: ModTutoriel17   File: LivingEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event)
{
    ItemStack boots = event.entityLiving.getEquipmentInSlot(1);
    ItemStack leggings = event.entityLiving.getEquipmentInSlot(2);
    ItemStack chestPlate = event.entityLiving.getEquipmentInSlot(3);
    ItemStack helmet = event.entityLiving.getEquipmentInSlot(4);

    if(boots != null && boots.getItem() == ModTutoriel.bootsTuto && leggings != null && leggings.getItem() == ModTutoriel.leggingsTuto && chestPlate != null && chestPlate.getItem() == ModTutoriel.chestPlateTuto && helmet != null && helmet.getItem() == ModTutoriel.helmetTuto)
    {
        if(event.source.getEntity() != null && event.source.getEntity() instanceof EntityCreeper)
        {
            boots.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            leggings.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            chestPlate.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            helmet.damageItem(MathHelper.floor_float(event.ammount / 4), event.entityLiving);
            event.ammount = 0F;
        }
        else if(event.source.getDamageType().equals("cactus"))
        {
            event.entityLiving.worldObj.newExplosion(event.entityLiving, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, event.ammount, true, true);
        }
    }
}
 
Example 35
Project: GriefGuardian   File: ClaimGuardEventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onEntityHurt(LivingHurtEvent event){
	if (event.entity.worldObj.isRemote)
		return;

	EntityPlayer player = null;
	if (event.source.getSourceOfDamage() != null && event.source.getSourceOfDamage() instanceof EntityPlayer){
		player = (EntityPlayer)event.source.getSourceOfDamage();
	}
	if (player == null)
		return;

	if (event.entity instanceof EntityPlayer)
		if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(player, PermissionsMutex.HARM_PLAYERS, event.entity.posX, event.entity.posY, event.entity.posZ))
			event.setCanceled(true);

	if (event.entity instanceof EntityCreature)
		if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(player, PermissionsMutex.HARM_CREATURES, event.entity.posX, event.entity.posY, event.entity.posZ))
			event.setCanceled(true);

	if (event.entity instanceof EntityMob)
		if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(player, PermissionsMutex.HARM_MONSTERS, event.entity.posX, event.entity.posY, event.entity.posZ))
			event.setCanceled(true);
}
 
Example 36
Project: Morph   File: EventHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event)
{
    if(event.source.getEntity() instanceof EntityPlayerMP && !(event.source instanceof EntityDamageSourceIndirect))
    {
        EntityPlayer player = (EntityPlayer)event.source.getEntity();
        MorphInfo info = Morph.proxy.tickHandlerServer.getPlayerMorphInfo(player);

        if(info != null && player.getCurrentEquippedItem() == null)
        {
            for(Ability ab : info.morphAbilities)
            {
                if(ab instanceof AbilityPotionEffect)
                {
                    AbilityPotionEffect abPot = (AbilityPotionEffect)ab;
                    event.entityLiving.addPotionEffect(new PotionEffect(abPot.potionId, abPot.duration, abPot.amplifier, abPot.ambient));
                }
            }
        }
    }
}
 
Example 37
Project: Artifacts   File: ComponentAdrenaline.java   View source code 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 38
Project: Bewitchment   File: ItemSilverArmor.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onEntityDamage(LivingHurtEvent event) {
	DamageSource source = event.getSource();

	Entity attacker = source.getTrueSource();
	if ((attacker instanceof EntityLivingBase) && ((EntityLivingBase) attacker).getCreatureAttribute() == EnumCreatureAttribute.UNDEAD) {
		event.setAmount(event.getAmount() * 0.95F);
	}
}
 
Example 39
Project: Bewitchment   File: ShellArmorBrew.java   View source code 5 votes vote down vote up
@Override
public void onHurt(LivingHurtEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
	Entity attacker = source.getImmediateSource();
	int redo = 5 - amplifier;
	if (attacker != null && (redo < 0 || attacker.world.rand.nextInt(redo) == 0)) {
		float damage = event.getAmount();
		attacker.attackEntityFrom(DamageSource.causeThornsDamage(affected), damage);
	}
}
 
Example 40
Project: Bewitchment   File: OvercoatBrew.java   View source code 5 votes vote down vote up
@Override
public void onHurt(LivingHurtEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
	Entity attacker = source.getImmediateSource();
	if (attacker != null) {
		event.setCanceled(true);
	}
}