use of icbm.classic.content.blocks.explosive.TileEntityExplosive in project ICBM-Classic by BuiltBrokenModding.
the class BlastSonic method doExplode.
@Override
public // TODO Rewrite this entire method
boolean doExplode(// TODO Rewrite this entire method
int callCount) {
if (callCount <= 0) {
firstTick();
}
// TODO scale off of size & callcout
final int radius = Math.max(1, this.callCount);
if (callCount % 4 == 0) {
if (isThreadCompleted()) {
if (!getThreadResults().isEmpty()) {
final Iterator<BlockPos> it = getThreadResults().iterator();
while (it.hasNext()) {
final BlockPos targetPosition = it.next();
final double distance = location.distance(targetPosition);
// Only act on blocks inside the current radius TODO scale radius separate from ticks so we can control block creation
if (distance <= radius) {
// Remove
it.remove();
// Get data
final IBlockState blockState = world.getBlockState(targetPosition);
final Block block = blockState.getBlock();
// Only act on movable blocks
if (!block.isAir(blockState, world, targetPosition) && blockState.getBlockHardness(world, targetPosition) >= 0) {
// Trigger explosions
if (block == BlockReg.blockExplosive) {
((TileEntityExplosive) this.world().getTileEntity(targetPosition)).trigger(false);
}
// Destroy block
this.world().setBlockToAir(targetPosition);
// Create floating block
if (!(block instanceof BlockFluidBase || block instanceof IFluidBlock) && this.world().rand.nextFloat() < 0.1) {
this.world().spawnEntity(new EntityFlyingBlock(this.world(), targetPosition, blockState));
}
}
}
}
} else {
isAlive = false;
if (ConfigDebug.DEBUG_THREADS) {
String msg = String.format("BlastSonic#doPostExplode() -> Thread failed to find blocks to edit. Either thread failed or no valid blocks were found in range." + "\nWorld = %s " + "\nThread = %s" + "\nSize = %s" + "\nPos = %s", world, getThread(), size, location);
ICBMClassic.logger().error(msg);
}
}
}
}
// TODO scale to radius
final int entityEffectRadius = 2 * this.callCount;
final AxisAlignedBB bounds = new AxisAlignedBB(location.x() - entityEffectRadius, location.y() - entityEffectRadius, location.z() - entityEffectRadius, location.x() + entityEffectRadius, location.y() + entityEffectRadius, location.z() + entityEffectRadius);
final List<Entity> allEntities = this.world().getEntitiesWithinAABB(Entity.class, bounds);
for (Entity entity : allEntities) {
if (entity instanceof IMissile) {
// TODO change from guided to dummy fire
((IMissile) entity).destroyMissile(true);
} else if (!(entity instanceof EntityPlayer) || !((EntityPlayer) entity).isCreative()) {
// Get difference
double xDelta = entity.posX - location.x();
double yDelta = entity.posY - location.y();
double zDelta = entity.posZ - location.z();
// Normalize
float distance = MathHelper.sqrt(xDelta * xDelta + yDelta * yDelta + zDelta * zDelta);
xDelta = xDelta / (double) distance;
yDelta = yDelta / (double) distance;
zDelta = zDelta / (double) distance;
// Scale
final double scale = Math.max(0, (1 - (distance / getBlastRadius()))) * 3;
xDelta *= scale;
yDelta *= scale;
zDelta *= scale;
entity.motionX += xDelta * this.world().rand.nextFloat() * 0.2;
entity.motionY += Math.abs(yDelta * this.world().rand.nextFloat()) * 1;
entity.motionZ += zDelta * this.world().rand.nextFloat() * 0.2;
}
}
return this.callCount > this.getBlastRadius();
}
Aggregations