Search in sources :

Example 1 with EntityFlyingBlock

use of icbm.classic.content.entity.EntityFlyingBlock in project ICBM-Classic by BuiltBrokenModding.

the class BlastAntiGravitational method doExplode.

@Override
public void doExplode() {
    int r = this.callCount;
    if (!this.world().isRemote && this.thread.isComplete) {
        if (r == 0) {
            Collections.sort(this.thread.results, new GravitationalBlockSorter(position));
        }
        int blocksToTake = 20;
        for (Pos targetPosition : this.thread.results) {
            double distance = targetPosition.distance(position);
            if (distance > r || distance < r - 2 || blocksToTake <= 0) {
                continue;
            }
            final Block block = targetPosition.getBlock(world());
            if (block != null) {
                float hardness = block.getBlockHardness(world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                if (hardness >= 0 && hardness < 1000) {
                    int metadata = world().getBlockMetadata(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                    if (distance < r - 1 || world().rand.nextInt(3) > 0) {
                        //Remove block
                        this.world().setBlockToAir(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                        blocksToTake--;
                        //Create flying block
                        EntityFlyingBlock entity = new EntityFlyingBlock(world(), targetPosition.add(0.5D), block, metadata, 0);
                        entity.yawChange = 50 * world().rand.nextFloat();
                        entity.pitchChange = 100 * world().rand.nextFloat();
                        entity.motionY += Math.max(0.15 * world().rand.nextFloat(), 0.1);
                        entity.noClip = true;
                        world().spawnEntityInWorld(entity);
                        //Track flying block
                        flyingBlocks.add(entity);
                    }
                }
            }
        }
    }
    int radius = (int) this.getRadius();
    AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - radius, position.y() - radius, position.z() - radius, position.y() + radius, 100, position.z() + radius);
    List<Entity> allEntities = world().getEntitiesWithinAABB(Entity.class, bounds);
    for (Entity entity : allEntities) {
        if (!(entity instanceof EntityFlyingBlock) && entity.posY < 100 + position.y()) {
            if (entity.motionY < 0.4) {
                entity.motionY += 0.15;
            }
        }
    }
    if (this.callCount > 20 * 120) {
        this.controller.endExplosion();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) Block(net.minecraft.block.Block) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock)

Example 2 with EntityFlyingBlock

use of icbm.classic.content.entity.EntityFlyingBlock in project ICBM-Classic by BuiltBrokenModding.

the class CommandICBM method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) {
    try {
        EntityPlayer entityPlayer = (EntityPlayer) sender;
        int dimension = entityPlayer.worldObj.provider.dimensionId;
        if (args == null || args.length == 0 || args[0].equalsIgnoreCase("help")) {
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc help"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc lag <radius>"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc remove <All/Missile/Explosion> <radius>"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc emp <radius>"));
            return;
        } else if (args.length >= 2 && args[0].equalsIgnoreCase("lag")) {
            int radius = parseInt(sender, args[1]);
            if (radius > 0) {
                AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(entityPlayer.posX - radius, entityPlayer.posY - radius, entityPlayer.posZ - radius, entityPlayer.posX + radius, entityPlayer.posY + radius, entityPlayer.posZ + radius);
                List<Entity> entitiesNearby = entityPlayer.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
                for (Entity entity : entitiesNearby) {
                    if (entity instanceof EntityFlyingBlock) {
                        ((EntityFlyingBlock) entity).setBlock();
                    } else if (entity instanceof EntityMissile) {
                        entity.setDead();
                    } else if (entity instanceof EntityExplosion) {
                        entity.setDead();
                    }
                }
                ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM lag sources within " + radius + " radius."));
                return;
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        } else if (args.length >= 3 && args[0].equalsIgnoreCase("remove")) {
            int radius = parseInt(sender, args[2]);
            boolean all = args[1].equalsIgnoreCase("all");
            boolean missile = args[1].equalsIgnoreCase("missiles");
            boolean explosion = args[1].equalsIgnoreCase("explosion");
            String str = "entities";
            if (missile) {
                str = "missiles";
            }
            if (explosion) {
                str = "explosions";
            }
            if (radius > 0) {
                EntityPlayer player = (EntityPlayer) sender;
                AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(player.posX - radius, player.posY - radius, player.posZ - radius, player.posX + radius, player.posY + radius, player.posZ + radius);
                List<Entity> entitiesNearby = player.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
                for (Entity entity : entitiesNearby) {
                    if ((all || explosion) && entity instanceof EntityFlyingBlock) {
                        ((EntityFlyingBlock) entity).setBlock();
                    } else if ((all || missile) && entity instanceof EntityMissile) {
                        entity.setDead();
                    } else if ((all || explosion) && entity instanceof EntityExplosion) {
                        entity.setDead();
                    }
                }
                ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM " + str + " within " + radius + " radius."));
                return;
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        } else if (args.length >= 2 && args[0].equalsIgnoreCase("emp")) {
            int radius = parseInt(sender, args[1]);
            if (radius > 0) {
                new BlastEMP(entityPlayer.worldObj, null, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, radius).setEffectBlocks().setEffectEntities().doExplode();
                switch(entityPlayer.worldObj.rand.nextInt(20)) {
                    case 0:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Did you pay the power bill?"));
                        return;
                    case 1:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("See them power their toys now!"));
                        return;
                    case 2:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Hey who turned the lights out."));
                        return;
                    case 3:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Ha! I run on steam power!"));
                        return;
                    case 4:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("The power of lighting at my finger tips!"));
                        return;
                    default:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Zap!"));
                        return;
                }
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        }
    } catch (Exception e) {
    }
    throw new WrongUsageException(this.getCommandUsage(sender));
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityMissile(icbm.classic.content.entity.EntityMissile) BlastEMP(icbm.classic.content.explosive.blast.BlastEMP) WrongUsageException(net.minecraft.command.WrongUsageException) WrongUsageException(net.minecraft.command.WrongUsageException) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) List(java.util.List) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 3 with EntityFlyingBlock

use of icbm.classic.content.entity.EntityFlyingBlock in project ICBM-Classic by BuiltBrokenModding.

the class BlastSonic method doExplode.

@Override
public void doExplode() {
    int r = this.callCount;
    if (!this.world().isRemote) {
        if (this.thread != null && this.thread.isComplete) {
            Iterator<Pos> it = this.thread.results.iterator();
            while (it.hasNext()) {
                Pos targetPosition = it.next();
                double distance = targetPosition.distance(position);
                if (distance > r || distance < r - 3) {
                    continue;
                }
                Block blockID = this.world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                if (blockID == Blocks.air || blockID.blockHardness < 0) {
                    continue;
                }
                //if (block instanceof IForceFieldBlock)
                //{
                //    continue;
                //}
                int metadata = this.world().getBlockMetadata(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                if (distance < r - 1 || this.world().rand.nextInt(3) > 0) {
                    if (blockID == ICBMClassic.blockExplosive) {
                        BlockExplosive.triggerExplosive(this.world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), ((TileEntityExplosive) this.world().getTileEntity(targetPosition.xi(), targetPosition.yi(), targetPosition.zi())).explosive, 1);
                    } else {
                        this.world().setBlockToAir(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                    }
                    targetPosition = targetPosition.add(0.5D);
                    if (this.world().rand.nextFloat() < 0.3 * (this.getRadius() - r)) {
                        EntityFlyingBlock entity = new EntityFlyingBlock(this.world(), targetPosition, blockID, metadata);
                        this.world().spawnEntityInWorld(entity);
                        entity.yawChange = 50 * this.world().rand.nextFloat();
                        entity.pitchChange = 100 * this.world().rand.nextFloat();
                    }
                    it.remove();
                }
            }
        }
    }
    int radius = 2 * this.callCount;
    AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - radius, position.y() - radius, position.z() - radius, position.x() + radius, position.y() + radius, position.z() + radius);
    List<Entity> allEntities = this.world().getEntitiesWithinAABB(Entity.class, bounds);
    synchronized (allEntities) {
        for (Iterator it = allEntities.iterator(); it.hasNext(); ) {
            Entity entity = (Entity) it.next();
            if (entity instanceof EntityMissile) {
                ((EntityMissile) entity).setExplode();
                break;
            } else {
                double xDifference = entity.posX - position.x();
                double zDifference = entity.posZ - position.z();
                r = (int) this.getRadius();
                if (xDifference < 0) {
                    r = (int) -this.getRadius();
                }
                entity.motionX += (r - xDifference) * 0.02 * this.world().rand.nextFloat();
                entity.motionY += 3 * this.world().rand.nextFloat();
                r = (int) this.getRadius();
                if (zDifference < 0) {
                    r = (int) -this.getRadius();
                }
                entity.motionZ += (r - zDifference) * 0.02 * this.world().rand.nextFloat();
            }
        }
    }
    if (this.callCount > this.getRadius()) {
        this.controller.endExplosion();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) Iterator(java.util.Iterator) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) EntityMissile(icbm.classic.content.entity.EntityMissile)

Example 4 with EntityFlyingBlock

use of icbm.classic.content.entity.EntityFlyingBlock in project ICBM-Classic by BuiltBrokenModding.

the class BlastRedmatter method doDestroyBlocks.

protected void doDestroyBlocks() {
    // Try to find and grab some blocks to orbit
    int blocksDestroyed = 0;
    for (int currentRadius = 1; currentRadius < getRadius(); currentRadius++) {
        for (int xr = -currentRadius; xr < currentRadius; xr++) {
            for (int yr = -currentRadius; yr < currentRadius; yr++) {
                for (int zr = -currentRadius; zr < currentRadius; zr++) {
                    final Location currentPos = position.add(xr, yr, zr);
                    final double dist = position.distance(currentPos);
                    //We are looping in a shell orbit around the center
                    if (dist < currentRadius && dist > currentRadius - 2) {
                        final Block block = currentPos.getBlock();
                        //Null if call was made on an unloaded chunk
                        if (block != null) {
                            int meta = currentPos.getBlockMetadata();
                            //Ignore air blocks and unbreakable blocks
                            if (!block.isAir(world(), currentPos.xi(), currentPos.yi(), currentPos.zi()) && block.getBlockHardness(this.world(), currentPos.xi(), currentPos.yi(), currentPos.zi()) >= 0) {
                                //TODO handle multi-blocks
                                final boolean isFluid = block instanceof BlockLiquid || block instanceof IFluidBlock;
                                currentPos.setBlock(Blocks.air, 0, isFluid ? 0 : 3);
                                //TODO: render fluid streams moving into hole
                                if (!isFluid && doFlyingBlocks) {
                                    //Convert a random amount of destroyed blocks into flying blocks for visuals
                                    if (this.world().rand.nextFloat() > 0.8) {
                                        EntityFlyingBlock entity = new EntityFlyingBlock(this.world(), currentPos.add(0.5D), block, meta);
                                        entity.yawChange = 50 * this.world().rand.nextFloat();
                                        entity.pitchChange = 50 * this.world().rand.nextFloat();
                                        this.world().spawnEntityInWorld(entity);
                                    }
                                }
                                //Keep track of blocks removed to keep from lagging the game
                                blocksDestroyed++;
                                if (blocksDestroyed > this.MAX_BLOCKS_REMOVED_PER_TICK) {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 5 with EntityFlyingBlock

use of icbm.classic.content.entity.EntityFlyingBlock 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)

Aggregations

EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)11 Block (net.minecraft.block.Block)6 Entity (net.minecraft.entity.Entity)5 Pos (com.builtbroken.mc.imp.transform.vector.Pos)4 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)4 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)3 BlockPos (net.minecraft.util.math.BlockPos)3 Location (com.builtbroken.mc.imp.transform.vector.Location)2 EntityExplosion (icbm.classic.content.entity.EntityExplosion)2 EntityMissile (icbm.classic.content.entity.EntityMissile)2 BlockLiquid (net.minecraft.block.BlockLiquid)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)1 IMissile (icbm.classic.api.caps.IMissile)1 IBlast (icbm.classic.api.explosion.IBlast)1 BlastAntimatter (icbm.classic.content.blast.threaded.BlastAntimatter)1 TileEntityExplosive (icbm.classic.content.blocks.explosive.TileEntityExplosive)1 EntityExplosive (icbm.classic.content.entity.EntityExplosive)1