use of icbm.classic.content.blast.Blast in project ICBM-Classic by BuiltBrokenModding.
the class EntityExplosion method readEntityFromNBT.
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
@Override
protected void readEntityFromNBT(NBTTagCompound nbt) {
try {
NBTTagCompound blastSave = nbt.getCompoundTag(NBTConstants.BLAST);
this.blastYOffset = nbt.getDouble(NBTConstants.BLAST_POS_Y);
if (getBlast() == null) {
// Legacy code
if (blastSave.hasKey(NBTConstants.CLASS)) {
Class clazz = Class.forName(blastSave.getString(NBTConstants.CLASS));
Constructor constructor = clazz.getConstructor();
Blast blast = (Blast) constructor.newInstance();
blast.setBlastWorld(world);
blast.setPosition(posX, posY + blastYOffset, posZ);
blast.setEntityController(this);
blast.buildBlast();
} else if (blastSave.hasKey(NBTConstants.EX_ID)) {
constructBlast(blastSave.getString(NBTConstants.EX_ID), blastYOffset);
} else {
ICBMClassic.logger().error("EntityExplosion: Failed to read save state for explosion!");
}
}
if (getBlast() instanceof IBlastRestore) {
((IBlastRestore) getBlast()).load(blastSave);
}
} catch (Exception e) {
ICBMClassic.logger().error("EntityExplosion: Unexpected error restoring save state of explosion entity!", e);
}
}
use of icbm.classic.content.blast.Blast 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();
}
use of icbm.classic.content.blast.Blast in project ICBM-Classic by BuiltBrokenModding.
the class TestTileEMPTower method testFire_isReady_hasEnergy.
@Test
void testFire_isReady_hasEnergy() {
// Create tower, create mock around tile so we can fake some methods
final TileEMPTower tileEMPTower = spy(create());
tileEMPTower.setPos(new BlockPos(20, 30, 40));
tileEMPTower.setEnergy(Integer.MAX_VALUE);
// Mock blast so we don't invoke world calls
when(tileEMPTower.buildBlast()).thenReturn(new Blast() {
@Override
public BlastState runBlast() {
return BlastState.TRIGGERED;
}
});
// Should have fired
Assertions.assertTrue(tileEMPTower.fire());
}
Aggregations