示例#1
0
        /// <summary>
        /// Sets a block by given world position.
        /// </summary>
        /// <param name="x">Block's x world position.</param>
        /// <param name="y">Block's y world position.</param>
        /// <param name="z">Block's z world position.</param>
        /// <param name="block">Block to set.</param>
        /// <remarks>This method will not check if given point/block coordinates are in chunk-cache's bounds. If you need a reliable & safe way, use <see cref="SetBlockAt"/> instead.</remarks>
        public static void FastSetBlockAt(int x, int y, int z, Block block)
        {
            // make sure given coordinates are in chunk cache's bounds.
            if (!ChunkCache.IsInBounds(x, y, z))
            {
                return; // if it's out of bounds, just return;
            }
            // wrap x coordinate.
            var wrapX = x % CacheWidthInBlocks;

            if (wrapX < 0)
            {
                wrapX += CacheWidthInBlocks;
            }

            // wrap z coordinate.
            var wrapZ = z % CacheLenghtInBlocks;

            if (wrapZ < 0)
            {
                wrapZ += CacheLenghtInBlocks;
            }

            // calculate the flatten index.
            var flattenIndex = wrapX * XStep + wrapZ * ZStep + y;

            // sett the block
            Blocks[flattenIndex] = block;
        }
示例#2
0
        /// <summary>
        /// Gets a block by given world position.
        /// </summary>
        /// <param name="x">Block's x world position.</param>
        /// <param name="y">Block's y world position.</param>
        /// <param name="z">Block's z world position.</param>
        /// <returns>Copy of <see cref="Block"/></returns>
        public static Block BlockAt(int x, int y, int z)
        {
            // make sure given coordinates are in chunk cache's bounds.
            if (!ChunkCache.IsInBounds(x, y, z))
            {
                return(Block.Empty); // if it's out of bounds, just return an empty block.
            }
            // wrap x coordinate.
            var wrapX = x % CacheWidthInBlocks;

            if (wrapX < 0)
            {
                wrapX += CacheWidthInBlocks;
            }

            // wrap z coordinate.
            var wrapZ = z % CacheLenghtInBlocks;

            if (wrapZ < 0)
            {
                wrapZ += CacheLenghtInBlocks;
            }

            // calculate the flatten index.
            var flattenIndex = wrapX * XStep + wrapZ * ZStep + y;

            // return block copy.
            return(Blocks[flattenIndex]);
        }
示例#3
0
        /// <summary>
        /// Gets a block by given world position.
        /// </summary>
        /// <param name="x">Block's x world position.</param>
        /// <param name="y">Block's y world position.</param>
        /// <param name="z">Block's z world position.</param>
        /// <remarks>As <see cref="Block"/> is a struct, the returned block will be a copy of original one.</remarks>
        public Block BlockAt(int x, int y, int z)
        {
            // make sure given coordinates are in chunk cache's bounds.
            if (!ChunkCache.IsInBounds(x, y, z))
            {
                return(Block.Empty); // if it's out of bounds, just return an empty block.
            }
            var flattenIndex = BlockIndexByWorldPosition(x, y, z);

            // return block copy.
            return(Blocks[flattenIndex]);
        }