public static void RenderDataFromRegion(BlockColors bc, RegionMCA mca, byte[][] TopoData, Color[] Blocks = null) { byte[] hMap = TopoData[0]; byte[] hWMap = TopoData[1]; Voxel Chunk; RegionMasterPaletteWithBlocks RegionBlocks = new RegionMasterPaletteWithBlocks(); if (mca.IsLoaded) { for (int zz = 0; zz < 32; zz++) { for (int xx = 0; xx < 32; xx++) { var ridx = (zz * 16 * 512) + (xx * 16); mca.SetOffset(65, xx * 16, zz * 16); mca.RefreshChunk(); Chunk = mca.Chunk; NbtChunk c = null; c = mca.NbtChunk(mca); int[,] cGround = new int[16, 16]; if (c.IsLoaded && c.sections != null) { var sc = c.sections.tagvalue.Count; var bb = new List <BitChunker>(); var bp = new List <List <string> >(); if (sc > 0) { foreach (var sect in c.sections.tagvalue) { var sdata = ((Nbt.NbtLongArray)sect["BlockStates"]).tagvalue; var yidx = ((Nbt.NbtByte)sect["Y"]).tagvalue; if (sdata.Length > 256) { } var pal = ((Nbt.NbtList)sect["Palette"]).tagvalue; var bl = new BitChunker(sdata); bb.Add(bl); var bp_block = new List <string>(); foreach (var p in pal) { bp_block.Add(((Nbt.NbtString)p["Name"]).tagvalue); } bp.Add(bp_block); } } sc--; var cidx = 0; RenderBlocks(); void RenderBlocks() { var blocksleft = 256; for (var iB = sc; iB > 0; iB--) { var bl = bb[iB]; var blp = bp[iB]; for (var iC = 15; iC > 0; iC--) { cidx = iC * 256; var h = (iB * 16) + iC; for (var cz = 0; cz < 16; cz++) { for (var cx = 0; cx < 16; cx++, cidx++) { if (cGround[cx, cz] == 0) { var bidx = bl[cidx]; var midx = ridx + ((cz * 512) + cx); if (bidx < blp.Count) { var block = blp[bidx]; if (block.Contains(":water")) { if (hWMap[midx] == 255) { hWMap[midx] = (byte)h; } } else if (block.Contains(":air")) { hWMap[midx] = 255; hMap[midx] = 0; } else { RegionBlocks.SetBlock(midx, block); cGround[cx, cz] = h; hMap[midx] = (byte)h; if (hWMap[midx] == 0) { hWMap[midx] = 255; } --blocksleft; if (blocksleft == 0) { return; } } } else { //can't do this... why have index not in palette? cGround[cx, cz] = h; hMap[midx] = (byte)h; if (hWMap[midx] == 0) { hWMap[midx] = 255; } --blocksleft; if (blocksleft == 0) { return; } } } } } } } } } else { for (var cz = 0; cz < 16; cz++) { for (var cx = 0; cx < 16; cx++) { var midx = ridx + ((cz * 512) + cx); hWMap[midx] = 255; hMap[midx] = 0; RegionBlocks.SetBlock(midx, "minecraft:void_air"); } } } } } if (Blocks != null) { Color[] Pal = bc.GetPalette(RegionBlocks.MasterPalette); var idx_max = 512 * 512; for (var idx = 0; idx < idx_max; idx++) { Blocks[idx] = Pal[RegionBlocks.RegionBlockStates[idx]]; } } } }
public static BlockColors Create() { var bc = new BlockColors(); bc.InitBlockColors(); return(bc); }