private void GenerateHeightMap(IChunk chunk) { Coordinates3D coords; var map = new byte[Chunk.Width, Chunk.Depth]; for (byte x = 0; x < Chunk.Width; x++) { for (byte z = 0; z < Chunk.Depth; z++) { for (byte y = (byte)(chunk.GetHeight(x, z) + 2); y > 0; y--) { if (y >= Chunk.Height) { continue; } coords.X = x; coords.Y = y - 1; coords.Z = z; var id = chunk.GetBlockID(coords); if (id == 0) { continue; } var provider = BlockRepository.GetBlockProvider(id); if (provider.LightOpacity != 0) { map[x, z] = y; break; } } } } HeightMaps[chunk.Coordinates] = map; }
void ScheduleUpdatesForChunk(IWorld world, IChunk chunk) { int _x = chunk.Coordinates.X * Chunk.Width; int _z = chunk.Coordinates.Z * Chunk.Depth; Coordinates3D coords, _coords; for (byte x = 0; x < Chunk.Width; x++) { for (byte z = 0; z < Chunk.Depth; z++) { for (int y = 0; y < chunk.GetHeight(x, z); y++) { _coords.X = x; _coords.Y = y; _coords.Z = z; var id = chunk.GetBlockID(_coords); if (id == 0) { continue; } coords.X = _x + x; coords.Y = y; coords.Z = _z + z; var provider = BlockRepository.GetBlockProvider(id); provider.BlockLoadedFromChunk(coords, this, world); } } } }
private void GenerateHeightMap(IChunk chunk) { Coordinates3D coords; var map = new byte[Chunk.Width, Chunk.Depth]; for (byte x = 0; x < Chunk.Width; x++) { for (byte z = 0; z < Chunk.Depth; z++) { for (byte y = (byte)(chunk.GetHeight(x, z) + 2); y > 0; y--) { if (y >= Chunk.Height) continue; coords.X = x; coords.Y = y - 1; coords.Z = z; var id = chunk.GetBlockID(coords); if (id == 0) continue; var provider = BlockRepository.GetBlockProvider(id); if (provider.LightOpacity != 0) { map[x, z] = y; break; } } } } HeightMaps[chunk.Coordinates] = map; }
public void TrySpread(Coordinates3D coords, IWorld world, IMultiplayerServer server) { if (!world.IsValidPosition(coords + Coordinates3D.Up)) { return; } var sky = world.GetSkyLight(coords + Coordinates3D.Up); var block = world.GetBlockLight(coords + Coordinates3D.Up); if (sky < 9 && block < 9) { return; } for (int i = 0, j = MathHelper.Random.Next(GrowthCandidates.Length); i < GrowthCandidates.Length; i++, j++) { var candidate = GrowthCandidates[j % GrowthCandidates.Length] + coords; if (!world.IsValidPosition(candidate) || !world.IsValidPosition(candidate + Coordinates3D.Up)) { continue; } var id = world.GetBlockID(candidate); if (id == DirtBlock.BlockID) { var _sky = world.GetSkyLight(candidate + Coordinates3D.Up); var _block = world.GetBlockLight(candidate + Coordinates3D.Up); if (_sky < 4 && _block < 4) { continue; } IChunk chunk = world.FindChunk(candidate); bool grow = true; for (int y = candidate.Y; y < chunk.GetHeight((byte)candidate.X, (byte)candidate.Z); y++) { var b = world.GetBlockID(new Coordinates3D(candidate.X, y, candidate.Z)); var p = world.BlockRepository.GetBlockProvider(b); if (p.LightOpacity >= 2) { grow = false; break; } } world.SetBlockID(candidate, GrassBlock.BlockID); server.Scheduler.ScheduleEvent(chunk, DateTime.UtcNow.AddSeconds(MathHelper.Random.Next(MinGrowthTime, MaxGrowthTime)), s => TrySpread(candidate, world, server)); break; } } }
void ScheduleUpdatesForChunk(IWorld world, IChunk chunk) { int _x = chunk.Coordinates.X * Chunk.Width; int _z = chunk.Coordinates.Z * Chunk.Depth; for (byte x = 0; x < Chunk.Width; x++) { for (byte z = 0; z < Chunk.Depth; z++) { for (int y = 0; y < chunk.GetHeight(x, z); y++) { var coords = new Coordinates3D(_x + x, y, _z + z); var id = world.GetBlockID(coords); if (id == 0) { continue; } var provider = BlockRepository.GetBlockProvider(id); provider.BlockLoadedFromChunk(coords, this, world); } } } }
void ScheduleUpdatesForChunk(IWorld world, IChunk chunk) { chunk.UpdateHeightMap(); int _x = chunk.Coordinates.X * Chunk.Width; int _z = chunk.Coordinates.Z * Chunk.Depth; Coordinates3D coords, _coords; for (byte x = 0; x < Chunk.Width; x++) { for (byte z = 0; z < Chunk.Depth; z++) { for (int y = 0; y < chunk.GetHeight(x, z); y++) { _coords.X = x; _coords.Y = y; _coords.Z = z; var id = chunk.GetBlockID(_coords); if (id == 0) continue; coords.X = _x + x; coords.Y = y; coords.Z = _z + z; var provider = BlockRepository.GetBlockProvider(id); provider.BlockLoadedFromChunk(coords, this, world); } } } }
public int GetHeight(int x, int z) { IChunk chunk = _chunkCache.GetChunk(new ChunkCoord(x >> 4, z >> 4)); return(chunk.GetHeight(x & 15, z & 15)); }
void ScheduleUpdatesForChunk(IWorld world, IChunk chunk) { int _x = chunk.Coordinates.X * Chunk.Width; int _z = chunk.Coordinates.Z * Chunk.Depth; for (byte x = 0; x < Chunk.Width; x++) { for (byte z = 0; z < Chunk.Depth; z++) { for (int y = 0; y < chunk.GetHeight(x, z); y++) { var coords = new Coordinates3D(_x + x, y, _z + z); var id = world.GetBlockID(coords); if (id == 0) continue; var provider = BlockRepository.GetBlockProvider(id); provider.BlockLoadedFromChunk(coords, this, world); } } } }