Java Code Examples for net.minecraft.entity.EntityLivingBase#attackEntityFrom()

The following examples show how to use net.minecraft.entity.EntityLivingBase#attackEntityFrom() . These examples are extracted from open source projects. 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
@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 Project: Cyberware   File: ItemCyberheart.java    License: MIT License 6 votes vote down vote up
@SubscribeEvent(priority=EventPriority.HIGHEST)
public void power(CyberwareUpdateEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	ItemStack test = new ItemStack(this);
	if (e.ticksExisted % 20 == 0 && CyberwareAPI.isCyberwareInstalled(e, test))
	{
		if (!CyberwareAPI.getCapability(e).usePower(test, getPowerConsumption(test)))
		{
			e.attackEntityFrom(EssentialsMissingHandler.heartless, Integer.MAX_VALUE);
		}
	}
	
	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this)))
	{
		e.removePotionEffect(MobEffects.WEAKNESS);
	}
}
 
Example 3
@Override
public void tick(int ticksSoFar, World world, EntityPlayer parent, ItemStack itemStack) {
    int rangeInc = ((ItemFamiliar_Old) itemStack.getItem()).getAttackRangeIncrease(itemStack);

    List<EntityLivingBase> lastTargetters = getPotentialTargets(world, parent, rangeInc);
    if(lastTargetters.size() == 0) {
        FamiliarAIController_Old.cleanTargetterList(parent);
        return;
    }
    EntityLivingBase mob = lastTargetters.get(world.rand.nextInt(lastTargetters.size()));
    if(mob.isDead || mob instanceof EntityPlayer) {
        FamiliarAIController_Old.cleanTargetterList(parent);
        return;
    }

    mob.attackEntityFrom(DamageSource.magic, ((ItemFamiliar_Old) itemStack.getItem()).getAttackStrength(itemStack));

    world.playSoundEffect(mob.posX + 0.5, mob.posY + 0.5, mob.posZ + 0.5, "thaumcraft:zap", 0.8F, 1.0F);

    PacketFamiliarBolt bolt = new PacketFamiliarBolt(parent.getCommandSenderName(), (float) mob.posX, (float) mob.posY, (float) mob.posZ, 6, true);
    PacketHandler.INSTANCE.sendToAllAround(bolt, new NetworkRegistry.TargetPoint(mob.worldObj.provider.dimensionId, mob.posX, mob.posY, mob.posZ, 32));
    FamiliarAIController_Old.cleanTargetterList(parent);
}
 
Example 4
@Override
public void performEffect(EntityLivingBase target, int par2) {
	if (target instanceof ITaintedMob) {
		target.heal(1);
	} else
	if (!target.isEntityUndead() && !(target instanceof EntityPlayer))
       {
		target.attackEntityFrom(DamageSourceThaumcraft.taint, 1);
       } 
	else
	if (!target.isEntityUndead() && (target.getMaxHealth() > 1 || (target instanceof EntityPlayer)))
       {
		target.attackEntityFrom(DamageSourceThaumcraft.taint, 1);
       } 
}
 
Example 5
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    if (ElectricItem.manager.use(itemstack, hitCost, attacker)) {
        entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 8F);
    }
    return false;
}
 
Example 6
@Override
public void performEffect(EntityLivingBase target, int par2) {
	if (target instanceof ITaintedMob) {
		target.heal(1);
	} else
	if (!target.isEntityUndead() && !(target instanceof EntityPlayer))
       {
		target.attackEntityFrom(DamageSourceThaumcraft.taint, 1);
       } 
	else
	if (!target.isEntityUndead() && (target.getMaxHealth() > 1 || (target instanceof EntityPlayer)))
       {
		target.attackEntityFrom(DamageSourceThaumcraft.taint, 1);
       } 
}
 
Example 7
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    if (ElectricItem.manager.use(itemstack, hitCost, attacker)) {
        entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 12F);
    }
    return false;
}
 
Example 8
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
	if (!(attacker instanceof EntityPlayer)) {
		return true;
	} else {
		if (ElectricItem.manager.canUse(stack, this.operationEnergyCost)) {
			attacker.world.addWeatherEffect(new EntityLightningBolt(attacker.world, target.lastTickPosX, target.lastTickPosY, target.lastTickPosZ, false));
			ElectricItem.manager.use(stack, this.operationEnergyCost, attacker);
		} else {
			target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 1.0F);
		}
		return false;
	}
}
 
Example 9
private void damageEntity(EntityLivingBase target, Entity caster, float damage) {
	int invTime = target.hurtResistantTime;
	target.hurtResistantTime = 0;
	if (caster instanceof EntityLivingBase) {
		((EntityLivingBase) caster).setLastAttackedEntity(target);
		if (caster instanceof EntityPlayer)
			target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) caster).setMagicDamage(), damage);
		else
			target.attackEntityFrom(new DamageSource("generic").setMagicDamage(), damage);
	} else
		target.attackEntityFrom(new DamageSource("generic").setMagicDamage(), damage);
	target.hurtResistantTime = invTime;
}
 
Example 10
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    if (ElectricItem.manager.use(itemstack, hitCost, attacker)) {
        entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 12F);
    }
    return false;
}
 
Example 11
/**
 * Updates the task
 */
public void updateTask() {
	EntityLivingBase entitylivingbase = this.theEntity.getAttackTarget();
	this.theEntity.getNavigator().clearPath();
	this.theEntity.getLookHelper().setLookPositionWithEntity(entitylivingbase, 90.0F, 90.0F);

	if (!this.theEntity.canEntityBeSeen(entitylivingbase)) {
		this.theEntity.setAttackTarget((EntityLivingBase) null);
	} else {
		++this.tickCounter;

		if (this.tickCounter == 0) {
			this.theEntity.setTargetedEntity(this.theEntity.getAttackTarget().getEntityId());
			// this.theEntity.world.setEntityState(this.theEntity,
			// (byte) 21);
		} else if (this.tickCounter >= this.theEntity.getAttackDuration()) {
			float damage = 3.0F;

			if (this.theEntity.world.getDifficulty() == EnumDifficulty.HARD) {
				damage += 3.0F;
			}

			DamageSource ds = DamageSource.causeIndirectMagicDamage(this.theEntity, this.theEntity);

			entitylivingbase.attackEntityFrom(ds, damage);
			entitylivingbase.attackEntityFrom(DamageSource.causeMobDamage(this.theEntity),
					(float) this.theEntity.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue());
			theEntity.attackedTarget = theEntity.getAttackTarget();
			theEntity.setAttackTarget((EntityLivingBase) null);
			theEntity.world.setEntityState(theEntity, (byte) 15);
			theEntity.playSound(SoundEvents.ENTITY_GENERIC_EXPLODE, 1.0F, 1.0F / (theEntity.getRNG().nextFloat() * 0.4F + 0.8F));
		}

		super.updateTask();
	}
}
 
Example 12
private void attack(EntityLivingBase toAttack, double damage, int boltType) {
    toAttack.attackEntityFrom(DamageSource.magic, (float) damage);
    toAttack.worldObj.playSoundEffect(toAttack.posX + 0.5, toAttack.posY + 0.5, toAttack.posZ + 0.5, "thaumcraft:zap", 0.8F, 1.0F);
    PacketFamiliarBolt bolt = new PacketFamiliarBolt(owningPlayer.getCommandSenderName(), (float) toAttack.posX, (float) toAttack.posY, (float) toAttack.posZ, boltType, true);
    PacketHandler.INSTANCE.sendToAllAround(bolt, new NetworkRegistry.TargetPoint(toAttack.worldObj.provider.dimensionId, owningPlayer.posX,
            owningPlayer.posY, owningPlayer.posZ, 16));
}
 
Example 13
public boolean tryFireMinigun(EntityLivingBase target){
    boolean lastShotOfAmmo = false;
    if(ammo != null && (pressurizable == null || pressurizable.getPressure(stack) > 0)) {
        setMinigunTriggerTimeOut(Math.max(10, getMinigunSoundCounter()));
        if(getMinigunSpeed() == MAX_GUN_SPEED && (!requiresTarget || gunAimedAtTarget)) {
            if(!requiresTarget) target = raytraceTarget();
            lastShotOfAmmo = ammo.attemptDamageItem(1, rand);
            if(pressurizable != null) pressurizable.addAir(stack, -airUsage);
            if(target != null) {
                ItemStack potion = ItemGunAmmo.getPotion(ammo);
                if(potion != null) {
                    if(rand.nextInt(20) == 0) {
                        List<PotionEffect> effects = Items.potionitem.getEffects(potion);
                        if(effects != null) {
                            for(PotionEffect effect : effects) {
                                target.addPotionEffect(new PotionEffect(effect));
                            }
                        }
                    }
                } else {
                    target.attackEntityFrom(DamageSource.causePlayerDamage(player), Config.configMinigunDamage);
                }
            }
        }
    }
    return lastShotOfAmmo;
}
 
Example 14
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    if (ElectricItem.manager.use(itemstack, hitCost, attacker)) {
        entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 10F);
    }
    return false;
}
 
Example 15
@Override
public void onWornTick(ItemStack stack, EntityLivingBase player) {
	if (!player.worldObj.isRemote) {
		if (stack != null && stack.getItemDamage() == 0) {
			if (player instanceof EntityPlayer) {
				((EntityPlayer) player).capabilities.disableDamage = true;

				wornTick++;

				NBTTagCompound tag = new NBTTagCompound();
				tag.setInteger("MindCorruption", wornTick);
				((EntityPlayer) player).writeToNBT(tag);
				int corruption = tag.getInteger("MindCorruption");
				if (tag != null && corruption != wornTick) {
					wornTick = corruption;
				}

				if (corruption <= 0)
					((EntityPlayer) player).addChatMessage(new ChatComponentText(TextHelper.PURPLE + "You have worn the Ring. Your soul has now been forever " + TextHelper.PURPLE + "tainted. " + TextHelper.RED + TextHelper.ITALIC + "Beware of wearing the ring. The tainting will only " + TextHelper.RED + TextHelper.ITALIC + "increase, and strange things will start happening."));

				if (corruption > 6000 && corruption < 24000 && random.nextInt(2000) == 0)
					player.addPotionEffect(new PotionEffect(Potion.blindness.id, 500, 2, false));

				if (corruption >= 6000 && corruption < 24000 && random.nextInt(2000) == 0)
					player.addPotionEffect(new PotionEffect(Potion.confusion.id, 500, 2, false));

				if (corruption >= 24000 && corruption < 72000 && random.nextInt(2000) == 0) {
					for (int i = 0; i <= 5; i++)
						((EntityPlayer) player).capabilities.disableDamage = false;

					player.attackEntityFrom(DamageSource.magic, 5);
				}

				if (corruption >= 72000 && corruption < 120000 && random.nextInt(4000) == 0) {
					for (int i = 0; i <= 100; i++)
						((EntityPlayer) player).capabilities.disableDamage = false;

					player.motionY = 2;
				}

				if (corruption >= 120000 && random.nextInt(10000) == 0) {
					for (int i = 0; i <= 510; i++)
						((EntityPlayer) player).capabilities.disableDamage = false;

					player.addPotionEffect(new PotionEffect(Potion.wither.id, 5000, 4, false));
				}
			}
		}
	}
}
 
Example 16
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    stack.damageItem(1, attacker);
    entityliving.attackEntityFrom(DamageSource.generic, damageAdded);
    return true;
}
 
Example 17
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 2F);
    itemstack.damageItem(1, attacker);
    return true;
}
 
Example 18
Source Project: Artifacts   File: DispenserBehaviorSword.java    License: MIT License 4 votes vote down vote up
/**
   * Dispense the specified stack, play the dispense sound and spawn particles.
   */
  public ItemStack dispenseStack(IBlockSource blockSource, ItemStack itemStack)
  {
      EnumFacing enumfacing = BlockDispenser.func_149937_b/*getFacing*/(blockSource.getBlockMetadata());
      double d0, d1, d2, d3, d4, d5;
      d0 = (int)blockSource.getX() - 1;
      d1 = (int)blockSource.getY() - 1;
      d2 = (int)blockSource.getZ() - 1;
      d3 = (int)blockSource.getX() + 1;
      d4 = (int)blockSource.getY() + 1;
      d5 = (int)blockSource.getZ() + 1;
      //System.out.println((int)par1IBlockSource.getX() + "," + (int)par1IBlockSource.getZ());
      d0 += 0.5 * d0/Math.abs(d0);
      d1 += 0.5 * d1/Math.abs(d1);
      d2 += 0.5 * d2/Math.abs(d2);
      d3 += 0.5 * d3/Math.abs(d3);
      d4 += 0.5 * d4/Math.abs(d4);
      d5 += 0.5 * d5/Math.abs(d5);
      
      d0 += enumfacing.getFrontOffsetX();
      d3 += enumfacing.getFrontOffsetX();
      d2 += enumfacing.getFrontOffsetZ();
      d5 += enumfacing.getFrontOffsetZ();
      
      if(enumfacing.getFrontOffsetX() != 0) {
      	d2 += 0.5;
      	d5 -= 0.5;
      }
      if(enumfacing.getFrontOffsetZ() != 0) {
      	d0 += 0.5;
      	d3 -= 0.5;
      }
      
      //Play sound.
      blockSource.getWorld().playAuxSFX(1002, blockSource.getXInt(), blockSource.getYInt(), blockSource.getZInt(), 0);
      
      AxisAlignedBB par2AxisAlignedBB = AxisAlignedBB.getBoundingBox(d0, d1, d2, d3, d4, d5);
      //System.out.println(par2AxisAlignedBB);
      List<EntityLivingBase> ents = blockSource.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, par2AxisAlignedBB);
      if(ents.size() > 0) {
      	for(int l=ents.size() - 1; l >= 0; l--) {
      		EntityLivingBase ent = ents.get(l);
      		ent.attackEntityFrom(DamageSourceSword.instance, damage);
      		itemStack.damageItem(1, ent);
      	}
      }
      TileEntity te = blockSource.getBlockTileEntity();
      if(te != null && te instanceof TileEntityTrap) {
      	TileEntityTrap tet = (TileEntityTrap) te;
	/*int a = par2ItemStack.getItem().itemID;
	int b = 0;
	switch(a) {
		case 11:
			b = 1;
			break;
		case 12:
			b = 2;
			break;
		case 16:
			b = 3;
			break;
		case 20:
			b = 4;
			break;
		case 27:
			b = 5;
			break;
	}*/
	tet.startSwordRender(blockSource.getWorld(), blockSource.getXInt()+enumfacing.getFrontOffsetX(), blockSource.getYInt()+enumfacing.getFrontOffsetY(), blockSource.getZInt()+enumfacing.getFrontOffsetZ(), blockSource.getBlockMetadata(), itemStack);
}
      else {
      	System.out.println("Tile Entity was null!");
      }
      
      /*EntitySword entsw = new EntitySword(par1IBlockSource.getWorld(), par1IBlockSource.getX(), par1IBlockSource.getY(), par1IBlockSource.getZ());
      par1IBlockSource.getWorld().spawnEntityInWorld((Entity)entsw);*/
      return itemStack;
  }
 
Example 19
Source Project: Cyberware   File: ItemSkinUpgrade.java    License: MIT License 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGH)
public void handleMissingEssentials(CyberwareUpdateEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	ItemStack test = new ItemStack(this, 1, 3);
	if (CyberwareAPI.isCyberwareInstalled(e, test))
	{
		boolean last = lastImmuno(e);
		boolean powerUsed = e.ticksExisted % 20 == 0 ? CyberwareAPI.getCapability(e).usePower(test, getPowerConsumption(test)) : last;
		
		if (!powerUsed && e instanceof EntityPlayer && e.ticksExisted % 100 == 0 && !e.isPotionActive(CyberwareContent.neuropozyneEffect))
		{
			e.attackEntityFrom(EssentialsMissingHandler.lowessence, 2F);
		}
		
		if (potions.containsKey(e.getEntityId()))
		{
			Collection<PotionEffect> potionsLastActive = potions.get(e.getEntityId());
			Collection<PotionEffect> currentEffects = e.getActivePotionEffects();
			for (PotionEffect cE : currentEffects)
			{
				if (cE.getPotion() == MobEffects.POISON || cE.getPotion() == MobEffects.HUNGER)
				{
					boolean found = false;
					for (PotionEffect lE : potionsLastActive)
					{
						if (lE.getPotion() == cE.getPotion() && lE.getAmplifier() == cE.getAmplifier())
						{
							found = true;
							break;
						}
					}
					
					if (!found)
					{
						e.addPotionEffect(new PotionEffect(cE.getPotion(), (int) (cE.getDuration() * 1.8F), cE.getAmplifier(), cE.getIsAmbient(), cE.doesShowParticles()));
					}
				}
			}
		}
		potions.put(e.getEntityId(), e.getActivePotionEffects());
	}
	else
	{
		lastImmuno.remove(e.getEntityId());
		potions.remove(e.getEntityId());
	}
}
 
Example 20
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 12F);
    itemstack.damageItem(1, attacker);
    return true;
}