public Block GetConvertedBlock(BlockCoordinates blockCoordinates) { ChunkColumn chunk = GetChunk(blockCoordinates); if (chunk == null) { return new Air() { Coordinates = blockCoordinates, SkyLight = 15 } } ; byte bid = chunk.GetBlock(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte metadata = chunk.GetMetadata(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte blockLight = chunk.GetBlocklight(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte skyLight = chunk.GetSkylight(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); Block block = PCPEConvert.ConvertBlock(bid, metadata); block.Coordinates = blockCoordinates; block.BlockLight = blockLight; block.SkyLight = skyLight; return(block); }
public byte GetSkyLight(BlockCoordinates blockCoordinates) { ChunkColumn chunk = GetChunk(blockCoordinates); if (chunk == null) { return(15); } return(chunk.GetSkylight(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0x7f, blockCoordinates.Z & 0x0f)); }
public void ShowHeights(ChunkColumn chunk) { if (chunk == null) { return; } for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (byte y = 255; y > 0; y--) { if (chunk.GetSkylight(x, y, z) == 0) { chunk.SetBlock(x, y, z, 41); } } } } }
private BlockColumnMeta GetColumnMeta(ChunkColumn chunk, int x, int z) { var pos = new BlockPosition((chunk.x << 4) + x, (chunk.z << 4) + z); var y = chunk.GetHeight(x, z); //var highestBlock = Level.GetBlock(pos.X, y, pos.Z); var highestBlock = GetHighestBlock(pos.X, pos.Z); if (highestBlock == null) { return(new BlockColumnMeta() { Position = pos, Height = 0, BiomeId = 0, BlockId = 0, LightLevel = 0 }); } //_skyLightCalculations.Calculate(Level, highestBlock); //if (highestBlock.LightLevel > 0) //{ // BlockLightCalculations.Calculate(Level, highestBlock); //} return(new BlockColumnMeta() { Position = pos, Height = (byte)highestBlock.Coordinates.Y, BiomeId = highestBlock.BiomeId, BlockId = highestBlock.Id, LightLevel = chunk.GetSkylight(x, y, z) }); }
private static NbtFile CreateNbtFromChunkColumn(ChunkColumn chunk, int yoffset) { var nbt = new NbtFile(); var levelTag = new NbtCompound("Level"); nbt.RootTag.Add(levelTag); levelTag.Add(new NbtInt("xPos", chunk.X)); levelTag.Add(new NbtInt("zPos", chunk.Z)); levelTag.Add(new NbtByteArray("Biomes", chunk.BiomeId)); var sectionsTag = new NbtList("Sections"); levelTag.Add(sectionsTag); for (var i = 0; i < 8; i++) { var sectionTag = new NbtCompound(); sectionsTag.Add(sectionTag); sectionTag.Add(new NbtByte("Y", (byte)i)); var sy = i * 16; var blocks = new byte[4096]; var data = new byte[2048]; var blockLight = new byte[2048]; var skyLight = new byte[2048]; for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = 0; y < 16; y++) { var yi = sy + y; if (yi < 0 || yi >= 256) { continue; // ? } var anvilIndex = (y + yoffset) * 16 * 16 + z * 16 + x; var blockId = chunk.GetBlock(x, yi, z); blocks[anvilIndex] = (byte)blockId; SetNibble4(data, anvilIndex, chunk.GetMetadata(x, yi, z)); SetNibble4(blockLight, anvilIndex, chunk.GetBlocklight(x, yi, z)); SetNibble4(skyLight, anvilIndex, chunk.GetSkylight(x, yi, z)); } } } sectionTag.Add(new NbtByteArray("Blocks", blocks)); sectionTag.Add(new NbtByteArray("Data", data)); sectionTag.Add(new NbtByteArray("BlockLight", blockLight)); sectionTag.Add(new NbtByteArray("SkyLight", skyLight)); } levelTag.Add(new NbtList("Entities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileEntities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileTicks", NbtTagType.Compound)); return(nbt); }
private static NbtFile CreateNbtFromChunkColumn(ChunkColumn chunk) { var nbt = new NbtFile(); NbtCompound levelTag = new NbtCompound("Level"); nbt.RootTag.Add(levelTag); levelTag.Add(new NbtInt("xPos", chunk.x)); levelTag.Add(new NbtInt("zPos", chunk.z)); levelTag.Add(new NbtByteArray("Biomes", chunk.biomeId)); NbtList sectionsTag = new NbtList("Sections"); levelTag.Add(sectionsTag); for (int i = 0; i < 8; i++) { NbtCompound sectionTag = new NbtCompound(); sectionsTag.Add(sectionTag); sectionTag.Add(new NbtByte("Y", (byte)i)); int sy = i * 16; byte[] blocks = new byte[4096]; byte[] data = new byte[2048]; byte[] blockLight = new byte[2048]; byte[] skyLight = new byte[2048]; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 16; y++) { int yi = sy + y; if (yi < 0 || yi >= 256) { continue; // ? } int anvilIndex = (y + _waterOffsetY) * 16 * 16 + z * 16 + x; byte blockId = chunk.GetBlock(x, yi, z); // PE to Anvil friendly converstion if (blockId == 5) { blockId = 125; } else if (blockId == 158) { blockId = 126; } else if (blockId == 50) { blockId = 75; } else if (blockId == 50) { blockId = 76; } else if (blockId == 89) { blockId = 123; } else if (blockId == 89) { blockId = 124; } else if (blockId == 73) { blockId = 152; } blocks[anvilIndex] = blockId; SetNibble4(data, anvilIndex, chunk.GetMetadata(x, yi, z)); SetNibble4(blockLight, anvilIndex, chunk.GetBlocklight(x, yi, z)); SetNibble4(skyLight, anvilIndex, chunk.GetSkylight(x, yi, z)); } } } sectionTag.Add(new NbtByteArray("Blocks", blocks)); sectionTag.Add(new NbtByteArray("Data", data)); sectionTag.Add(new NbtByteArray("BlockLight", blockLight)); sectionTag.Add(new NbtByteArray("SkyLight", skyLight)); } levelTag.Add(new NbtList("Entities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileEntities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileTicks", NbtTagType.Compound)); return(nbt); }
private static NbtFile CreateNbtFromChunkColumn(ChunkColumn chunk, int yoffset) { var nbt = new NbtFile(); NbtCompound levelTag = new NbtCompound("Level"); nbt.RootTag.Add(levelTag); levelTag.Add(new NbtInt("xPos", chunk.x)); levelTag.Add(new NbtInt("zPos", chunk.z)); levelTag.Add(new NbtByteArray("Biomes", chunk.biomeId)); NbtList sectionsTag = new NbtList("Sections"); levelTag.Add(sectionsTag); for (int i = 0; i < 8; i++) { NbtCompound sectionTag = new NbtCompound(); sectionsTag.Add(sectionTag); sectionTag.Add(new NbtByte("Y", (byte) i)); int sy = i*16; byte[] blocks = new byte[4096]; byte[] data = new byte[2048]; byte[] blockLight = new byte[2048]; byte[] skyLight = new byte[2048]; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 16; y++) { int yi = sy + y; if (yi < 0 || yi >= 256) continue; // ? int anvilIndex = (y + yoffset)*16*16 + z*16 + x; byte blockId = chunk.GetBlock(x, yi, z); // PE to Anvil friendly converstion if (blockId == 5) blockId = 125; else if (blockId == 158) blockId = 126; else if (blockId == 50) blockId = 75; else if (blockId == 50) blockId = 76; else if (blockId == 89) blockId = 123; else if (blockId == 89) blockId = 124; else if (blockId == 73) blockId = 152; blocks[anvilIndex] = blockId; SetNibble4(data, anvilIndex, chunk.GetMetadata(x, yi, z)); SetNibble4(blockLight, anvilIndex, chunk.GetBlocklight(x, yi, z)); SetNibble4(skyLight, anvilIndex, chunk.GetSkylight(x, yi, z)); } } } sectionTag.Add(new NbtByteArray("Blocks", blocks)); sectionTag.Add(new NbtByteArray("Data", data)); sectionTag.Add(new NbtByteArray("BlockLight", blockLight)); sectionTag.Add(new NbtByteArray("SkyLight", skyLight)); } // TODO: Save entities NbtList entitiesTag = new NbtList("Entities", NbtTagType.Compound); levelTag.Add(entitiesTag); NbtList blockEntitiesTag = new NbtList("TileEntities", NbtTagType.Compound); levelTag.Add(blockEntitiesTag); foreach (NbtCompound blockEntityNbt in chunk.BlockEntities.Values) { NbtCompound nbtClone = (NbtCompound) blockEntityNbt.Clone(); nbtClone.Name = null; blockEntitiesTag.Add(nbtClone); } levelTag.Add(new NbtList("TileTicks", NbtTagType.Compound)); return nbt; }
private static NbtFile CreateNbtFromChunkColumn(ChunkColumn chunk, int yoffset) { var nbt = new NbtFile(); var levelTag = new NbtCompound("Level"); nbt.RootTag.Add(levelTag); levelTag.Add(new NbtInt("xPos", chunk.X)); levelTag.Add(new NbtInt("zPos", chunk.Z)); levelTag.Add(new NbtByteArray("Biomes", chunk.BiomeId)); var sectionsTag = new NbtList("Sections"); levelTag.Add(sectionsTag); for (var i = 0; i < 8; i++) { var sectionTag = new NbtCompound(); sectionsTag.Add(sectionTag); sectionTag.Add(new NbtByte("Y", (byte) i)); var sy = i*16; var blocks = new byte[4096]; var data = new byte[2048]; var blockLight = new byte[2048]; var skyLight = new byte[2048]; for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = 0; y < 16; y++) { var yi = sy + y; if (yi < 0 || yi >= 256) continue; // ? var anvilIndex = (y + yoffset)*16*16 + z*16 + x; var blockId = chunk.GetBlock(x, yi, z); blocks[anvilIndex] = (byte) blockId; SetNibble4(data, anvilIndex, chunk.GetMetadata(x, yi, z)); SetNibble4(blockLight, anvilIndex, chunk.GetBlocklight(x, yi, z)); SetNibble4(skyLight, anvilIndex, chunk.GetSkylight(x, yi, z)); } } } sectionTag.Add(new NbtByteArray("Blocks", blocks)); sectionTag.Add(new NbtByteArray("Data", data)); sectionTag.Add(new NbtByteArray("BlockLight", blockLight)); sectionTag.Add(new NbtByteArray("SkyLight", skyLight)); } levelTag.Add(new NbtList("Entities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileEntities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileTicks", NbtTagType.Compound)); return nbt; }
private void Spread(ConcurrentQueue <LightingItem> queue, ChunkColumn chunk, BlockFace face, int x, int y, int z, int lightLevel) { if (lightLevel <= 0) { return; } var chunkCoordinates = new ChunkCoordinates(x >> 4, z >> 4); if (chunkCoordinates.X != chunk.X || chunkCoordinates.Z != chunk.Z) { Enqueue(face, x, y, z, lightLevel); return; } //if (!ChunkManager.TryGetChunk(chunkCoordinates, out var chunk)) //{ // Enqueue(face, x, y, z, lightLevel); // return; //} //var self = World.GetBlockState(x, y, z).Block; var self = chunk.GetBlockState(x & 0xf, y & 0xff, z & 0xf).Block; if (self.BlockMaterial.BlocksLight) { return; } lightLevel -= self.LightOpacity; if (lightLevel < 0) { lightLevel = 0; } if (lightLevel < chunk.GetSkylight(x & 0xf, y & 0xff, z & 0xf)) { return; } chunk.SetSkyLight(x & 0xf, y & 0xff, z & 0xf, (byte)lightLevel); if (lightLevel <= 0) { return; } //lightLevel--; if (face != BlockFace.East) { Enqueue(queue, BlockFace.West, x - 1, y, z, lightLevel); } if (face != BlockFace.West) { Enqueue(queue, BlockFace.East, x + 1, y, z, lightLevel); } if (face != BlockFace.South) { Enqueue(queue, BlockFace.North, x, y, z - 1, lightLevel); } if (face != BlockFace.North) { Enqueue(queue, BlockFace.South, x, y, z + 1, lightLevel); } if (face != BlockFace.Up && y > 0) { Enqueue(queue, BlockFace.Down, x, y - 1, z, lightLevel); } if (face != BlockFace.Down && y < 256) { Enqueue(queue, BlockFace.Up, x, y + 1, z, lightLevel); } }