use of icbm.classic.api.explosion.IBlast in project ICBM-Classic by BuiltBrokenModding.
the class TestTileEMPTower method testGenerateEmp_all.
@Test
void testGenerateEmp_all() {
// Create tower
final TileEMPTower tileEMPTower = create();
tileEMPTower.setPos(new BlockPos(20, 30, 40));
// Create EMP
final IBlast emp = tileEMPTower.buildBlast();
// Validate position
Assertions.assertEquals(20.5, emp.x());
Assertions.assertEquals(31.2, emp.y());
Assertions.assertEquals(40.5, emp.z());
// Validate world
Assertions.assertEquals(world, emp.world());
// Validate size
Assertions.assertEquals(tileEMPTower.empRadius, emp.getBlastRadius());
}
use of icbm.classic.api.explosion.IBlast in project ICBM-Classic by BuiltBrokenModding.
the class BlastRedmatter method attackEntity.
private void attackEntity(Entity entity, double distance) {
// Handle eating logic
if (// TODO make config driven, break section out into its own method
distance < (ConfigBlast.REDMATTER.ENTITY_DESTROY_RADIUS * getScaleFactor())) {
if (entity instanceof EntityExplosion) {
final IBlast blast = ((EntityExplosion) entity).getBlast();
if (// TODO move to capability
blast instanceof BlastAntimatter) {
if (ConfigBlast.REDMATTER.ENABLE_AUDIO) {
ICBMSounds.EXPLOSION.play(world, location.x(), location.y(), location.z(), 7.0F, CalculationHelpers.randFloatRange(world().rand, -0.6F, 0.9F), true);
}
if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
// Destroy self
clearBlast();
}
} else if (// TODO move to capability, also why isAlive checks?
blast instanceof BlastRedmatter && ((BlastRedmatter) blast).isAlive && this.isAlive) {
// 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
final double selfRad = Math.pow(this.getBlastRadius(), 3);
final double targetRad = Math.pow(((EntityExplosion) entity).getBlast().getBlastRadius(), 3);
// TODO why cube?
final float newRad = (float) Math.cbrt(selfRad + targetRad);
// Average out timer
this.callCount = (callCount + ((BlastRedmatter) blast).callCount) / 2;
this.size = newRad;
// TODO combine the vectors
this.controller.setVelocity(0, 0, 0);
// TODO fire an event when combined (non-cancelable to allow acting on combined result)
}
// Kill the blast
blast.clearBlast();
} else if (// TODO move to capability
entity instanceof EntityMissile) {
// TODO should trigger the explosive capability
((EntityMissile) entity).doExplosion();
} else if (// TODO move to capability
entity instanceof EntityExplosive) {
// TODO should trigger the explosive capability
((EntityExplosive) entity).explode();
} else if (entity instanceof EntityLiving || entity instanceof EntityPlayer) {
entity.attackEntityFrom(new DamageSourceRedmatter(this), 2000);
} else {
// Kill entity in the center of the ball
entity.setDead();
if (entity instanceof EntityFlyingBlock) {
if (this.size < 120) {
this.size += 0.05;
}
}
}
}
}
use of icbm.classic.api.explosion.IBlast in project ICBM-Classic by BuiltBrokenModding.
the class ExplosiveHandler method removeNear.
/**
* Called to remove blasts near the location
*
* @param world = position
* @param x - position
* @param y - position
* @param z - position
* @param range - distance from position, less than zero will turn into global
* @return number of blasts removed
*/
public static int removeNear(World world, double x, double y, double z, double range) {
final Pos pos = new Pos(x, y, z);
// Collect blasts marked for removal
final List<IBlast> toRemove = ExplosiveHandler.activeBlasts.stream().filter(blast -> blast.world() == world).filter(blast -> range < 0 || range > 0 && range > pos.distance(blast)).collect(Collectors.toList());
// Do removals
activeBlasts.removeAll(toRemove);
toRemove.forEach(IBlast::clearBlast);
return toRemove.size();
}
Aggregations