public final void refresh() {
        if (chunkCache != null) {
            for (Chunk aChunkCache : chunkCache) {
                aChunkCache.dispose();
            }
        }
        if (listsCount > -1) {
            GL11.glDeleteLists(baseListId, listsCount);
        }
        // So that worlds that are not multiples of 16 do not have invisible chunks.
        int paddedWidth = nextMultipleOf16(level.width);
        int paddedHeight = nextMultipleOf16(level.height);
        int paddedLength = nextMultipleOf16(level.length);

        xChunks = paddedWidth / 16;
        yChunks = paddedHeight / 16;
        zChunks = paddedLength / 16;
        chunkCache = new Chunk[xChunks * yChunks * zChunks];
        loadQueue = new Chunk[xChunks * yChunks * zChunks];

        int offset = 0;
        listsCount = xChunks * yChunks * zChunks * 2;
        baseListId = GL11.glGenLists(listsCount);

        for (int x = 0; x < xChunks; ++x) {
            for (int y = 0; y < yChunks; ++y) {
                for (int z = 0; z < zChunks; ++z) {
                    chunkCache[(z * yChunks + y) * xChunks + x]
                            = new Chunk(level, x * 16, y * 16, z * 16, baseListId + offset);
                    loadQueue[(z * yChunks + y) * xChunks + x]
                            = chunkCache[(z * yChunks + y) * xChunks + x];
                    offset += 2;
                }
            }
        }

        for (Chunk chunk : chunksToUpdate) {
            chunk.loaded = false;
        }

        chunksToUpdate.clear();
        refreshEnvironment();
        queueChunks(0, 0, 0, paddedWidth, paddedHeight, paddedLength);
    }