net.minecraft.util.EntityDamageSource Java Examples

The following examples show how to use net.minecraft.util.EntityDamageSource. 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: ToolMetaItem.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
    T metaValueItem = getItem(stack);
    if (metaValueItem != null) {
        IToolStats toolStats = metaValueItem.getToolStats();
        if (!damageItem(stack, toolStats.getToolDamagePerEntityAttack(stack), false)) {
            return true;
        }
        float additionalDamage = toolStats.getNormalDamageBonus(target, stack, attacker);
        float additionalMagicDamage = toolStats.getMagicDamageBonus(target, stack, attacker);
        if (additionalDamage > 0.0f) {
            target.attackEntityFrom(new EntityDamageSource(attacker instanceof EntityPlayer ? "player" : "mob", attacker), additionalDamage);
        }
        if (additionalMagicDamage > 0.0f) {
            target.attackEntityFrom(new EntityDamageSource("indirectMagic", attacker), additionalMagicDamage);
        }
    }
    return true;
}
 
Example #2
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 #3
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, double damage) {
    if (entity instanceof EntityEnderCrystal && !(source instanceof EntityDamageSource)) {
        return false;
    }

    final EnumMap<DamageModifier, Double> modifiers = new EnumMap<DamageModifier, Double>(DamageModifier.class);
    final EnumMap<DamageModifier, Function<? super Double, Double>> functions = new EnumMap(DamageModifier.class);

    modifiers.put(DamageModifier.BASE, damage);
    functions.put(DamageModifier.BASE, ZERO);

    final EntityDamageEvent event = handleEntityDamageEvent(entity, source, modifiers, functions);
    if (event == null) {
        return false;
    }
    return event.isCancelled() || (event.getDamage() == 0 && !(entity instanceof EntityItemFrame)); // Cauldron - fix frame removal
}
 
Example #4
Source File: EntityFluidCow.java    From Moo-Fluids with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean attackEntityFrom(final DamageSource damageSource, final float damageAmount) {
  if (damageSource instanceof EntityDamageSource) {
    EntityDamageSource entityDamageSource = (EntityDamageSource)damageSource;
    if (entityDamageSource.getTrueSource() instanceof EntityPlayer) {
      final EntityPlayer entityPlayer = (EntityPlayer) damageSource.getTrueSource();
      if (entityPlayer.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
        applyDamagesToEntity(entityPlayer);
      }
    }
  }
  return super.attackEntityFrom(damageSource, damageAmount);
}
 
Example #5
Source File: JetpackPotato.java    From SimplyJetpacks with MIT License 5 votes vote down vote up
@Override
public void flyUser(EntityLivingBase user, ItemStack stack, ItemPack item, boolean force) {
    if (this.isFired(stack)) {
        super.flyUser(user, stack, item, true);
        user.rotationYawHead += 37.5F;
        if (item.getFuelStored(stack) <= 0) {
            user.setCurrentItemOrArmor(3, null);
            if (!user.worldObj.isRemote) {
                user.worldObj.createExplosion(user, user.posX, user.posY, user.posZ, 4.0F, false);
                for (int i = 0; i <= MathHelper.RANDOM.nextInt(3) + 4; i++) {
                    ItemStack firework = FireworksHelper.getRandomFireworks(0, 1, MathHelper.RANDOM.nextInt(6) + 1, 1);
                    user.worldObj.spawnEntityInWorld(new EntityFireworkRocket(user.worldObj, user.posX + MathHelper.RANDOM.nextDouble() * 6.0D - 3.0D, user.posY, user.posZ + MathHelper.RANDOM.nextDouble() * 6.0D - 3.0D, firework));
                }
                user.attackEntityFrom(new EntityDamageSource("jetpackpotato", user), 100.0F);
                if (user instanceof EntityPlayer) {
                    user.dropItem(Items.baked_potato, 1);
                }
            }
        }
    } else {
        if (force || SyncHandler.isFlyKeyDown(user)) {
            if (this.isTimerSet(stack)) {
                this.decrementTimer(stack, user);
            } else {
                this.setTimer(stack, 50);
            }
        }
    }
}
 
Example #6
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 #7
Source File: EntityFallTofu.java    From TofuCraftReload with MIT License 5 votes vote down vote up
protected void onImpact(RayTraceResult result) {
    if (!this.world.isRemote) {
        if (result.entityHit != null) {
            if (this.owner == null) {
                DamageSource damagesource = DamageSource.FALLING_BLOCK;
                result.entityHit.attackEntityFrom(damagesource, 5);
            } else {
                result.entityHit.attackEntityFrom(new EntityDamageSource("fallingBlock", this.owner), 5);
            }
        }
    }
}
 
Example #8
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
private boolean isPoweredCreeper(DamageSource source) {
	if (source.isExplosion() && source instanceof EntityDamageSource) {
		Entity entity = ((EntityDamageSource) source).getEntity();
		if (entity != null && entity instanceof EntityCreeper)
			return ((EntityCreeper) entity).getPowered();
	}

	return false;
}
 
Example #9
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 #10
Source File: LightningTracker.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void tick(TickEvent.WorldTickEvent event) {
	newEntries.forEach(e -> entityToEntry.put(e.getTarget(), e));
	newEntries.clear();
	
	entityToEntry.keySet().removeIf(entity -> {
		TrackingEntry entry = entityToEntry.get(entity);
		Entity caster = entry.getCaster();
		int ticks = entry.getTicks();
		double potency = entry.getPotency();
		double duration = entry.getDuration();
		
		if (ticks > 0) {
			entry.setTicks(ticks - 1);
			return false;
		}

		entity.setFire((int) duration);
	
		int invTime = entity.hurtResistantTime;
		entity.hurtResistantTime = 0;
		if (caster instanceof EntityPlayer)
			entity.attackEntityFrom(new EntityDamageSource("lightningbolt", caster), (float) potency);
		else entity.attackEntityFrom(DamageSource.LIGHTNING_BOLT, (float) potency);
		entity.hurtResistantTime = invTime;
		return true;
	});
}
 
Example #11
Source File: DamageSourceThaumcraft.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public static DamageSource causeTentacleDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("tentacle", par0EntityLiving);
}
 
Example #12
Source File: EntityEnderminy.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
/**
 * Called when the entity is attacked.
 */
@Override
public boolean attackEntityFrom(DamageSource damageSource, float p_70097_2_) {

  if(isEntityInvulnerable(damageSource)) {
    return false;
  }

  setScreaming(true);

  if(damageSource instanceof EntityDamageSourceIndirect) {
    isAggressive = false;
    for (int i = 0; i < 64; ++i) {
      if(teleportRandomly()) {
        return true;
      }
    }
    return super.attackEntityFrom(damageSource, p_70097_2_);
  }

  boolean res = super.attackEntityFrom(damageSource, p_70097_2_);
  if(damageSource instanceof EntityDamageSource && damageSource.getTrueSource() instanceof EntityPlayer &&
      getHealth() > 0
  //&& !ItemDarkSteelSword.isEquippedAndPowered((EntityPlayer) damageSource.getEntity(), 1)) {
  ) {
    isAggressive = true;
    if(rand.nextInt(3) == 0) {
      for (int i = 0; i < 64; ++i) {
        if(teleportRandomly(16)) {
          setAttackTarget((EntityPlayer) damageSource.getTrueSource());
          doGroupArgo();
          return true;
        }
      }
    }
  }

  if(res) {
    doGroupArgo();
  }
  return res;

}
 
Example #13
Source File: DamageSourceThaumcraft.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public static DamageSource causeSwarmDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("swarm", par0EntityLiving);
}
 
Example #14
Source File: UpgradeKilling.java    From BetterChests with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static DamageSource getDamageSource(EntityPlayer source) {
	return source == null ? DAMAGE_SOURCE : new EntityDamageSource(DAMAGE_DESC, source);
}
 
Example #15
Source File: DamageSourceThaumcraft.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static DamageSource causeSwarmDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("swarm", par0EntityLiving);
}
 
Example #16
Source File: DamageSourceThaumcraft.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static DamageSource causeTentacleDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("tentacle", par0EntityLiving);
}
 
Example #17
Source File: DamageSourceThaumcraft.java    From GardenCollection with MIT License 4 votes vote down vote up
public static DamageSource causeTentacleDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("tentacle", par0EntityLiving);
}
 
Example #18
Source File: DamageSourceThaumcraft.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
public static DamageSource causeTentacleDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("tentacle", par0EntityLiving);
}
 
Example #19
Source File: DamageSourceThaumcraft.java    From GardenCollection with MIT License 4 votes vote down vote up
public static DamageSource causeSwarmDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("swarm", par0EntityLiving);
}
 
Example #20
Source File: DamageSourceThaumcraft.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
public static DamageSource causeTentacleDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("tentacle", par0EntityLiving);
}
 
Example #21
Source File: DamageSourceThaumcraft.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
public static DamageSource causeSwarmDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("swarm", par0EntityLiving);
}
 
Example #22
Source File: DamageSourceThaumcraft.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
public static DamageSource causeSwarmDamage(EntityLivingBase par0EntityLiving)
{
    return new EntityDamageSource("swarm", par0EntityLiving);
}
 
Example #23
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));
				}
			}
		}
	}
}
 
Example #24
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 #25
Source File: PotionCrash.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public DamageSource damageSourceEarthquake(EntityLivingBase player) {
	return new EntityDamageSource("wizardry.crash", player);
}
 
Example #26
Source File: DamageSources.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static DamageSource causeCombatDamage(String type, EntityLivingBase damager) {
    return new EntityDamageSource(type, damager);
}
 
Example #27
Source File: DamageSources.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static DamageSource causeElectricDamage(EntityLivingBase damager) {
    return new EntityDamageSource(ELECTRIC.getDamageType(), damager).setDamageBypassesArmor();
}