Exemplo n.º 1
0
        private CachedChunk LoadChunk(Vector3i position)
        {
            var chunk = WorldSerializer.LoadChunk(this, position);

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

            //TODO: implement terrain gen
            chunk = new CachedChunk(this, position);
            var worldMin = position * Chunk.Size;
            var worldMax = worldMin + new Vector3i(Chunk.Size - 1);

            for (var x = 0; x < Chunk.Size; x++)
            {
                for (var z = 0; z < Chunk.Size; z++)
                {
                    var height = OpenSimplexNoise.Generate((worldMin.X + x) * 0.06f, (worldMin.Z + z) * 0.06f) * 5;
                    height += OpenSimplexNoise.Generate((worldMin.X + x) * 0.1f, (worldMin.Z + z) * 0.1f) * 2;
                    //height += OpenSimplexNoise.Generate((worldMin.X + x) * 0.005f, (worldMin.Z + z) * 0.005f) * 10;
                    height = 0;


                    for (var y = 0; y < Chunk.Size; y++)
                    {
                        if (worldMin.Y + y <= height)
                        {
                            chunk.SetBlock(x, y, z, (worldMin.Y + y == (int)height) ? GameRegistry.GetBlock("Vanilla:Grass") : GameRegistry.GetBlock("Vanilla:Dirt"));
                        }
                    }

                    /*
                     * for (var y = 0; y < Chunk.Size; y++)
                     * {
                     * var density = (OpenSimplexNoise.Generate((worldMin.X + x) * 0.045f, (worldMin.Y + y) * 0.075f, (worldMin.Z + z) * 0.045f) +1)*30;
                     * if (density > 13+15)
                     * {
                     *  chunk.SetBlock(x,y,z, GameRegistry.GetBlock("Vanilla:Stone"));
                     *      if(chunk.GetBlock(x,y-1,z).RegistryKey == "Vanilla:Grass")
                     *          chunk.SetBlock(x,y-1,z, GameRegistry.GetBlock("Vanilla:Dirt"));
                     * }
                     * else if (density > 10+15)
                     * {
                     *  chunk.SetBlock(x, y, z,
                     *      chunk.GetBlock(x, y + 1, z).IsOpaqueFullBlock(this, new Vector3i(x, y + 1, z))
                     *          ? GameRegistry.GetBlock("Vanilla:Dirt")
                     *          : GameRegistry.GetBlock("Vanilla:Grass"));
                     *
                     *      if (chunk.GetBlock(x, y - 1, z).RegistryKey == "Vanilla:Grass")
                     *          chunk.SetBlock(x, y - 1, z, GameRegistry.GetBlock("Vanilla:Dirt"));
                     *  }
                     * }
                     */
                }
            }


            return(chunk);
        }
Exemplo n.º 2
0
 internal Chunk(CachedChunk cachedChunk) : this(cachedChunk.World, cachedChunk.Position)
 {
     _blockIds    = cachedChunk.BlockIds;
     _lightLevels = cachedChunk.LightLevels;
     _blockDatas  = cachedChunk.BlockDatas;
     _min         = cachedChunk.Min;
     _max         = cachedChunk.Max;
 }