Search in sources :

Example 11 with Location

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

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

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

the class ThreadLargeExplosion method run.

@Override
public void run() {
    int steps = (int) Math.ceil(Math.PI / Math.atan(1.0D / this.radius));
    for (int phi_n = 0; phi_n < 2 * steps; phi_n++) {
        for (int theta_n = 0; theta_n < steps; theta_n++) {
            double phi = Math.PI * 2 / steps * phi_n;
            double theta = Math.PI / steps * theta_n;
            Pos delta = new Pos(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi));
            float power = this.energy - (this.energy * this.position.world().rand.nextFloat() / 2);
            Location t = position;
            for (float d = 0.3F; power > 0f; power -= d * 0.75F * 10) {
                if (t.distance(position) > this.radius) {
                    break;
                }
                Block block = t.getBlock();
                if (block != null) {
                    if (block.getBlockHardness(this.position.world(), t.xi(), t.yi(), t.zi()) >= 0) {
                        power -= this.callBack.getResistance(this.position.world(), position, t, source, block);
                        if (power > 0f) {
                            this.results.add(t.toPos());
                        }
                    }
                }
                t = t.add(delta);
            }
        }
    }
    super.run();
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 14 with Location

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

the class BlastEnderman method doExplode.

@Override
public void doExplode() {
    if (this.world().isRemote) {
        int r = (int) (this.getRadius() - ((double) this.callCount / (double) this.duration) * this.getRadius());
        for (int x = -r; x < r; x++) {
            for (int z = -r; z < r; z++) {
                for (int y = -r; y < r; y++) {
                    Location targetPosition = position.add(new Pos(x, y, z));
                    double distance = targetPosition.distance(position);
                    if (distance < r && distance > r - 1) {
                        if (targetPosition.getBlock(world()) != Blocks.air)
                            continue;
                        if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.01)) {
                            float velX = (float) ((targetPosition.x() - position.x()) * 0.6);
                            float velY = (float) ((targetPosition.y() - position.y()) * 0.6);
                            float velZ = (float) ((targetPosition.z() - position.z()) * 0.6);
                            ICBMClassic.proxy.spawnParticle("portal", world(), targetPosition, velX, velY, velZ, 5f, 1);
                        }
                    }
                }
            }
        }
    }
    int radius = (int) this.getRadius();
    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 = world().getEntitiesWithinAABB(Entity.class, bounds);
    boolean explosionCreated = false;
    for (Entity entity : allEntities) {
        if (entity != this.controller) {
            double xDifference = entity.posX - position.x();
            double yDifference = entity.posY - position.y();
            double zDifference = entity.posZ - position.z();
            int r = (int) this.getRadius();
            if (xDifference < 0)
                r = (int) -this.getRadius();
            entity.motionX -= (r - xDifference) * Math.abs(xDifference) * 0.0006;
            r = (int) this.getRadius();
            if (entity.posY > position.y())
                r = (int) -this.getRadius();
            entity.motionY += (r - yDifference) * Math.abs(yDifference) * 0.0011;
            r = (int) this.getRadius();
            if (zDifference < 0)
                r = (int) -this.getRadius();
            entity.motionZ -= (r - zDifference) * Math.abs(zDifference) * 0.0006;
            if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < 4) {
                if (!explosionCreated && callCount % 5 == 0) {
                    world().spawnParticle("hugeexplosion", entity.posX, entity.posY, entity.posZ, 0.0D, 0.0D, 0.0D);
                    explosionCreated = true;
                }
                try {
                    /** If a target doesn't exist, search for a random one within 100 block
                         * range. */
                    if (this.teleportTarget == null) {
                        int checkY;
                        int checkX = this.world().rand.nextInt(300) - 150 + (int) this.controller.posX;
                        int checkZ = this.world().rand.nextInt(300) - 150 + (int) this.controller.posZ;
                        for (checkY = 63; !this.world().isAirBlock(checkX, checkY, checkZ) && !this.world().isAirBlock(checkX, checkY + 1, checkZ); ++checkY) {
                            ;
                        }
                        this.teleportTarget = new Pos(checkX, checkY, checkZ);
                    }
                    this.world().playSoundAtEntity(entity, "mob.endermen.portal", 1.0F, 1.0F);
                    if (entity instanceof EntityPlayerMP) {
                        ((EntityPlayerMP) entity).playerNetServerHandler.setPlayerLocation(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5, entity.rotationYaw, entity.rotationPitch);
                    } else {
                        entity.setPosition(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5);
                    }
                } catch (Exception e) {
                    ICBMClassic.INSTANCE.logger().error("Failed to teleport entity to the End.", e);
                }
            }
        }
    }
    this.world().playSound(this.position.x(), this.position.y(), this.position.z(), "portal.portal", 2F, world().rand.nextFloat() * 0.4F + 0.8F, false);
    if (this.callCount > this.duration) {
        this.controller.endExplosion();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 15 with Location

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

the class Blast method onPositionUpdate.

/**
     * Called each tick the blast has moved
     *
     * @param posX
     * @param posY
     * @param posZ
     */
public void onPositionUpdate(double posX, double posY, double posZ) {
    this.explosionX = posX;
    this.explosionY = posY;
    this.explosionZ = posZ;
    position = new Location(world(), posX, posY, posZ);
}
Also used : Location(com.builtbroken.mc.imp.transform.vector.Location)

Aggregations

Location (com.builtbroken.mc.imp.transform.vector.Location)30 Pos (com.builtbroken.mc.imp.transform.vector.Pos)11 Block (net.minecraft.block.Block)7 TileEntity (net.minecraft.tileentity.TileEntity)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 HashMap (java.util.HashMap)5 IMultiTile (com.builtbroken.mc.api.tile.multiblock.IMultiTile)4 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)4 ByteBuf (io.netty.buffer.ByteBuf)4 Map (java.util.Map)4 World (net.minecraft.world.World)4 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)4 IPacketIDReceiver (com.builtbroken.mc.core.network.IPacketIDReceiver)3 IPacketReceiver (com.builtbroken.mc.core.network.IPacketReceiver)3 PacketIDException (com.builtbroken.mc.core.network.ex.PacketIDException)3 PacketTileReadException (com.builtbroken.mc.core.network.ex.PacketTileReadException)3 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 Entity (net.minecraft.entity.Entity)3 Test (org.junit.Test)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)2