Java Code Examples for net.minecraft.util.DamageSource#getTrueSource()

The following examples show how to use net.minecraft.util.DamageSource#getTrueSource() . 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: EntityGnomeWood.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Called when another entity attacks this gnome
 */
@Override
public boolean attackEntityFrom(DamageSource damage, float f)
{
	boolean superflag = super.attackEntityFrom(damage, f);
	if (superflag && !this.isDead && damage.getTrueSource() != null)
	{
		if (this.job != null)
		{
			this.job.finishJob(false);
			this.job = null;
		}
		if (this.gnode != null)
		{	// if home is closer than 4 tiles, gtfo
			if (this.getDistanceSq(this.gnode.getPos().down(2)) < 16.0D) // if distance < 4
			{
				this.gnode.selfDestruct();
			}
		}
		this.panic = true;
	}
	return superflag;
}
 
Example 2
Source File: EntityWitherCat.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource source, float amount) {
  if (owner != null && source.getTrueSource() == owner) {
    return false;
  }
  boolean res = super.attackEntityFrom(source, amount);
  if (!world.isRemote) {
    if (source.getTrueSource() instanceof EntityLivingBase) {
      if (owner != null) {
        EntityLivingBase ownerHitBy = owner.getRevengeTarget();
        if (ownerHitBy == null) {
          owner.setRevengeTarget((EntityLivingBase) source.getTrueSource());
        }
      } else if (owner == null) {
        setAttackTarget((EntityLivingBase) source.getTrueSource());
      }
    }
  }
  return res;
}
 
Example 3
Source File: EntityDireSlime.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
public void onDeath(DamageSource damageSource) {
  super.onDeath(damageSource);
  if (!world.isRemote && damageSource != null && damageSource.getTrueSource() instanceof EntityPlayer) {
    SlimeConf nextConf = SlimeConf.getConfForSize(getSlimeSize()).bigger();
    if (nextConf != null && world.rand.nextFloat() <= nextConf.chance) {
      EntityDireSlime spawn = new EntityDireSlime(world);
      spawn.setSlimeSize(nextConf.size,true);
      spawn.setLocationAndAngles(posX, posY, posZ, rotationYaw, 0);
      spawn.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(this)), null);
      if (SpawnUtil.isSpaceAvailableForSpawn(world, spawn, false)) {
        world.spawnEntity(spawn);
      }
    }
  }
}
 
Example 4
Source File: EntityMage.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void achievement(DamageSource cause) {
	if (world.isRemote) {
		return;
	}
	Entity entity = cause.getTrueSource();
	if (entity != null && entity instanceof EntityPlayer) {
		//TODO
		//((EntityPlayer) entity).addStat(MAGE_ACHIEVEMNT);
	}
}
 
Example 5
Source File: EntityToro.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private EntityLivingBase getAttacker(DamageSource source) {
	try {
		return (EntityLivingBase) source.getTrueSource();
	} catch (Exception e) {
		return null;
	}
}
 
Example 6
Source File: EntityRainbowGuard.java    From ToroQuest with 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 7
Source File: EntityBas.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void achievement(DamageSource cause) {
	if (world.isRemote) {
		return;
	}
	Entity entity = cause.getTrueSource();
	if (entity != null && entity instanceof EntityPlayer) {
		//TODO
		//((EntityPlayer) entity).addStat(BASTION_ACHIEVEMNT);
	}
}
 
Example 8
Source File: EntityBas.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void attackDistantAttackerWithBats(DamageSource source) {
	if (!(source.getTrueSource() instanceof EntityLivingBase)) {
		return;
	}
	EntityLivingBase distantAttacker = (EntityLivingBase) source.getTrueSource();
	spawnBats(distantAttacker);
}
 
Example 9
Source File: EntityGuard.java    From ToroQuest with 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;
	}

	EntityLivingBase attacker = this.getAttackTarget();
	if (attacker == null && source.getTrueSource() instanceof EntityLivingBase) {
		setAttackTarget((EntityLivingBase) source.getTrueSource());
		callForHelp((EntityLivingBase) source.getTrueSource());
	}
	return true;
}
 
Example 10
Source File: EntityWitherWitch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@Override
protected float applyPotionDamageCalculations(DamageSource damageSource, float damage) {
  //same as a vanilla witch
  damage = super.applyPotionDamageCalculations(damageSource, damage);
  if(damageSource.getTrueSource() == this) {
    damage = 0.0F;
  }
  if(damageSource.isMagicDamage()) {
    damage = (float) (damage * 0.15D);
  }
  return damage;
}
 
Example 11
Source File: EntityMage.java    From ToroQuest with 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 12
Source File: EntityMage.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reduces damage, depending on potions
 */
protected float applyPotionDamageCalculations(DamageSource source, float damage) {
	damage = super.applyPotionDamageCalculations(source, damage);

	if (source.getTrueSource() == this) {
		damage = 0.0F;
	}

	if (source.isMagicDamage()) {
		damage = (float) ((double) damage * 0.15D);
	}

	return damage;
}
 
Example 13
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 14
Source File: EntityMonolithEye.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void redirectArrowAtAttacker(DamageSource source) {
	if ("arrow".equals(source.getDamageType())) {

		if (source.getTrueSource() != null && source.getTrueSource() instanceof EntityLivingBase) {
			attackWithArrow((EntityLivingBase) source.getTrueSource());
		}

		if (source.getImmediateSource() != null) {
			source.getImmediateSource().setDead();
		}

	}
}
 
Example 15
Source File: EntityFugitive.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void achievement(DamageSource cause) {
	if (world.isRemote) {
		return;
	}
	Entity entity = cause.getTrueSource();
	if (entity != null && entity instanceof EntityPlayer) {
		//((EntityPlayer) entity).addStat(BOUNTY_HUNTER_ACHIEVEMNT);
	}
}
 
Example 16
Source File: EntityVillageLord.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void achievement(DamageSource cause) {
	if (world.isRemote) {
		return;
	}
	Entity entity = cause.getTrueSource();
	//TODO
	/*
	if (entity != null && entity instanceof EntityPlayer) {
		((EntityPlayer) entity).addStat(LORD_ACHIEVEMNT);
	}
	*/
}
 
Example 17
Source File: EntityVillageLord.java    From ToroQuest with 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 18
Source File: EntitySphere.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
@Override
public boolean attackEntityFrom(DamageSource source, float amount) {
    if (this.isEntityInvulnerable(source)) {
        return false;
    } else {
        this.markVelocityChanged();

        if (source.getTrueSource() != null) {
            Vec3d vec3d = source.getTrueSource().getLookVec();

            if (vec3d != null) {
                this.motionX = vec3d.x;
                this.motionY = vec3d.y;
                this.motionZ = vec3d.z;
                this.accelerationX = this.motionX * 0.1D;
                this.accelerationY = this.motionY * 0.1D;
                this.accelerationZ = this.motionZ * 0.1D;
            }

            if (source.getTrueSource() instanceof EntityLivingBase) {
                this.shootingEntity = (EntityLivingBase) source.getTrueSource();
            }

            return true;
        } else {
            return false;
        }
    }
}
 
Example 19
Source File: EntityMonolithEye.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
protected void redirectAttack(DamageSource source, float amount) {
	Entity attacker = source.getTrueSource();
	if (attacker != null) {
		attacker.attackEntityFrom(source, amount);
	}
}
 
Example 20
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;

}