Search in sources :

Example 1 with EntityMissile

use of icbm.classic.content.entity.EntityMissile 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 2 with EntityMissile

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

the class TileCruiseLauncher method launch.

/**
     * Launches the missile
     */
@Override
public void launch() {
    if (this.canLaunch()) {
        this.extractEnergy();
        EntityMissile entityMissile = new EntityMissile(world(), xi() + 0.5, yi() + 1.5, zi() + 0.5, -(float) currentAim.yaw() - 180, -(float) currentAim.pitch(), 2);
        entityMissile.missileType = EntityMissile.MissileType.CruiseMissile;
        entityMissile.explosiveID = Explosives.get(this.getStackInSlot(0).getItemDamage());
        entityMissile.acceleration = 1;
        entityMissile.launch(null);
        world().spawnEntityInWorld(entityMissile);
        //Clear slot last so we can still access data as needed or roll back changes if a crash happens
        this.decrStackSize(0, 1);
    }
}
Also used : EntityMissile(icbm.classic.content.entity.EntityMissile)

Example 3 with EntityMissile

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

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

the class MissileAnti method update.

@Override
public void update(EntityMissile missileObj) {
    if (missileObj.lockedTarget != null) {
        Pos target = new Pos(missileObj.lockedTarget);
        if (missileObj.lockedTarget.isDead) {
            missileObj.explode();
            return;
        }
        if (missileObj.lockedTarget instanceof EntityMissile) {
            target = ((EntityMissile) missileObj.lockedTarget).getPredictedPosition(4);
        }
        missileObj.motionX = (target.x() - missileObj.posX) * (0.3F);
        missileObj.motionY = (target.y() - missileObj.posY) * (0.3F);
        missileObj.motionZ = (target.z() - missileObj.posZ) * (0.3F);
        return;
    }
    AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(missileObj.posX - ABMRange, missileObj.posY - ABMRange, missileObj.posZ - ABMRange, missileObj.posX + ABMRange, missileObj.posY + ABMRange, missileObj.posZ + ABMRange);
    // TODO: Check if this works.
    Entity nearestEntity = missileObj.worldObj.findNearestEntityWithinAABB(EntityMissile.class, bounds, missileObj);
    if (nearestEntity instanceof EntityMissile) {
        // Lock target onto missileObj missile
        missileObj.lockedTarget = nearestEntity;
        missileObj.didTargetLockBefore = true;
        missileObj.worldObj.playSoundAtEntity(missileObj, ICBMClassic.PREFIX + "targetlocked", 5F, 0.9F);
    } else {
        missileObj.motionX = missileObj.deltaPathX / missileObj.missileFlightTime;
        missileObj.motionZ = missileObj.deltaPathZ / missileObj.missileFlightTime;
        if (missileObj.didTargetLockBefore == true) {
            missileObj.explode();
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityMissile(icbm.classic.content.entity.EntityMissile)

Example 5 with EntityMissile

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

the class MissileNuclearCluster method update.

@Override
public void update(EntityMissile missileObj) {
    if (missileObj.motionY < -0.5) {
        if (missileObj.missileCount < MAX_CLUSTER) {
            if (!missileObj.worldObj.isRemote) {
                Pos position = missileObj.toPos();
                EntityMissile clusterMissile = new EntityMissile(missileObj.worldObj);
                //TODO randomize spread to prevent collisions
                clusterMissile.setPosition(position.x(), position.y(), position.z());
                clusterMissile.explosiveID = Explosives.NUCLEAR;
                missileObj.worldObj.spawnEntityInWorld(clusterMissile);
                clusterMissile.missileType = MissileType.CruiseMissile;
                clusterMissile.protectionTime = 20;
                clusterMissile.launch(missileObj.targetVector.add(new Pos((missileObj.missileCount - MAX_CLUSTER / 2) * random() * 30, (missileObj.missileCount - MAX_CLUSTER / 2) * random() * 30, (missileObj.missileCount - MAX_CLUSTER / 2) * random() * 30)));
            }
            missileObj.protectionTime = 20;
            missileObj.missileCount++;
        } else {
            missileObj.setDead();
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityMissile(icbm.classic.content.entity.EntityMissile)

Aggregations

EntityMissile (icbm.classic.content.entity.EntityMissile)13 Pos (com.builtbroken.mc.imp.transform.vector.Pos)6 Entity (net.minecraft.entity.Entity)6 Point (com.builtbroken.mc.imp.transform.vector.Point)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)3 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)2 Explosive (icbm.classic.content.explosive.Explosive)2 Explosion (icbm.classic.content.explosive.ex.Explosion)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 IItemFrequency (com.builtbroken.mc.api.items.hz.IItemFrequency)1 Rectangle (com.builtbroken.mc.imp.transform.region.Rectangle)1 Location (com.builtbroken.mc.imp.transform.vector.Location)1 EntityExplosion (icbm.classic.content.entity.EntityExplosion)1 Explosives (icbm.classic.content.explosive.Explosives)1 BlastEMP (icbm.classic.content.explosive.blast.BlastEMP)1 Iterator (java.util.Iterator)1 List (java.util.List)1