Example #1
0
        /**
         * Get the mesh for a single block and add it to the given mesh data object.
         **/
        public virtual MeshData GetBlockMesh(Chunk chunk, int x, int y, int z, MeshData meshData)
        {
            if(!Register.GetBlockById(chunk.GetBlock(x, y + 1, z)).IsSolid(Direction.UP))
            {
            meshData = MeshData.CreateFaceUp(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x, y - 1, z)).IsSolid(Direction.DOWN))
            {
            meshData = MeshData.CreateFaceDown(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x, y, z + 1)).IsSolid(Direction.NORTH))
            {
            meshData = MeshData.CreateFaceNorth(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x, y, z - 1)).IsSolid(Direction.SOUTH))
            {
            meshData = MeshData.CreateFaceSouth(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x + 1, y, z)).IsSolid(Direction.EAST))
            {
            meshData = MeshData.CreateFaceEast(chunk, x, y, z, this, meshData, 0.5f);
            }

            if(!Register.GetBlockById(chunk.GetBlock(x - 1, y, z)).IsSolid(Direction.WEST))
            {
            meshData = MeshData.CreateFaceWest(chunk, x, y, z, this, meshData, 0.5f);
            }

            return meshData;
        }
        /**
         * Get the block at the given coords. Returns BlockAir if null.
         */
        public int GetBlock(int x, int y, int z)
        {
            Chunk chunk = GetChunk(x, y, z);

            if (chunk != null)
            {
                int block = chunk.GetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z);

                return(block);
            }
            else
            {
                return(0);
            }
        }
Example #3
0
 void SetBlock(Chunk chunk, int blockId, WorldPos pos, bool replaceBlocks = false)
 {
     if (Chunk.InRange(pos.x) && Chunk.InRange(pos.y) && Chunk.InRange(pos.z))
     {
     if (replaceBlocks || chunk.GetBlock(pos.x, pos.y, pos.z) == 0)
     {
         chunk.SetBlock(pos.x, pos.y, pos.z, blockId);
     }
     }
 }