public Chunk(int x, int y) { blocks = new BlockRaw[16 * 16 * 128]; int size = 16 * 128 * 16; int halfSize = size / 2; byte[] data = new Byte[halfSize]; metadata = new NibbleSlice(data, 0, halfSize); this.x = x; this.y = y; this.populated = false; }
public Chunk() { Biomes = new byte[Width * Depth]; HeightMap = new int[Width * Depth]; TileEntities = new Dictionary <Coordinates3D, NbtCompound>(); TerrainPopulated = false; LightPopulated = false; MaxHeight = 0; const int size = Width * Height * Depth; const int halfSize = size / 2; Data = new byte[size + halfSize * 3]; Metadata = new NibbleSlice(Data, size, halfSize); BlockLight = new NibbleSlice(Data, size + halfSize, halfSize); SkyLight = new NibbleSlice(Data, size + halfSize * 2, halfSize); }
public void Deserialize(NbtTag value) { var tag = (NbtCompound)value; X = tag["X"].IntValue; Z = tag["Z"].IntValue; if (tag.Contains("TerrainPopulated")) { TerrainPopulated = tag["TerrainPopulated"].ByteValue > 0; } if (tag.Contains("LightPopulated")) { LightPopulated = tag["LightPopulated"].ByteValue > 0; } const int size = Width * Height * Depth; const int halfSize = size / 2; Data = new byte[(int)(size * 2.5)]; Buffer.BlockCopy(tag["Blocks"].ByteArrayValue, 0, Data, 0, size); Metadata = new NibbleSlice(Data, size, halfSize); BlockLight = new NibbleSlice(Data, size + halfSize, halfSize); SkyLight = new NibbleSlice(Data, size + halfSize * 2, halfSize); Metadata.Deserialize(tag["Data"]); BlockLight.Deserialize(tag["BlockLight"]); SkyLight.Deserialize(tag["SkyLight"]); if (tag.Contains("TileEntities")) { foreach (var entity in tag["TileEntities"] as NbtList) { TileEntities[new Coordinates3D(entity["coordinates"][0].IntValue, entity["coordinates"][1].IntValue, entity["coordinates"][2].IntValue)] = entity["value"][0] as NbtCompound; } } UpdateHeightMap(); // TODO: Entities }