Search in sources :

Example 6 with EntityMissile

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

the class TileRadarStation method isPoweringTo.

public boolean isPoweringTo(ForgeDirection side) {
    if (incomingMissiles.size() > 0) {
        if (this.emitAll) {
            return true;
        }
        for (EntityMissile incomingMissile : this.incomingMissiles) {
            Point position = incomingMissile.toPos().toVector2();
            ForgeDirection missileTravelDirection = ForgeDirection.UNKNOWN;
            double closest = -1;
            for (int i = 2; i < 6; i++) {
                double dist = position.distance(new Point(this.xCoord + ForgeDirection.getOrientation(i).offsetX, this.zCoord + ForgeDirection.getOrientation(i).offsetZ));
                if (dist < closest || closest < 0) {
                    missileTravelDirection = ForgeDirection.getOrientation(i);
                    closest = dist;
                }
            }
            if (missileTravelDirection.getOpposite() == side) {
                return true;
            }
        }
    }
    return false;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Point(com.builtbroken.mc.imp.transform.vector.Point) EntityMissile(icbm.classic.content.entity.EntityMissile) Point(com.builtbroken.mc.imp.transform.vector.Point)

Example 7 with EntityMissile

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

the class TileRadarStation method doScan.

private void doScan() {
    this.incomingMissiles.clear();
    this.detectedEntities.clear();
    List<Entity> entities = RadarRegistry.getAllLivingObjectsWithin(world(), xi() + 1.5, yi() + 0.5, zi() + 0.5, MAX_DETECTION_RANGE, null);
    for (Entity entity : entities) {
        if (entity instanceof EntityMissile) {
            if (((EntityMissile) entity).getTicksInAir() > -1) {
                if (!this.detectedEntities.contains(entity)) {
                    this.detectedEntities.add(entity);
                }
                if (this.isMissileGoingToHit((EntityMissile) entity)) {
                    if (this.incomingMissiles.size() > 0) {
                        /** Sort in order of distance */
                        double dist = new Pos((TileEntity) this).distance(new Pos(entity));
                        for (int i = 0; i < this.incomingMissiles.size(); i++) {
                            EntityMissile daoDan = this.incomingMissiles.get(i);
                            if (dist < new Pos((TileEntity) this).distance(daoDan.toPos())) {
                                this.incomingMissiles.add(i, (EntityMissile) entity);
                                break;
                            } else if (i == this.incomingMissiles.size() - 1) {
                                this.incomingMissiles.add((EntityMissile) entity);
                                break;
                            }
                        }
                    } else {
                        this.incomingMissiles.add((EntityMissile) entity);
                    }
                }
            }
        } else {
            this.detectedEntities.add(entity);
        }
    }
    List<EntityPlayer> players = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(this.xCoord - MAX_DETECTION_RANGE, this.yCoord - MAX_DETECTION_RANGE, this.zCoord - MAX_DETECTION_RANGE, this.xCoord + MAX_DETECTION_RANGE, this.yCoord + MAX_DETECTION_RANGE, this.zCoord + MAX_DETECTION_RANGE));
    for (EntityPlayer player : players) {
        if (player != null) {
            boolean youHuoLuan = false;
            for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                ItemStack itemStack = player.inventory.getStackInSlot(i);
                if (itemStack != null) {
                    if (itemStack.getItem() instanceof IItemFrequency) {
                        youHuoLuan = true;
                        break;
                    }
                }
            }
            if (!youHuoLuan) {
                this.detectedEntities.add(player);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityMissile(icbm.classic.content.entity.EntityMissile) Point(com.builtbroken.mc.imp.transform.vector.Point) IItemFrequency(com.builtbroken.mc.api.items.hz.IItemFrequency)

Example 8 with EntityMissile

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

the class Blast method doDamageEntities.

protected void doDamageEntities(float radius, float power, boolean destroyItem) {
    // Step 2: Damage all entities
    radius *= 2.0F;
    Location minCoord = position.add(-radius - 1);
    Location maxCoord = position.add(radius + 1);
    List<Entity> allEntities = world().getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(minCoord.xi(), minCoord.yi(), minCoord.zi(), maxCoord.xi(), maxCoord.yi(), maxCoord.zi()));
    Vec3 var31 = Vec3.createVectorHelper(position.x(), position.y(), position.z());
    for (int i = 0; i < allEntities.size(); ++i) {
        Entity entity = allEntities.get(i);
        if (this.onDamageEntity(entity)) {
            continue;
        }
        if (entity instanceof EntityMissile) {
            ((EntityMissile) entity).setExplode();
            continue;
        }
        if (entity instanceof EntityItem && !destroyItem) {
            continue;
        }
        double distance = entity.getDistance(position.x(), position.y(), position.z()) / radius;
        if (distance <= 1.0D) {
            double xDifference = entity.posX - position.x();
            double yDifference = entity.posY - position.y();
            double zDifference = entity.posZ - position.z();
            double var35 = MathHelper.sqrt_double(xDifference * xDifference + yDifference * yDifference + zDifference * zDifference);
            xDifference /= var35;
            yDifference /= var35;
            zDifference /= var35;
            double var34 = world().getBlockDensity(var31, entity.boundingBox);
            double var36 = (1.0D - distance) * var34;
            int damage = 0;
            damage = (int) ((var36 * var36 + var36) / 2.0D * 8.0D * power + 1.0D);
            entity.attackEntityFrom(DamageSource.setExplosionSource(this), damage);
            entity.motionX += xDifference * var36;
            entity.motionY += yDifference * var36;
            entity.motionZ += zDifference * var36;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityMissile(icbm.classic.content.entity.EntityMissile) EntityItem(net.minecraft.entity.item.EntityItem) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 9 with EntityMissile

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

the class ItemRocketLauncher method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    if (!world.isRemote) {
        long clickMs = System.currentTimeMillis();
        if (clickTimePlayer.containsKey(player.getCommandSenderName())) {
            if (clickMs - clickTimePlayer.get(player.getCommandSenderName()) < firingDelay) {
                //TODO play weapon empty click audio to note the gun is reloading
                return itemStack;
            }
        }
        if (this.getEnergy(itemStack) >= ENERGY || player.capabilities.isCreativeMode) {
            // Check the player's inventory and look for missiles.
            for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++) {
                ItemStack inventoryStack = player.inventory.getStackInSlot(slot);
                if (inventoryStack != null) {
                    if (inventoryStack.getItem() instanceof ItemMissile) {
                        int meta = inventoryStack.getItemDamage();
                        Explosives ex = Explosives.get(meta);
                        ExplosivePreDetonationEvent evt = new ExplosivePreDetonationEvent(world, player.posX, player.posY, player.posZ, ExplosiveType.AIR, Explosives.get(meta).handler);
                        MinecraftForge.EVENT_BUS.post(evt);
                        if (((Explosion) ex.handler) != null && !evt.isCanceled()) {
                            // Limit the missile to tier two.
                            if ((((Explosion) ex.handler).getTier() <= Settings.MAX_ROCKET_LAUCNHER_TIER || Engine.runningAsDev) && ((Explosion) ex.handler).isCruise()) {
                                EntityMissile entityMissile = new EntityMissile(player);
                                entityMissile.missileType = EntityMissile.MissileType.LAUNCHER;
                                entityMissile.explosiveID = ex;
                                entityMissile.acceleration = 1;
                                entityMissile.launch(null);
                                world.spawnEntityInWorld(entityMissile);
                                if (player.isSneaking()) {
                                    player.mountEntity(entityMissile);
                                    player.setSneaking(false);
                                }
                                if (!player.capabilities.isCreativeMode) {
                                    player.inventory.setInventorySlotContents(slot, null);
                                    player.inventoryContainer.detectAndSendChanges();
                                    this.discharge(itemStack, ENERGY, true);
                                }
                                //Store last time player launched a rocket
                                clickTimePlayer.put(player.getCommandSenderName(), clickMs);
                                return itemStack;
                            }
                        } else {
                            player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("message.launcher.protected")));
                        }
                    }
                }
            }
        }
    }
    return itemStack;
}
Also used : Explosion(icbm.classic.content.explosive.ex.Explosion) ExplosivePreDetonationEvent(resonant.api.explosion.ExplosionEvent.ExplosivePreDetonationEvent) Explosives(icbm.classic.content.explosive.Explosives) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText) EntityMissile(icbm.classic.content.entity.EntityMissile)

Example 10 with EntityMissile

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

the class MissileCluster 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 missile = new EntityMissile(missileObj.worldObj);
                //TODO spread to avoid collision
                missile.setPosition(position.x(), position.y(), position.z());
                missile.launcherPos = position;
                missile.explosiveID = Explosives.CONDENSED;
                double radius = spread;
                double theta = 0;
                double x = 0;
                double y = 0;
                double z = 0;
                if (missileObj.missileCount > 0) {
                    theta = (missileObj.missileCount / 12.0) * Math.PI * 2;
                    x = radius * Math.cos(theta);
                    missile.posX += Math.cos(theta) * 5;
                    z = radius * Math.sin(theta);
                    missile.posZ += Math.sin(theta) * 5;
                }
                missile.missileType = MissileType.CruiseMissile;
                missile.protectionTime = 20 + missileObj.targetHeight - 1;
                missile.launch(missileObj.targetVector.add(new Pos(x, y, z)));
                missileObj.worldObj.spawnEntityInWorld(missile);
            }
            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