Search in sources :

Example 36 with Pos

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

the class BlastSonic method doPreExplode.

@Override
public void doPreExplode() {
    if (!this.world().isRemote) {
        if (this.hasShockWave) {
            for (int x = (int) (-this.getRadius() * 2); x < this.getRadius() * 2; ++x) {
                for (int y = (int) (-this.getRadius() * 2); y < this.getRadius() * 2; ++y) {
                    for (int z = (int) (-this.getRadius() * 2); z < this.getRadius() * 2; ++z) {
                        Location targetPosition = position.add(new Pos(x, y, z));
                        Block blockID = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                        if (blockID != Blocks.air) {
                            Material material = blockID.getMaterial();
                            if (blockID != Blocks.bedrock && !(material.isLiquid()) && (blockID.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) > this.nengLiang || material == Material.glass)) {
                                targetPosition.setBlock(world(), Blocks.air);
                            }
                        }
                    }
                }
            }
        }
        this.thread = new ThreadLargeExplosion(this.position, (int) this.getRadius(), this.nengLiang, this.exploder, new IThreadCallBack() {

            @Override
            public float getResistance(World world, IPos3D explosionPosition, IPos3D targetPosition, Entity source, Block block) {
                float resistance = 0;
                if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
                    resistance = 1f;
                } else {
                    resistance = block.getExplosionResistance(source, world, (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z(), explosionPosition.x(), explosionPosition.y(), explosionPosition.z());
                }
                return resistance;
            }
        });
        this.thread.start();
    }
    if (this.hasShockWave) {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "hypersonic", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    } else {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "sonicwave", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IThreadCallBack(icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack) Material(net.minecraft.block.material.Material) World(net.minecraft.world.World) ThreadLargeExplosion(icbm.classic.content.explosive.thread.ThreadLargeExplosion) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) BlockLiquid(net.minecraft.block.BlockLiquid) Pos(com.builtbroken.mc.imp.transform.vector.Pos) 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 37 with Pos

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

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

the class BlastRepulsive method doExplode.

@Override
public void doExplode() {
    if (!this.world().isRemote) {
        for (int x = 0; x < this.checkBanJing; ++x) {
            for (int y = 0; y < this.checkBanJing; ++y) {
                for (int z = 0; z < this.checkBanJing; ++z) {
                    if (x == 0 || x == this.checkBanJing - 1 || y == 0 || y == this.checkBanJing - 1 || z == 0 || z == this.checkBanJing - 1) {
                        double xStep = x / (this.checkBanJing - 1.0F) * 2.0F - 1.0F;
                        double yStep = y / (this.checkBanJing - 1.0F) * 2.0F - 1.0F;
                        double zStep = z / (this.checkBanJing - 1.0F) * 2.0F - 1.0F;
                        double diagonalDistance = Math.sqrt(xStep * xStep + yStep * yStep + zStep * zStep);
                        xStep /= diagonalDistance;
                        yStep /= diagonalDistance;
                        zStep /= diagonalDistance;
                        float var14 = this.getRadius() * (0.7F + this.world().rand.nextFloat() * 0.6F);
                        double var15 = this.position.x();
                        double var17 = this.position.y();
                        double var19 = this.position.z();
                        for (float var21 = 0.3F; var14 > 0.0F; var14 -= var21 * 0.75F) {
                            int var22 = MathHelper.floor_double(var15);
                            int var23 = MathHelper.floor_double(var17);
                            int var24 = MathHelper.floor_double(var19);
                            Block var25 = this.world().getBlock(var22, var23, var24);
                            if (var25 != Blocks.air) {
                                var14 -= (var25.getExplosionResistance(this.exploder, this.world(), var22, var23, var24, this.position.xi(), this.position.yi(), this.position.zi()) + 0.3F) * var21;
                            }
                            if (var14 > 0.0F) {
                                blownBlocks.add(new Pos(var22, var23, var24));
                            }
                            var15 += xStep * var21;
                            var17 += yStep * var21;
                            var19 += zStep * var21;
                        }
                    }
                }
            }
        }
    }
    this.world().playSoundEffect(this.position.x(), this.position.y(), this.position.z(), "random.explode", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    switch(this.pushType) {
        case 0:
            this.doDamageEntities(this.getRadius(), nengLiang, this.destroyItem);
            break;
        default:
            this.pushEntities(12, this.getRadius() * 4, this.pushType);
            break;
    }
    if (!this.world().isRemote) {
        int var3;
        Pos blownPosition;
        int var5;
        int var6;
        int var7;
        Block block;
        int metadata;
        for (var3 = blownBlocks.size() - 1; var3 >= 0; --var3) {
            blownPosition = blownBlocks.get(var3);
            var5 = blownPosition.xi();
            var6 = blownPosition.yi();
            var7 = blownPosition.zi();
            block = this.world().getBlock(var5, var6, var7);
            metadata = this.world().getBlockMetadata(var5, var6, var7);
            double var9 = (var5 + this.world().rand.nextFloat());
            double var11 = (var6 + this.world().rand.nextFloat());
            double var13 = (var7 + this.world().rand.nextFloat());
            double var151 = var9 - this.position.y();
            double var171 = var11 - this.position.y();
            double var191 = var13 - this.position.z();
            double var211 = MathHelper.sqrt_double(var151 * var151 + var171 * var171 + var191 * var191);
            var151 /= var211;
            var171 /= var211;
            var191 /= var211;
            double var23 = 0.5D / (var211 / this.getRadius() + 0.1D);
            var23 *= (this.world().rand.nextFloat() * this.world().rand.nextFloat() + 0.3F);
            var151 *= var23;
            var171 *= var23;
            var191 *= var23;
            this.world().spawnParticle("explode", (var9 + this.position.x() * 1.0D) / 2.0D, (var11 + this.position.y() * 1.0D) / 2.0D, (var13 + this.position.z() * 1.0D) / 2.0D, var151, var171, var191);
            this.world().spawnParticle("smoke", var9, var11, var13, var151, var171, var191);
            if (block != Blocks.air) {
                try {
                    if (block.canDropFromExplosion(null)) {
                        block.dropBlockAsItemWithChance(this.world(), var5, var6, var7, this.world().getBlockMetadata(var5, var6, var7), 1F, 0);
                    }
                    block.onBlockExploded(this.world(), var5, var6, var7, this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block)

Example 39 with Pos

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

the class BlastExothermic method doPostExplode.

@Override
public void doPostExplode() {
    super.doPostExplode();
    if (!this.world().isRemote) {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "powerdown", 4.0F, 0.8F);
        if (this.canFocusBeam(this.world(), position) && this.thread.isComplete) {
            for (Pos targetPosition : this.thread.results) {
                double distanceFromCenter = position.distance(targetPosition);
                if (distanceFromCenter > this.getRadius()) {
                    continue;
                }
                /*
                     * Reduce the chance of setting blocks on fire based on distance from center.
                     */
                double chance = this.getRadius() - (Math.random() * distanceFromCenter);
                if (chance > distanceFromCenter * 0.55) {
                    /*
                         * Check to see if the block is an air block and there is a block below it
                         * to support the fire.
                         */
                    Block blockID = this.world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                    if (blockID.getMaterial() == Material.water || blockID == Blocks.ice) {
                        this.world().setBlockToAir(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                    }
                    if (blockID.blockMaterial == Material.rock && this.world().rand.nextFloat() > 0.8) {
                        this.world().setBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), Blocks.flowing_lava, 0, 2);
                    }
                    Block blockBellow = world().getBlock(targetPosition.xi(), targetPosition.yi() - 1, targetPosition.zi());
                    if ((blockID.isReplaceable(world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi())) && blockBellow.getMaterial().isSolid() && blockBellow.isSideSolid(world(), targetPosition.xi(), targetPosition.yi() - 1, targetPosition.zi(), ForgeDirection.UP)) {
                        if (this.world().rand.nextFloat() > 0.99) {
                            this.world().setBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), Blocks.flowing_lava, 0, 2);
                        } else {
                            this.world().setBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), Blocks.fire, 0, 2);
                            blockID = this.world().getBlock(targetPosition.xi(), targetPosition.yi() - 1, targetPosition.zi());
                            if (((ExExothermic) Explosives.EXOTHERMIC.handler).createNetherrack && (blockID == Blocks.stone || blockID == Blocks.grass || blockID == Blocks.dirt) && this.world().rand.nextFloat() > 0.75) {
                                this.world().setBlock(targetPosition.xi(), targetPosition.yi() - 1, targetPosition.zi(), Blocks.netherrack, 0, 2);
                            }
                        }
                    }
                }
            }
            this.world().playSoundEffect(position.x() + 0.5D, position.y() + 0.5D, position.z() + 0.5D, ICBMClassic.PREFIX + "explosionfire", 6.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 1F);
        }
        if (!world().getGameRules().getGameRuleBooleanValue("doDaylightCycle")) {
            this.world().setWorldTime(18000);
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block) ExExothermic(icbm.classic.content.explosive.ex.ExExothermic)

Example 40 with Pos

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

the class BlastFire method doExplode.

@Override
public void doExplode() {
    if (!this.world().isRemote) {
        int radius = (int) this.getRadius();
        for (int x = 0; x < radius; ++x) {
            for (int y = 0; y < radius; ++y) {
                for (int z = 0; z < radius; ++z) {
                    if (x == 0 || x == radius - 1 || y == 0 || y == radius - 1 || z == 0 || z == radius - 1) {
                        double xStep = x / (radius - 1.0F) * 2.0F - 1.0F;
                        double yStep = y / (radius - 1.0F) * 2.0F - 1.0F;
                        double zStep = z / (radius - 1.0F) * 2.0F - 1.0F;
                        double diagonalDistance = Math.sqrt(xStep * xStep + yStep * yStep + zStep * zStep);
                        xStep /= diagonalDistance;
                        yStep /= diagonalDistance;
                        zStep /= diagonalDistance;
                        float var14 = radius * (0.7F + world().rand.nextFloat() * 0.6F);
                        double var15 = position.x();
                        double var17 = position.y();
                        double var19 = position.z();
                        for (float var21 = 0.3F; var14 > 0.0F; var14 -= var21 * 0.75F) {
                            Pos targetPosition = new Pos(var15, var17, var19);
                            double distanceFromCenter = position.distance(targetPosition);
                            Block var25 = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                            if (var25 != Blocks.air) {
                                var14 -= (var25.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) + 0.3F) * var21;
                            }
                            if (var14 > 0.0F) {
                                // Set fire by chance and distance
                                double chance = radius - (Math.random() * distanceFromCenter);
                                if (chance > distanceFromCenter * 0.55) {
                                    /*
                                         * Check to see if the block is an air block and there is a
                                         * block below it to support the fire.
                                         */
                                    Block block = world().getBlock((int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z());
                                    boolean canReplace = block.isReplaceable(world(), (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z()) || block.isAir(world(), (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z());
                                    if (canReplace && Blocks.fire.canPlaceBlockAt(world(), (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z())) {
                                        targetPosition.setBlock(world(), Blocks.fire);
                                    } else if (block == Blocks.ice) {
                                        targetPosition.setBlockToAir(world());
                                    }
                                }
                            }
                            var15 += xStep * var21;
                            var17 += yStep * var21;
                            var19 += zStep * var21;
                        }
                    }
                }
            }
        }
    }
    world().playSoundEffect(position.x() + 0.5D, position.y() + 0.5D, position.z() + 0.5D, ICBMClassic.PREFIX + "explosionfire", 4.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 1F);
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block)

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