下面列出了net.minecraft.util.DamageSource#getTrueSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
@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;
}
@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);
}
}
}
}
@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);
}
@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;
}
}
}
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);
}
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);
}
*/
}
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);
}
}
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();
}
}
}
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);
}
}
/**
* 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;
}
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;
}
@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;
}
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;
}
protected void attackDistantAttackerWithBats(DamageSource source) {
if (!(source.getTrueSource() instanceof EntityLivingBase)) {
return;
}
EntityLivingBase distantAttacker = (EntityLivingBase) source.getTrueSource();
spawnBats(distantAttacker);
}
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);
}
}
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;
}
private EntityLivingBase getAttacker(DamageSource source) {
try {
return (EntityLivingBase) source.getTrueSource();
} catch (Exception e) {
return null;
}
}
protected void redirectAttack(DamageSource source, float amount) {
Entity attacker = source.getTrueSource();
if (attacker != null) {
attacker.attackEntityFrom(source, amount);
}
}
/**
* 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;
}