public ClientChunk CreateClientChunk(ChunkOctree<ClientChunk> octree, long x, long y, long z)
        {
            var existing = octree.Get(x, y, z);

            if (existing != null)
            {
                return existing;
            }

            var @new = new ClientChunk(x, y, z);
            octree.Set(@new);

            return @new;
        }
        public void RecalculateDesiredChunks(
            PlayerServerEntity playerEntity,
            ChunkOctree<ServerChunk> serverOctree,
            Action<long, long, long> chunkRequired)
        {
            var chunks = new List<ChunkPos>();

            var current = serverOctree.Get((long)playerEntity.X, (long)playerEntity.Y, (long)playerEntity.Z);

            foreach (var l in this.m_PredeterminedChunkPositions.GetAbsolutePositions(new Vector3(
                (float)current.X,
                (float)current.Y,
                (float)current.Z)))
            {
                chunks.Add(
                    new ChunkPos
                    {
                        X = (long)l.X,
                        Y = (long)l.Y,
                        Z = (long)l.Z
                    });
            }

            // Check if each of the chunks is already in the octree.
            foreach (var pos in chunks.ToArray())
            {
                if (this.m_ClientHasChunkOctree.Get(pos.X, pos.Y, pos.Z) != null)
                {
                    chunks.Remove(pos);
                }
            }

            // Callback for required chunks.
            foreach (var chunk in chunks)
            {
                chunkRequired(chunk.X, chunk.Y, chunk.Z);
            }
        }
        private ClientChunk GetChunkOrGenerate(ChunkOctree<ClientChunk> octree, ILevel level, long x, long y, long z)
        {
            using (this.m_Profiler.Measure("tychaia-chunk_test"))
            {
                var existing = octree.Get(x, y, z);
                if (existing != null)
                    return existing;
            }

            using (this.m_Profiler.Measure("tychaia-chunk_create"))
            {
                return this.m_ClientChunkFactory.CreateClientChunk(
                    octree,
                    x,
                    y,
                    z);
            }
        }