public static bool NeighboursBlock(IChunk chunk, Coordinates3D location, byte block, byte meta = 0x0) { var surrounding = new[] { location + Coordinates3D.Left, location + Coordinates3D.Right, location + Coordinates3D.Forwards, location + Coordinates3D.Backwards, }; for (int i = 0; i < surrounding.Length; i++) { var toCheck = surrounding[i]; if (toCheck.X < 0 || toCheck.X >= Chunk.Width || toCheck.Z < 0 || toCheck.Z >= Chunk.Depth || toCheck.Y < 0 || toCheck.Y >= Chunk.Height) { return(false); } if (chunk.GetBlockID(toCheck).Equals(block)) { if (meta != 0x0 && chunk.GetMetadata(toCheck) != meta) { return(false); } return(true); } } return(false); }
internal void LoadChunk(IChunk chunk) { QueuePacket(new ChunkPreamblePacket(chunk.Coordinates.X, chunk.Coordinates.Z)); QueuePacket(CreatePacket(chunk)); Server.Scheduler.ScheduleEvent("client.finalize-chunks", this, TimeSpan.Zero, server => { return; LoadedChunks.Add(chunk.Coordinates); foreach (var kvp in chunk.TileEntities) { var coords = kvp.Key; var descriptor = new BlockDescriptor { Coordinates = coords + new Coordinates3D(chunk.X, 0, chunk.Z), Metadata = chunk.GetMetadata(coords), ID = chunk.GetBlockID(coords), BlockLight = chunk.GetBlockLight(coords), SkyLight = chunk.GetSkyLight(coords) }; var provider = Server.BlockRepository.GetBlockProvider(descriptor.ID); provider.TileEntityLoadedForClient(descriptor, World, kvp.Value, this); } }); }
private BlockDescriptor GetBlockDataFromChunk(Coordinates3D adjustedCoordinates, IChunk chunk, Coordinates3D coordinates) { return(new BlockDescriptor { ID = chunk.GetBlockID(adjustedCoordinates), Metadata = chunk.GetMetadata(adjustedCoordinates), BlockLight = chunk.GetBlockLight(adjustedCoordinates), SkyLight = chunk.GetSkyLight(adjustedCoordinates), Coordinates = coordinates }); }
public static bool NeighboursBlock(IChunk chunk, Coordinates3D location, byte block, byte meta = 0x0) { var surrounding = new[] { location + Coordinates3D.Left, location + Coordinates3D.Right, location + Coordinates3D.Forwards, location + Coordinates3D.Backwards, }; for (int i = 0; i < surrounding.Length; i++) { var toCheck = surrounding[i]; if (toCheck.X < 0 || toCheck.X >= Chunk.Width || toCheck.Z < 0 || toCheck.Z >= Chunk.Depth || toCheck.Y < 0 || toCheck.Y >= Chunk.Height) return false; if (chunk.GetBlockID(toCheck).Equals(block)) { if (meta != 0x0 && chunk.GetMetadata(toCheck) != meta) return false; return true; } } return false; }
public byte GetMetadata(Coordinates3D coordinates) { return(Chunk.GetMetadata(coordinates)); }
private async Task ApplyChunkAsync(IChunk chunk, Point index) { // TODO: It would be better to directly replace the chunk via ChunkLoader for (var y = 0; y < Chunk.Size; y++) { for (var x = 0; x < Chunk.Size; x++) { var position = index * Chunk.Size + new Point(x, y); await Map.SetAsync(position, chunk[x, y]); await Map.SetMetadataAsync(position, chunk.GetMetadata(new Point(x, y))); } } }
private BlockDescriptor GetBlockDataFromChunk(Coordinates3D adjustedCoordinates, IChunk chunk, Coordinates3D coordinates) { return new BlockDescriptor { ID = chunk.GetBlockID(adjustedCoordinates), Metadata = chunk.GetMetadata(adjustedCoordinates), BlockLight = chunk.GetBlockLight(adjustedCoordinates), SkyLight = chunk.GetSkyLight(adjustedCoordinates), Coordinates = coordinates }; }