public Chunk(Client c, int x, int z, int pbitmap, boolean lighting, boolean groundup) {
        // Create chunk sections.
        this.c = c;
        this.groundup = groundup;
        this.lighting = lighting;
        this.pbitmap = pbitmap;
        this.x = x;
        this.z = z;
        parts = new ArrayList<Part>();

        blocknum = 0;
        nsection = 0;
        ablocks = 0;
        //System.out.println(Integer.toBinaryString(pbitmap));
        for (int i = 0; i < 16; i++) {
            //System.out.println("Bit map = " + (pbitmap & (1 << i)));
            if ((pbitmap & (1 << i)) != 0) {
                nsection++; // "parts of the chunk"
                parts.add(new Part((byte)i, c));
                //System.out.println("Added new part: " + i);
            }
        }

        for (int i = 0; i < 16; i++) {
            if ((pbitmap & (1 << i)) == 1) {
                ablocks++;
            }
        }
        //size of the chunk
        chunksize = nsection * (4096 * (5 + (lighting?1:0)) / 2) + (groundup?256:0);
        // Number of sections * blocks per section = blocks in this "Chunk"
        blocknum = nsection * 4096;
    }