Пример #1
0
        public Block GetBlock(int3 position)
        {
            int3 chunkPos = Helpers.ContainingChunkPosition(position);

            if (chunks.TryGetValue(chunkPos, out Chunk chunk))
            {
                int xx = Helpers.Mod(position.x, Chunk.CHUNK_SIZE);
                int yy = Helpers.Mod(position.y, Chunk.CHUNK_SIZE);
                int zz = Helpers.Mod(position.z, Chunk.CHUNK_SIZE);

                return(chunk.GetBlock(xx, yy, zz));
            }

            return(BlockProvider.GetBlock("air"));
        }
Пример #2
0
        /// <summary>
        /// Gets a block from the world.
        /// </summary>
        /// <param name="position">The world position.</param>
        /// <param name="world">The world you want to get the block from. If null, the current active world will be used.</param>
        /// <returns>The block at the given position.</returns>
        public static Block GetBlock(int3 position, VoxelWorld world = null)
        {
            if (world == null)
            {
                world = VoxelWorld.Main;

                if (world == null)
                {
                    Debug.LogError("There's no world to get a block from.");
                    return(BlockProvider.GetBlock(BlockProvider.AIR_TYPE));
                }
            }

            return(world.GetBlock(position));
        }
Пример #3
0
        internal void DecompressAndApply(NativeList <int2> list, Dictionary <int, string> palette)
        {
            int index = 0;

            for (int i = 0; i < list.Length; i++)
            {
                if (!BlockProvider.TryGetBlock(palette[list[i].x], out Block block))
                {
#if DEBUG
                    UnityEngine.Debug.LogWarning("Couldn't find block with ID '" + palette[list[i].x] + "' when decompressing. Replacing it with air.");
#endif
                    block = BlockProvider.GetBlock(BlockProvider.AIR_TYPE_ID);
                }

                for (int j = 0; j < list[i].y; j++)
                {
                    blocks[index] = block.id;
                    index++;
                }
            }

            list.Dispose();
        }
Пример #4
0
 public Block Get(int index)
 {
     return(BlockProvider.GetBlock(blocks[index]));
 }
Пример #5
0
 public Block Get(int x, int y, int z)
 {
     return(BlockProvider.GetBlock(blocks[Helpers.GetIndex1DFrom3D(x, y, z, Chunk.CHUNK_SIZE)]));
 }