Java Code Examples for net.minecraft.util.DamageSource

The following examples show how to use net.minecraft.util.DamageSource. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: TofuCraftReload   Source File: EntityTofuGandlem.java    License: MIT License 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource source, float amount) {
    if (this.isEntityInvulnerable(source)) {
        return false;
    } else if (source.getImmediateSource() instanceof EntityFukumame) {
        return false;
    } else {
        if (isSleep()) {
            setSleep(false);

           /* if(source.getImmediateSource() instanceof EntityPlayerMP) {
                this.bossInfo.addPlayer((EntityPlayerMP) source.getImmediateSource());
            }*/
        }
        if (source.getImmediateSource() instanceof EntityArrow) {
            return super.attackEntityFrom(source, amount * 0.8F);
        } else {
            return super.attackEntityFrom(source, amount);
        }
    }
}
 
Example 2
Source Project: ExNihiloAdscensio   Source File: ProjectileStone.java    License: MIT License 6 votes vote down vote up
@Override
protected void onImpact(RayTraceResult result)
{
    if (result.entityHit != null)
    {
        result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), (int) (Math.random() * (4.0F / 3.0F)));
    }
    else if (!world.isRemote)
    {
        setDead();
        
        if(stack != null)
        {
            world.spawnEntity(new EntityItem(world, posX, posY, posZ, stack));
        }
    }
    
    for (int j = 0; j < 8; ++j)
    {
        world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX, posY, posZ, 0.0D, 0.0D, 0.0D, new int[] { Block.getStateId(Blocks.STONE.getDefaultState()) });
    }
}
 
Example 3
Source Project: TofuCraftReload   Source File: EntityTofunian.java    License: MIT License 6 votes vote down vote up
public void onDeath(DamageSource cause) {
    if (this.village != null) {
        Entity entity = cause.getTrueSource();

        if (entity != null) {
            if (entity instanceof EntityPlayer) {
                this.village.modifyPlayerReputation(entity.getUniqueID(), -2);
            } else if (entity instanceof IMob) {
                this.village.endMatingSeason();
            }
        } else {
            EntityPlayer entityplayer = this.world.getClosestPlayerToEntity(this, 16.0D);

            if (entityplayer != null) {
                this.village.endMatingSeason();
            }
        }
    }

    super.onDeath(cause);
}
 
Example 4
Source Project: TofuCraftReload   Source File: EntityFukumame.java    License: MIT License 6 votes vote down vote up
/**
 * Called when this EntityThrowable hits a block or entity.
 */
@Override
protected void onImpact(RayTraceResult par1MovingObjectPosition) {
    Entity entityHit = par1MovingObjectPosition.entityHit;
    if (entityHit == this.ignoreEntity && this.age < 5) {
        return;
    }
    if (par1MovingObjectPosition.entityHit != null) {
        double d = this.getDamage();
        d *= this.isCrit ? 2.5D : 1.0D;


        entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float) d);
        if (entityHit instanceof EntityLivingBase) {
            EntityLivingBase entityLivivng = (EntityLivingBase) entityHit;
            entityLivivng.hurtResistantTime = entityLivivng.maxHurtResistantTime / 2;
        }
        for (int i = 0; i < 3; ++i) {
            this.world.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
        }
    }

    if (!this.world.isRemote) {
        this.setDead();
    }
}
 
Example 5
@Override
protected void attackEntity(Entity entity, float f)
{
    
    if (attackTime <= 0 && (f < 3.0D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
        attackTime = 20;
        boolean flag = (rand.nextInt(3) == 0);
        if (flag)
        {
            if (entity instanceof EntityPlayer) 
            {
            	MoCreatures.poisonPlayer((EntityPlayer) entity);
            }
            ((EntityLiving) entity).addPotionEffect(new PotionEffect(Potion.poison.id, 200, 0));
            MoCTools.playCustomSound(this, "wyvernpoisoning", worldObj);
        }
        
        int dmg = 5;
        if (getType() >= 5) dmg = 10;
        entity.attackEntityFrom(DamageSource.causeMobDamage(this), dmg);
        openMouth();
    }
}
 
Example 6
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        if ((entity != null) && (entity instanceof EntityPlayer) && getIsTamed()) { return false; }

        if ((entity != null) && (entity != this) && (worldObj.difficultySetting > 0) && getIsAdult())
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 7
Source Project: mocreaturesdev   Source File: MoCTools.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void buckleMobs(EntityLiving entityattacker, Double dist, World worldObj)
{
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(entityattacker, entityattacker.boundingBox.expand(dist, 2D, dist));
    for (int i = 0; i < list.size(); i++)
    {
        Entity entitytarget = (Entity) list.get(i);
        if (!(entitytarget instanceof EntityLiving) || (entityattacker.riddenByEntity != null && entitytarget == entityattacker.riddenByEntity))
        {
            continue;
        }
        //EntityMob entitymob = (EntityMob) entity;
        entitytarget.attackEntityFrom(DamageSource.causeMobDamage(entityattacker), 2);
        bigsmack(entityattacker, entitytarget, 0.6F);
        playCustomSound(entityattacker, "tud", worldObj);
        //todo tuck sound!!
    }
}
 
Example 8
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i) && (worldObj.difficultySetting > 0))
    {
        Entity entity = damagesource.getEntity();
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if (entity != this)
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 9
@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 10
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i) && (worldObj.difficultySetting > 0))
    {
        Entity entity = damagesource.getEntity();
        if ((riddenByEntity == entity) || (ridingEntity == entity)) { return true; }
        if (entity != this)
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 11
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
     
        
        if (entity != null && getIsTamed() && entity instanceof EntityPlayer) { return false; }
        

        if ((riddenByEntity != null) && (entity == riddenByEntity)) { return false; }
        
        if ((entity != this) && (worldObj.difficultySetting > 0))
        {
            entityToAttack = entity;
        }
        return true;
    }
    return false;
}
 
Example 12
@Override
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
    if (super.attackEntityFrom(damagesource, i))
    {
        Entity entity = damagesource.getEntity();
        //if ((entity != null) && (entity instanceof EntityPlayer) && getIsTamed()) { return false; }

        if ((entity != null) && (entity != this) && (worldObj.difficultySetting > 0) && getIsAdult())
        {
            entityToAttack = entity;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 13
Source Project: archimedes-ships   Source File: EntityShip.java    License: MIT License 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource source, float damage)
{
	/*if (source.isExplosion())
	{
		if (source.getEntity() != null && source.getEntity().getClass().getName().equals("ckathode.weaponmod.entity.projectile.EntityCannonBall"))
		{
			double dx = source.getEntity().posX - posX;
			double dy = source.getEntity().posY - posY;
			double dz = source.getEntity().posZ - posZ;
			
			Vec3 vec = worldObj.getWorldVec3Pool().getVecFromPool(dx, dy, dz);
			vec.rotateAroundY((float) Math.toRadians(-rotationYaw));
			
			worldObj.createExplosion(source.getEntity(), source.getEntity().posX, source.getEntity().posY, source.getEntity().posZ, 4F, false);
			source.getEntity().setDead();
		}
	}*/
	return false;
}
 
Example 14
@Override
protected void attackEntity(Entity entity, float f)
{
    if (attackTime <= 0 && (f < 2.5D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
        attackTime = 20;
        entity.attackEntityFrom(DamageSource.causeMobDamage(this), 2);

        if (MoCreatures.isServer() && !worldObj.provider.isHellWorld)
        {
            ((EntityLiving) entity).setFire(burningTime);
        }

        //entity.fire = burningTime;
    }
}
 
Example 15
Source Project: ToroQuest   Source File: EntityRainbowGuard.java    License: GNU General Public License v3.0 5 votes vote down vote up
public boolean attackEntityFrom(DamageSource source, float amount) {
	if (!super.attackEntityFrom(source, amount)) {
		return false;
	}

	if (isAtAttention()) {
		setAtAttention(false);
	}

	EntityLivingBase attacker = this.getAttackTarget();
	if (attacker == null && source.getTrueSource() instanceof EntityLivingBase) {
		setAttackTarget((EntityLivingBase) source.getTrueSource());
	}
	return true;
}
 
Example 16
private boolean handleGrowingNodeSecond(boolean needUpdate) {
    if(extendedNodeType == null || extendedNodeType != ExtendedNodeType.GROWING) return needUpdate;

    if(worldObj.difficultySetting == EnumDifficulty.PEACEFUL) return needUpdate;
    if(worldObj.isRemote) return needUpdate;
    if(ticksExisted % 8 != 0) return needUpdate;

    List livingEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(6.0D, 6.0D, 6.0D));
    if ((livingEntities != null) && (livingEntities.size() > 0)) {
        for (Object e : livingEntities) {
            EntityLivingBase livingEntity = (EntityLivingBase) e;
            if ((livingEntity.isEntityAlive()) && (!livingEntity.isEntityInvulnerable())) {
                if(livingEntity instanceof EntityPlayer && ((EntityPlayer) livingEntity).capabilities.isCreativeMode) continue;
                if(!behavior.mayZapNow()) continue;

                ResearchHelper.distributeResearch(Gadomancy.MODID.toUpperCase() + ".GROWING_AGGRESSION", worldObj, xCoord, yCoord, zCoord, 6);

                livingEntity.attackEntityFrom(DamageSource.magic, behavior.getZapDamage());

                worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "thaumcraft:zap", 0.8F, 1.0F);

                PacketTCNodeBolt packet = new PacketTCNodeBolt(xCoord + 0.5F, yCoord + 0.5F, zCoord + 0.5F, (float) livingEntity.posX, (float) (livingEntity.posY + livingEntity.height), (float) livingEntity.posZ, 0, false);
                PacketHandler.INSTANCE.sendToAllAround(packet, new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 32.0D));
            }
        }
    }

    return needUpdate;
}
 
Example 17
Source Project: TofuCraftReload   Source File: EntityTofunian.java    License: MIT License 5 votes vote down vote up
@Override
public boolean attackEntityAsMob(Entity entityIn) {
    boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float) ((int) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()));

    if (flag) {
        this.applyEnchantments(this, entityIn);
    }

    return flag;
}
 
Example 18
Source Project: mocreaturesdev   Source File: MoCEntityBee.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void attackEntity(Entity entity, float f)
{

    if (this.attackTime <= 0 && (f < 2.0D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
        attackTime = 20;
        entity.attackEntityFrom(DamageSource.causeMobDamage(this), 2);
    }
}
 
Example 19
@Override
public boolean attackEntityAsMob(Entity target) {
  if(isRidden() || isDead) {
    return false;
  }
  super.attackEntityAsMob(target);
  if(!isRearing()) {
    makeMad();
  }
  float damage = (float) getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
  return target.attackEntityFrom(DamageSource.causeMobDamage(this), damage);
}
 
Example 20
Source Project: ToroQuest   Source File: EntityVillageLord.java    License: GNU General Public License v3.0 5 votes vote down vote up
public boolean attackEntityFrom(DamageSource source, float amount) {
	if (this.isEntityInvulnerable(source)) {
		return false;
	}

	dropRepTo(source.getTrueSource());

	if (source.getTrueSource() instanceof EntityLivingBase) {
		callForHelp((EntityLivingBase) source.getTrueSource());
	}

	return super.attackEntityFrom(source, amount);
}
 
Example 21
Source Project: ToroQuest   Source File: EntityBas.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDeath(DamageSource cause) {
	super.onDeath(cause);
	if (!world.isRemote) {
		dropLoot();
		achievement(cause);
	}
}
 
Example 22
@Override
public void onDeath(DamageSource damagesource)
{
	if (MoCreatures.isServer())
    {
    	if (getIsTamed())
    	{
    		MoCTools.dropCustomItem(this, this.worldObj, new ItemStack(MoCreatures.medallion, 1));
    	}
    }
	super.onDeath(damagesource);
}
 
Example 23
@Override
public void onDeath(DamageSource damagesource)
{
	if (MoCreatures.isServer())
    {
    	if (getIsTamed())
    	{
    		MoCTools.dropCustomItem(this, this.worldObj, new ItemStack(MoCreatures.medallion, 1));
    	}
    }
	super.onDeath(damagesource);
}
 
Example 24
@Override
public void onDeath(DamageSource damagesource)
{

    unMount();
    MoCTools.checkForTwistedEntities(worldObj);
    super.onDeath(damagesource);
}
 
Example 25
Source Project: Cyberware   Source File: CyberwareDataHandler.java    License: MIT License 5 votes vote down vote up
private boolean shouldDropWare(DamageSource source)
{
	if (source == EssentialsMissingHandler.noessence) return true;
	if (source == EssentialsMissingHandler.heartless) return true;
	if (source == EssentialsMissingHandler.brainless) return true;
	if (source == EssentialsMissingHandler.nomuscles) return true;
	if (source == EssentialsMissingHandler.spineless) return true;

	return false;
}
 
Example 26
Source Project: ToroQuest   Source File: EntityMage.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected float redirectAttack(DamageSource source, float amount) {
	float reflectFactor = rand.nextFloat();

	float reflectAmount = amount * reflectFactor;
	float passAmount = amount - reflectAmount;

	reflectAmount *= ToroQuestConfiguration.bossAttackDamageMultiplier;

	Entity attacker = source.getTrueSource();
	if (attacker != null) {
		attacker.attackEntityFrom(source, reflectAmount);
	}
	this.world.setEntityState(this, (byte) 15);
	return passAmount;
}
 
Example 27
Source Project: SimplyJetpacks   Source File: ItemPack.java    License: MIT License 5 votes vote down vote up
@Override
public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) {
    T pack = this.getPack(armor);
    if (pack != null && pack.isArmored && !source.isUnblockable()) {
        if (pack.isFluxBased && source.damageType.equals("flux")) {
            return new ArmorProperties(0, 0.5D, Integer.MAX_VALUE);
        }
        int energyPerDamage = this.getFuelPerDamage(armor, pack);
        int maxAbsorbed = energyPerDamage > 0 ? 25 * (this.getFuelStored(armor) / energyPerDamage) : 0;
        return new ArmorProperties(0, 0.85D * (pack.armorReduction / 20.0D), maxAbsorbed);
    }
    return new ArmorProperties(0, 1, 0);
}
 
Example 28
@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 29
public boolean syphonHealth(EntityPlayer player){
    if(player.getHealth() > 3){
        player.setHealth(player.getHealth() - 3);
        return true;
    }
    else if(player.getHealth() > 0){
        player.func_110142_aN().func_94547_a(new DamageSource("blooderp"), 3, 3);
        player.setHealth(0);
        player.onDeath(new DamageSource("blooderp"));
        return true;
    }
    else
        return false;
}
 
Example 30
Source Project: HexxitGear   Source File: AbilityKnockback.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(EntityPlayer player) {
    List<EntityLiving> entities = player.worldObj.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox(player.posX - 5, player.posY, player.posZ - 5, player.posX + 5, player.posY + 3, player.posZ + 5));

    for (EntityLiving entity : entities) {
        double relX = player.posX - entity.posX;
        double relZ = player.posZ - entity.posZ;

        if (!entity.equals(player)) {
            entity.attackEntityFrom(DamageSource.causePlayerDamage(player), 2);
            entity.addVelocity((relX * 0.25) * -1, 0.2, (relZ * 0.25) * -1);
        }
    }
}