Search in sources :

Example 1 with IBlast

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

Example 2 with IBlast

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;
                }
            }
        }
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IBlast(icbm.classic.api.explosion.IBlast) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityExplosive(icbm.classic.content.entity.EntityExplosive) BlastAntimatter(icbm.classic.content.blast.threaded.BlastAntimatter) EntityMissile(icbm.classic.content.entity.missile.EntityMissile)

Example 3 with IBlast

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();
}
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)

Aggregations

IBlast (icbm.classic.api.explosion.IBlast)3 ICBMClassic (icbm.classic.ICBMClassic)1 ICBMConstants (icbm.classic.ICBMConstants)1 ICBMClassicAPI (icbm.classic.api.ICBMClassicAPI)1 IExplosive (icbm.classic.api.caps.IExplosive)1 BlastState (icbm.classic.api.explosion.BlastState)1 IBlastInit (icbm.classic.api.explosion.IBlastInit)1 IExplosiveData (icbm.classic.api.reg.IExplosiveData)1 Blast (icbm.classic.content.blast.Blast)1 BlastAntimatter (icbm.classic.content.blast.threaded.BlastAntimatter)1 EntityExplosion (icbm.classic.content.entity.EntityExplosion)1 EntityExplosive (icbm.classic.content.entity.EntityExplosive)1 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)1 EntityMissile (icbm.classic.content.entity.missile.EntityMissile)1 Pos (icbm.classic.lib.transform.vector.Pos)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Entity (net.minecraft.entity.Entity)1 EntityLiving (net.minecraft.entity.EntityLiving)1