Search in sources :

Example 76 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class IEExplosion method doExplosionTick.

public void doExplosionTick() {
    int max = Math.min(blockDestroyInt + blocksPerTick, this.affectedBlockPositions.size());
    for (; blockDestroyInt < max; blockDestroyInt++) {
        BlockPos pos = this.affectedBlockPositions.get(blockDestroyInt);
        IBlockState state = this.worldObj.getBlockState(pos);
        Block block = state.getBlock();
        //			if(spawnParticles)
        {
            double d0 = (double) ((float) pos.getX() + this.worldObj.rand.nextFloat());
            double d1 = (double) ((float) pos.getY() + this.worldObj.rand.nextFloat());
            double d2 = (double) ((float) pos.getZ() + this.worldObj.rand.nextFloat());
            double d3 = d0 - this.explosionX;
            double d4 = d1 - this.explosionY;
            double d5 = d2 - this.explosionZ;
            double d6 = (double) MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
            d3 = d3 / d6;
            d4 = d4 / d6;
            d5 = d5 / d6;
            double d7 = 0.5D / (d6 / (double) this.explosionSize + 0.1D);
            d7 = d7 * (double) (this.worldObj.rand.nextFloat() * this.worldObj.rand.nextFloat() + 0.3F);
            d3 = d3 * d7;
            d4 = d4 * d7;
            d5 = d5 * d7;
            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, (d0 + this.explosionX * 1.0D) / 2.0D, (d1 + this.explosionY * 1.0D) / 2.0D, (d2 + this.explosionZ * 1.0D) / 2.0D, d3, d4, d5);
            this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5);
        }
        if (state.getMaterial() != Material.AIR) {
            if (block.canDropFromExplosion(this))
                block.dropBlockAsItemWithChance(this.worldObj, pos, this.worldObj.getBlockState(pos), dropChance, 0);
            block.onBlockExploded(this.worldObj, pos, this);
        }
    }
    if (blockDestroyInt >= this.affectedBlockPositions.size())
        this.isExplosionFinished = true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 77 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class SkylineHelper method spawnHook.

public static EntitySkylineHook spawnHook(EntityPlayer player, TileEntity start, Connection connection) {
    BlockPos cc0 = connection.end == Utils.toCC(start) ? connection.start : connection.end;
    BlockPos cc1 = connection.end == Utils.toCC(start) ? connection.end : connection.start;
    IImmersiveConnectable iicStart = ApiUtils.toIIC(cc1, player.worldObj);
    IImmersiveConnectable iicEnd = ApiUtils.toIIC(cc0, player.worldObj);
    Vec3d vStart = new Vec3d(cc1);
    Vec3d vEnd = new Vec3d(cc0);
    if (iicStart != null)
        vStart = Utils.addVectors(vStart, iicStart.getConnectionOffset(connection));
    if (iicEnd != null)
        vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
    Vec3d[] steps = getConnectionCatenary(connection, vStart, vEnd);
    double dx = (steps[0].xCoord - vStart.xCoord);
    double dy = (steps[0].yCoord - vStart.yCoord);
    double dz = (steps[0].zCoord - vStart.zCoord);
    //connection.length;
    double d = 1;
    //						Math.sqrt(dx*dx+dz*dz+dy*dy);
    //		Vec3 moveVec = Vec3.createVectorHelper(dx,dy,dz);
    //		Vec3 moveVec = Vec3.createVectorHelper(dx/d,dy/d,dz/d);
    EntitySkylineHook hook = new EntitySkylineHook(player.worldObj, vStart.xCoord, vStart.yCoord, vStart.zCoord, connection, cc0, steps);
    float speed = 1;
    if (player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
        speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
    Vec3d moveVec = getSubMovementVector(vStart, steps[0], speed);
    //*speed;
    hook.motionX = moveVec.xCoord;
    //*speed;
    hook.motionY = moveVec.yCoord;
    //*speed;
    hook.motionZ = moveVec.zCoord;
    if (!player.worldObj.isRemote)
        player.worldObj.spawnEntityInWorld(hook);
    ItemSkyhook.existingHooks.put(player.getName(), hook);
    player.startRiding(hook);
    return hook;
}
Also used : EntitySkylineHook(blusunrize.immersiveengineering.common.entities.EntitySkylineHook) ItemSkyhook(blusunrize.immersiveengineering.common.items.ItemSkyhook) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 78 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class Utils method canBlocksSeeOther.

public static boolean canBlocksSeeOther(World world, BlockPos cc0, BlockPos cc1, Vec3d pos0, Vec3d pos1) {
    HashSet<BlockPos> inter = rayTrace(pos0, pos1, world);
    Iterator<BlockPos> it = inter.iterator();
    while (it.hasNext()) {
        BlockPos cc = it.next();
        if (!cc.equals(cc0) && !cc.equals(cc1))
            return false;
    }
    return true;
}
Also used : DirectionalBlockPos(blusunrize.immersiveengineering.api.DirectionalBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 79 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class Utils method ray.

private static void ray(double dif, Vec3d mov, Vec3d start, double lengthAdd, HashSet<BlockPos> ret, World world, HashSet<BlockPos> checked, Block tmp) {
    //Do NOT set this to true unless for debugging. Causes blocks to be placed along the traced ray
    boolean place = false;
    double standartOff = .0625;
    for (int i = 0; i < dif; i++) {
        Vec3d pos = addVectors(start, scalarProd(mov, i + lengthAdd + standartOff));
        Vec3d posNext = addVectors(start, scalarProd(mov, i + 1 + lengthAdd + standartOff));
        Vec3d posPrev = addVectors(start, scalarProd(mov, i + lengthAdd - standartOff));
        Vec3d posVeryPrev = addVectors(start, scalarProd(mov, i - 1 + lengthAdd - standartOff));
        BlockPos blockPos = new BlockPos((int) Math.floor(pos.xCoord), (int) Math.floor(pos.yCoord), (int) Math.floor(pos.zCoord));
        Block b;
        IBlockState state;
        if (!checked.contains(blockPos) && i + lengthAdd + standartOff < dif) {
            state = world.getBlockState(blockPos);
            b = state.getBlock();
            if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, pos, posNext) != null)
                ret.add(blockPos);
            //				if (place)
            //					world.setBlockState(blockPos, tmp);
            checked.add(blockPos);
        }
        blockPos = new BlockPos((int) Math.floor(posPrev.xCoord), (int) Math.floor(posPrev.yCoord), (int) Math.floor(posPrev.zCoord));
        if (!checked.contains(blockPos) && i + lengthAdd - standartOff < dif) {
            state = world.getBlockState(blockPos);
            b = state.getBlock();
            if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, posVeryPrev, posPrev) != null)
                ret.add(blockPos);
            //				if (place)
            //					world.setBlock(blockPos.posX, blockPos.posY, blockPos.posZ, tmp);
            checked.add(blockPos);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) DirectionalBlockPos(blusunrize.immersiveengineering.api.DirectionalBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 80 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class ItemSkyhook method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    TileEntity connector = null;
    double lastDist = 0;
    Connection line = null;
    double py = player.posY + player.getEyeHeight();
    for (int xx = -2; xx <= 2; xx++) for (int zz = -2; zz <= 2; zz++) for (int yy = 0; yy <= 3; yy++) {
        TileEntity tile = world.getTileEntity(new BlockPos(player.posX + xx, py + yy, player.posZ + zz));
        if (tile != null) {
            Connection con = SkylineHelper.getTargetConnection(world, tile.getPos(), player, null);
            if (con != null) {
                double d = tile.getDistanceSq(player.posX, py, player.posZ);
                if (connector == null || d < lastDist) {
                    connector = tile;
                    lastDist = d;
                    line = con;
                }
            }
        }
    }
    if (line != null && connector != null) {
        SkylineHelper.spawnHook(player, connector, line);
        player.setActiveHand(hand);
        return new ActionResult(EnumActionResult.SUCCESS, stack);
    }
    return new ActionResult(EnumActionResult.PASS, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)864 IBlockState (net.minecraft.block.state.IBlockState)220 TileEntity (net.minecraft.tileentity.TileEntity)135 Block (net.minecraft.block.Block)103 EnumFacing (net.minecraft.util.EnumFacing)95 ItemStack (net.minecraft.item.ItemStack)81 World (net.minecraft.world.World)77 EntityPlayer (net.minecraft.entity.player.EntityPlayer)54 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)46 Vec3d (net.minecraft.util.math.Vec3d)44 NotNull (org.jetbrains.annotations.NotNull)44 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)38 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)31 Entity (net.minecraft.entity.Entity)30 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)29 Nullable (org.jetbrains.annotations.Nullable)26 ArrayList (java.util.ArrayList)23 EntityLivingBase (net.minecraft.entity.EntityLivingBase)23 WorldServer (net.minecraft.world.WorldServer)23 TextComponentString (net.minecraft.util.text.TextComponentString)22