/// <summary>
        /// Copies a chunk from one location to another.
        /// </summary>
        /// <param name="src_cx">The global X-coordinate of the source chunk.</param>
        /// <param name="src_cz">The global Z-coordinate of the source chunk.</param>
        /// <param name="dst_cx">The global X-coordinate of the destination chunk.</param>
        /// <param name="dst_cz">The global Z-coordinate of the destination chunk.</param>
        /// <returns>A <see cref="ChunkRef"/> for the destination chunk.</returns>
        public ChunkRef CopyChunk(int src_cx, int src_cz, int dst_cx, int dst_cz)
        {
            IRegion src_r = GetRegion(src_cx, src_cz);

            if (src_r == null)
            {
                return(null);
            }

            IRegion dst_r = GetRegion(dst_cx, dst_cz);

            if (dst_r == null)
            {
                int rx = dst_cx >> REGION_XLOG;
                int rz = dst_cz >> REGION_ZLOG;
                dst_r = _regionMan.CreateRegion(rx, rz);
            }

            IChunk c = src_r.GetChunk(src_cx & REGION_XMASK, src_cz & REGION_ZMASK);

            c.SetLocation(dst_cx, dst_cz);

            dst_r.SaveChunk(c);

            return(dst_r.GetChunkRef(dst_cx & REGION_XMASK, dst_cz & REGION_ZMASK));
        }
        /// <inheritdoc/>
        public IChunk GetChunk(int cx, int cz)
        {
            IRegion r = GetRegion(cx, cz);

            if (r == null)
            {
                return(null);
            }

            return(r.GetChunk(cx & REGION_XMASK, cz & REGION_ZMASK));
        }
Exemple #3
0
        /// <summary>
        /// Returns a <see cref="IChunk"/> given local coordinates relative to this region.
        /// </summary>
        /// <param name="lcx">The local X-coordinate of a chunk relative to this region.</param>
        /// <param name="lcz">The local Z-coordinate of a chunk relative to this region.</param>
        /// <returns>A <see cref="IChunk"/> object for the given coordinates, or null if the chunk does not exist.</returns>
        /// <remarks>If the local coordinates are out of bounds for this region, the action will be forwarded to the correct region
        /// transparently.  The returned <see cref="IChunk"/> object may either come from cache, or be regenerated from disk.</remarks>
        public IChunk GetChunk(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? null : alt.GetChunk(ForeignX(lcx), ForeignZ(lcz)));
            }

            if (!ChunkExists(lcx, lcz))
            {
                return(null);
            }

            return(CreateChunkVerifiedCore(GetChunkTree(lcx, lcz)));
        }