use of resonant.api.explosion.IExplosiveIgnore in project ICBM-Classic by BuiltBrokenModding.
the class BlastRedmatter method affectEntity.
/**
* Makes an entity get affected by Red Matter.
*
* @Return True if explosion happened
*/
public boolean affectEntity(float radius, Entity entity, boolean doExplosion) {
//Ignore players that are in creative mode or can't be harmed
if (entity instanceof EntityPlayer && (((EntityPlayer) entity).capabilities.isCreativeMode || ((EntityPlayer) entity).capabilities.disableDamage)) {
return false;
}
//Ignore self
if (entity == this.controller) {
return false;
}
//Ignore entities that mark themselves are ignorable
if (entity instanceof IExplosiveIgnore) {
if (((IExplosiveIgnore) entity).canIgnore(this)) {
return false;
}
}
//Calculate different from center
double xDifference = entity.posX - position.xi() + 0.5;
double yDifference = entity.posY - position.yi() + 0.5;
double zDifference = entity.posZ - position.zi() + 0.5;
/** The percentage of the closeness of the entity. */
double xPercentage = 1 - (xDifference / radius);
double yPercentage = 1 - (yDifference / radius);
double zPercentage = 1 - (zDifference / radius);
double distancePercentage = this.position.distance(entity) / radius;
Pos entityPosition = new Pos(entity);
Pos centeredPosition = entityPosition.subtract(this.position);
centeredPosition = (Pos) centeredPosition.transform(new EulerAngle(1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random()));
Location newPosition = this.position.add(centeredPosition);
// Orbit Velocity
entity.addVelocity(newPosition.x() - entityPosition.x(), 0, newPosition.z() - entityPosition.z());
// Gravity Velocity (0.015 is barely enough to overcome y gravity so do not lower)
entity.addVelocity(-xDifference * 0.015 * xPercentage, -yDifference * 0.015 * yPercentage, -zDifference * 0.015 * zPercentage);
boolean explosionCreated = false;
if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < (ENTITY_DESTROY_RADIUS * (getRadius() / NORMAL_RADIUS))) {
if (entity instanceof EntityExplosion) {
if (((EntityExplosion) entity).getBlast() instanceof BlastAntimatter) {
if (doAudio) {
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "explosion", 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}
if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
entity.setDead();
return explosionCreated;
}
} else if (((EntityExplosion) entity).getBlast() instanceof BlastRedmatter) {
//https://www.wolframalpha.com/input/?i=(4%2F3)pi+*+r%5E3+%3D+(4%2F3)pi+*+a%5E3+%2B+(4%2F3)pi+*+b%5E3
//We are going to merge both blasts together
double sizeA = this.getRadius();
sizeA = sizeA * sizeA * sizeA;
double sizeB = ((EntityExplosion) entity).getBlast().getRadius();
sizeB = sizeB * sizeB * sizeB;
float radiusNew = (float) Math.cbrt(sizeA + sizeB);
//Average out timer
this.callCount = (callCount + ((EntityExplosion) entity).getBlast().callCount) / 2;
//Destroy current instance
this.isAlive = false;
this.controller.setDead();
//Create new to avoid doing packet syncing
new BlastRedmatter(world(), entity, position.x(), position.y(), position.z(), radiusNew).explode();
}
//Kill explosion entity
((EntityExplosion) entity).getBlast().isAlive = false;
//Kill entity in the center of the ball
entity.setDead();
} else if (entity instanceof EntityExplosive) {
((EntityExplosive) entity).explode();
} else if (entity instanceof EntityLiving) {
((EntityLiving) entity).attackEntityFrom(DamageSource.outOfWorld, 99999999);
} else {
//Kill entity in the center of the ball
entity.setDead();
}
}
return explosionCreated;
}
Aggregations