Search in sources :

Example 1 with Blast

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);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Blast(icbm.classic.content.blast.Blast)

Example 2 with Blast

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();
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Blast(icbm.classic.content.blast.Blast) Entity(net.minecraft.entity.Entity) WorldEvent(net.minecraftforge.event.world.WorldEvent) World(net.minecraft.world.World) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ICBMClassicAPI(icbm.classic.api.ICBMClassicAPI) IExplosiveData(icbm.classic.api.reg.IExplosiveData) List(java.util.List) BlastState(icbm.classic.api.explosion.BlastState) IBlastInit(icbm.classic.api.explosion.IBlastInit) IBlast(icbm.classic.api.explosion.IBlast) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) IExplosive(icbm.classic.api.caps.IExplosive) Mod(net.minecraftforge.fml.common.Mod) ICBMClassic(icbm.classic.ICBMClassic) ICBMConstants(icbm.classic.ICBMConstants) Pos(icbm.classic.lib.transform.vector.Pos) IBlast(icbm.classic.api.explosion.IBlast)

Example 3 with Blast

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());
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Blast(icbm.classic.content.blast.Blast) IBlast(icbm.classic.api.explosion.IBlast) BlastState(icbm.classic.api.explosion.BlastState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Blast (icbm.classic.content.blast.Blast)3 BlastState (icbm.classic.api.explosion.BlastState)2 IBlast (icbm.classic.api.explosion.IBlast)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ICBMClassic (icbm.classic.ICBMClassic)1 ICBMConstants (icbm.classic.ICBMConstants)1 ICBMClassicAPI (icbm.classic.api.ICBMClassicAPI)1 IExplosive (icbm.classic.api.caps.IExplosive)1 IBlastInit (icbm.classic.api.explosion.IBlastInit)1 IExplosiveData (icbm.classic.api.reg.IExplosiveData)1 Pos (icbm.classic.lib.transform.vector.Pos)1 Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Entity (net.minecraft.entity.Entity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 WorldEvent (net.minecraftforge.event.world.WorldEvent)1 Mod (net.minecraftforge.fml.common.Mod)1