Search in sources :

Example 31 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class BlastEMP method doExplode.

@Override
public void doExplode() {
    if (!world().isRemote) {
        if (this.effectBlocks) {
            for (int x = (int) -this.getRadius(); x < (int) this.getRadius(); x++) {
                for (int y = (int) -this.getRadius(); y < (int) this.getRadius(); y++) {
                    for (int z = (int) -this.getRadius(); z < (int) this.getRadius(); z++) {
                        double dist = MathHelper.sqrt_double((x * x + y * y + z * z));
                        Pos searchPosition = new Pos(x, y, z).add(position);
                        if (dist > this.getRadius()) {
                            continue;
                        }
                        if (Math.round(position.x() + y) == position.yi()) {
                            world().spawnParticle("largesmoke", searchPosition.x(), searchPosition.y(), searchPosition.z(), 0, 0, 0);
                        }
                        Block block = searchPosition.getBlock(world());
                        TileEntity tileEntity = searchPosition.getTileEntity(world());
                        //TODO more EMP effect to UniversalEnergySystem to better support cross mod support
                        if (block != null) {
                            //}
                            if (block instanceof IEMPBlock) {
                                ((IEMPBlock) block).onEMP(world(), searchPosition.xi(), searchPosition.yi(), searchPosition.zi(), this);
                            }
                        }
                        if (tileEntity != null) {
                            //if (tileEntity instanceof IFortronStorage)
                            //{
                            //    ((IFortronStorage) tileEntity).provideFortron((int) world().rand.nextFloat() * ((IFortronStorage) tileEntity).getFortronCapacity(), true);
                            //}
                            UniversalEnergySystem.clearEnergy(tileEntity, true);
                        }
                    }
                }
            }
        }
        if (this.effectEntities) {
            // Drop all missiles
            List<Entity> entitiesNearby = RadarRegistry.getAllLivingObjectsWithin(world(), new Cube(position.sub(getRadius()), position.add(getRadius())), null);
            for (Entity entity : entitiesNearby) {
                if (entity instanceof IMissile && !entity.isEntityEqual(this.controller)) {
                    if (((IMissile) entity).getTicksInAir() > -1) {
                        ((IMissile) entity).dropMissileAsItem();
                    }
                }
            }
            int maxFx = 10;
            AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - this.getRadius(), position.y() - this.getRadius(), position.z() - this.getRadius(), position.x() + this.getRadius(), position.y() + this.getRadius(), position.z() + this.getRadius());
            List<Entity> entities = world().getEntitiesWithinAABB(Entity.class, bounds);
            for (Entity entity : entities) {
                if (entity instanceof EntityLivingBase) {
                    if (this.world().isRemote && maxFx > 0) {
                        ICBMClassic.proxy.spawnShock(this.world(), this.position, new Pos(entity), 20);
                        maxFx--;
                    }
                    if (entity instanceof EntityCreeper) {
                        if (!this.world().isRemote) {
                            try {
                                ((EntityCreeper) entity).getDataWatcher().updateObject(17, (byte) 1);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    if (entity instanceof EntityPlayer) {
                        IInventory inventory = ((EntityPlayer) entity).inventory;
                        for (int i = 0; i < inventory.getSizeInventory(); i++) {
                            ItemStack itemStack = inventory.getStackInSlot(i);
                            if (itemStack != null) {
                                if (itemStack.getItem() instanceof IEMPItem) {
                                    ((IEMPItem) itemStack.getItem()).onEMP(itemStack, entity, this);
                                }
                                UniversalEnergySystem.clearEnergy(itemStack, true);
                            }
                        }
                    }
                } else if (entity instanceof EntityExplosive) {
                    entity.setDead();
                }
            }
        }
        VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 1, 3);
        VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 3, 3);
        VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 5, 3);
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "emp", 4.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 0.7F);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IInventory(net.minecraft.inventory.IInventory) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IEMPItem(resonant.api.explosion.IEMPItem) IEMPBlock(resonant.api.explosion.IEMPBlock) TileEntity(net.minecraft.tileentity.TileEntity) IMissile(resonant.api.explosion.IMissile) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IEMPBlock(resonant.api.explosion.IEMPBlock) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosive(icbm.classic.content.entity.EntityExplosive) ItemStack(net.minecraft.item.ItemStack)

Example 32 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class EntityMissile method getPredictedPosition.

public Pos getPredictedPosition(int t) {
    Pos guJiDiDian = toPos();
    double tempMotionY = this.motionY;
    if (this.ticksInAir > 20) {
        for (int i = 0; i < t; i++) {
            if (this.missileType == MissileType.CruiseMissile || this.missileType == MissileType.LAUNCHER) {
                guJiDiDian = guJiDiDian.add(this.xiaoDanMotion);
            } else {
                guJiDiDian = guJiDiDian.add(motionX, tempMotionY - this.acceleration, motionZ);
            }
        }
    }
    return guJiDiDian;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 33 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos 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 34 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos 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 35 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherScreen method receiveRadioWave.

@Override
public void receiveRadioWave(float hz, IRadioWaveSender sender, String messageHeader, Object[] data) {
    //Floor frequency as we do not care about sub ranges
    int frequency = (int) Math.floor(hz);
    //Only tier 3 (2 for tier value) can be remotely fired
    if (getTier() == 2 && frequency == getFrequency() && laucherBase != null) {
        //Laser detonator signal
        if (messageHeader.equals("activateLauncherWithTarget")) {
            Pos pos = (Pos) data[0];
            if (toPos().distance(pos) < this.laucherBase.getRange()) {
                setTarget(pos);
                launch();
                ((FakeRadioSender) sender).player.addChatComponentMessage(new ChatComponentText("Firing missile at " + pos));
            }
        } else //Remote detonator signal
        if (messageHeader.equals("activateLauncher")) {
            ((FakeRadioSender) sender).player.addChatComponentMessage(new ChatComponentText("Firing missile at " + getTarget()));
            launch();
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) FakeRadioSender(com.builtbroken.mc.prefab.hz.FakeRadioSender) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

Pos (com.builtbroken.mc.imp.transform.vector.Pos)105 Block (net.minecraft.block.Block)25 TileEntity (net.minecraft.tileentity.TileEntity)13 Location (com.builtbroken.mc.imp.transform.vector.Location)11 Entity (net.minecraft.entity.Entity)11 Cube (com.builtbroken.mc.imp.transform.region.Cube)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Test (org.junit.Test)7 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)6 EntityMissile (icbm.classic.content.entity.EntityMissile)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)5 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)5 ItemStack (net.minecraft.item.ItemStack)5 EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4