//input is local position public void GetBlockData(int xInChunk, int worldY, int zInChunk, out byte blockType, out byte blockData) { blockType = 0; blockData = 0; if (worldY < 0 || worldY > 255) { return; } if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15) { NBTHelper.GetBlockData(xInChunk + 16 * x, worldY, zInChunk + 16 * z, out blockType, out blockData); return; } int sectionIndex = Mathf.FloorToInt(worldY / 16f); if (sectionIndex >= 0 && sectionIndex < Sections.Count) { TagNodeCompound section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray blocks = section["Blocks"] as TagNodeByteArray; TagNodeByteArray data = section["Data"] as TagNodeByteArray; int yInSection = worldY - sectionIndex * 16; int blockPos = yInSection * 16 * 16 + zInChunk * 16 + xInChunk; if (blockPos >= 0 && blockPos < 4096) { blockType = blocks.Data[blockPos]; blockData = NBTHelper.GetNibble(data.Data, blockPos); return; } } return; }
private void BuildNbtTree() { int elements3 = XDIM * YDIM * ZDIM; TagNodeByteArray blocks = new TagNodeByteArray(new byte[elements3]); TagNodeByteArray data = new TagNodeByteArray(new byte[elements3 >> 1]); TagNodeByteArray skyLight = new TagNodeByteArray(new byte[elements3 >> 1]); TagNodeByteArray blockLight = new TagNodeByteArray(new byte[elements3 >> 1]); TagNodeByteArray addBlocks = new TagNodeByteArray(new byte[elements3 >> 1]); _blocks = new YZXByteArray(XDIM, YDIM, ZDIM, blocks); _data = new YZXNibbleArray(XDIM, YDIM, ZDIM, data); _skyLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, skyLight); _blockLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, blockLight); _addBlocks = new YZXNibbleArray(XDIM, YDIM, ZDIM, addBlocks); TagNodeCompound tree = new TagNodeCompound(); tree.Add("Y", new TagNodeByte(_y)); tree.Add("Blocks", blocks); tree.Add("Data", data); tree.Add("SkyLight", skyLight); tree.Add("BlockLight", blockLight); tree.Add("AddBlocks", addBlocks); _tree = tree; }
void InitTileEntity() { if (hasInitTileEntity) { return; } foreach (Vector3Int pos in tileEntityList) { if (!tileEntityObjs.ContainsKey(pos)) { int sectionIndex = pos.y / 16; TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray Blocks = Section["Blocks"] as TagNodeByteArray; TagNodeByteArray Data = Section["Data"] as TagNodeByteArray; int yInSection = pos.y % 16; int blockPos = yInSection * 16 * 16 + pos.z * 16 + pos.x; byte rawType = Blocks.Data[blockPos]; NBTBlock generator = NBTGeneratorManager.GetMeshGenerator(rawType); byte blockData = NBTHelper.GetNibble(Data.Data, blockPos); GameObject obj = generator.GetTileEntityGameObject(this, blockData, pos); tileEntityObjs[pos] = obj; } } hasInitTileEntity = true; }
public AnvilSection LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return(null); } _y = ctree["Y"] as TagNodeByte; _blocks = new YZXByteArray(XDIM, YDIM, ZDIM, ctree["Blocks"] as TagNodeByteArray); _data = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["Data"] as TagNodeByteArray); _skyLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["SkyLight"] as TagNodeByteArray); _blockLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["BlockLight"] as TagNodeByteArray); if (!ctree.ContainsKey("AddBlocks")) { ctree["AddBlocks"] = new TagNodeByteArray(new byte[2048]); } _addBlocks = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["AddBlocks"] as TagNodeByteArray); _tree = ctree; return(this); }
public void GetLightsByte(int xInChunk, int yInChunk, int zInChunk, out byte skyLight, out byte blockLight, bool extends = false) { skyLight = 15; blockLight = 0; if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15) { if (extends) { int xOffset = 0; int zOffset = 0; if (xInChunk < 0) { xOffset = -1; } else if (xInChunk > 15) { xOffset = 1; } if (zInChunk < 0) { zOffset = -1; } else if (zInChunk > 15) { zOffset = 1; } NBTChunk chunk = NBTHelper.GetChunk(x + xOffset, z + zOffset); if (chunk != null) { chunk.GetLightsByte(xInChunk - xOffset * 16, yInChunk, zInChunk - zOffset * 16, out skyLight, out blockLight); } } return; } int sectionIndex = yInChunk / 16; if (sectionIndex >= Sections.Count || yInChunk < 0 || yInChunk > 255) { return; } int yInSection = yInChunk % 16; int blockPos = yInSection * 16 * 16 + zInChunk * 16 + xInChunk; TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray SkyLight = Section["SkyLight"] as TagNodeByteArray; skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos); TagNodeByteArray BlockLight = Section["BlockLight"] as TagNodeByteArray; blockLight = NBTHelper.GetNibble(BlockLight.Data, blockPos); }
public static void GetBlockData(int x, int y, int z, ref byte blockType, ref byte blockData) { UnityEngine.Profiling.Profiler.BeginSample("GetBlockData"); int chunkX = Mathf.FloorToInt(x / 16f); int chunkY = Mathf.FloorToInt(y / 16f); int chunkZ = Mathf.FloorToInt(z / 16f); int xInChunk = x - chunkX * 16; int yInChunk = y - chunkY * 16; int zInChunk = z - chunkZ * 16; NBTChunk chunk = GetChunk(chunkX, chunkZ); if (chunk != null) { chunk.GetBlockData(xInChunk, y, zInChunk, ref blockType, ref blockData); } else { UnityEngine.Profiling.Profiler.BeginSample("GetChunkNode"); TagNodeCompound Chunk = GetChunkNode(chunkX, chunkZ); UnityEngine.Profiling.Profiler.EndSample(); if (Chunk != null) { UnityEngine.Profiling.Profiler.BeginSample("GetBlockData new block"); TagNodeCompound Level = Chunk["Level"] as TagNodeCompound; TagNodeList Sections = Level["Sections"] as TagNodeList; if (chunkY < Sections.Count) { TagNodeCompound section = Sections[chunkY] as TagNodeCompound; TagNodeByteArray Blocks = section["Blocks"] as TagNodeByteArray; byte[] blocks = new byte[4096]; Buffer.BlockCopy(Blocks, 0, blocks, 0, 4096); int blockPos = yInChunk * 16 * 16 + zInChunk * 16 + xInChunk; blockType = blocks[blockPos]; TagNodeByteArray Data = section["Data"] as TagNodeByteArray; byte[] data = Data.Data; blockData = GetNibble(data, blockPos); } UnityEngine.Profiling.Profiler.EndSample(); } } UnityEngine.Profiling.Profiler.EndSample(); }
//input is local position public void GetBlockData(int xInChunk, int worldY, int zInChunk, ref byte blockType, ref byte blockData) { if (xInChunk < 0 || xInChunk > 15 || worldY < 0 || worldY > 255 || zInChunk < 0 || zInChunk > 15) { //if (xInChunk < 0) //{ // NBTChunk chunk = NBTHelper.GetChunk(x - 1, z); // chunk.GetBlockData(xInChunk + 16, worldY, zInChunk, ref blockType, ref blockData); //} //else if (xInChunk > 15) //{ // NBTChunk chunk = NBTHelper.GetChunk(x + 1, z); // chunk.GetBlockData(xInChunk - 16, worldY, zInChunk, ref blockType, ref blockData); //} //else if (zInChunk < 0) //{ // NBTChunk chunk = NBTHelper.GetChunk(x, z - 1); // chunk.GetBlockData(xInChunk, worldY, zInChunk + 16, ref blockType, ref blockData); //} //else if (zInChunk > 15) //{ // NBTChunk chunk = NBTHelper.GetChunk(x, z + 1); // chunk.GetBlockData(xInChunk, worldY, zInChunk - 16, ref blockType, ref blockData); //} //NBTHelper.GetBlockData(xInChunk + 16 * x, worldY, zInChunk + 16 * z, ref blockType, ref blockData); return; } int sectionIndex = Mathf.FloorToInt(worldY / 16f); if (sectionIndex >= 0 && sectionIndex < Sections.Count) { TagNodeCompound section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray blocks = section["Blocks"] as TagNodeByteArray; TagNodeByteArray data = section["Data"] as TagNodeByteArray; int yInSection = worldY - sectionIndex * 16; int blockPos = yInSection * 16 * 16 + zInChunk * 16 + xInChunk; if (blockPos >= 0 && blockPos < 4096) { blockType = blocks.Data[blockPos]; blockData = NBTHelper.GetNibble(data.Data, blockPos); return; } } return; }
//input is local position public byte GetBlockByte(int xInChunk, int worldY, int zInChunk) { if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15) { //if (xInChunk < 0) //{ // NBTChunk chunk = NBTHelper.GetChunk(x - 1, z); // return chunk.GetBlockByte(xInChunk + 16, worldY, zInChunk); //} //else if (xInChunk > 15) //{ // NBTChunk chunk = NBTHelper.GetChunk(x + 1, z); // return chunk.GetBlockByte(xInChunk - 16, worldY, zInChunk); //} //else if (zInChunk < 0) //{ // NBTChunk chunk = NBTHelper.GetChunk(x, z - 1); // return chunk.GetBlockByte(xInChunk, worldY, zInChunk + 16); //} //else if (zInChunk > 15) //{ // NBTChunk chunk = NBTHelper.GetChunk(x, z + 1); // return chunk.GetBlockByte(xInChunk, worldY, zInChunk - 16); //} return(NBTHelper.GetBlockByte(xInChunk + 16 * x, worldY, zInChunk + 16 * z)); } int sectionIndex = Mathf.FloorToInt(worldY / 16f); if (sectionIndex >= 0 && sectionIndex < Sections.Count) { TagNodeCompound section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray blocks = section["Blocks"] as TagNodeByteArray; int yInSection = worldY - sectionIndex * 16; int blockPos = yInSection * 16 * 16 + zInChunk * 16 + xInChunk; if (blockPos >= 0 && blockPos < 4096) { return(blocks.Data[blockPos]); } } return(0); }
//input is local position public void SetBlockByte(int xInChunk, int worldY, int zInChunk, byte type) { int sectionIndex = Mathf.FloorToInt(worldY / 16f); if (sectionIndex >= 0 && sectionIndex < Sections.Count) { TagNodeCompound section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray blocks = section["Blocks"] as TagNodeByteArray; int yInSection = worldY - sectionIndex * 16; int blockPos = yInSection * 16 * 16 + zInChunk * 16 + xInChunk; if (blockPos >= 0 && blockPos < 4096) { blocks.Data[blockPos] = type; } } }
public void SetData(int _x, int _z, TagNodeCompound Level) { x = _x; z = _z; globalX = x * 16; globalZ = z * 16; Sections = Level["Sections"] as TagNodeList; TileEntities = Level["TileEntities"] as TagNodeList; Biomes = Level["Biomes"] as TagNodeByteArray; foreach (TagNodeCompound node in TileEntities) { tileEntityDict[new Vector3Int((TagNodeInt)node["x"], (TagNodeInt)node["y"], (TagNodeInt)node["z"])] = node; } gameObject.name = "chunk (" + x + "," + z + ")"; transform.localPosition = new Vector3(x * 16, 0, z * 16); ClearData(); }
private void BuildNBTTree() { int elements2 = XDIM * ZDIM; int elements3 = elements2 * YDIM; TagNodeByteArray blocks = new TagNodeByteArray(new byte[elements3]); TagNodeByteArray data = new TagNodeByteArray(new byte[elements3 >> 1]); TagNodeByteArray blocklight = new TagNodeByteArray(new byte[elements3 >> 1]); TagNodeByteArray skylight = new TagNodeByteArray(new byte[elements3 >> 1]); TagNodeByteArray heightMap = new TagNodeByteArray(new byte[elements2]); _blocks = new XZYByteArray(XDIM, YDIM, ZDIM, blocks); _data = new XZYNibbleArray(XDIM, YDIM, ZDIM, data); _blockLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, blocklight); _skyLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, skylight); _heightMap = new ZXByteArray(XDIM, ZDIM, heightMap); _entities = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _tileTicks = new TagNodeList(TagType.TAG_COMPOUND); TagNodeCompound level = new TagNodeCompound(); level.Add("Blocks", blocks); level.Add("Data", data); level.Add("SkyLight", blocklight); level.Add("BlockLight", skylight); level.Add("HeightMap", heightMap); level.Add("Entities", _entities); level.Add("TileEntities", _tileEntities); level.Add("TileTicks", _tileTicks); level.Add("LastUpdate", new TagNodeLong(Timestamp())); level.Add("xPos", new TagNodeInt(_cx)); level.Add("zPos", new TagNodeInt(_cz)); level.Add("TerrainPopulated", new TagNodeByte()); _tree = new NbtTree(); _tree.Root.Add("Level", level); _blockManager = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities); _entityManager = new EntityCollection(_entities); }
//input is local position public void SetBlockData(int xInChunk, int worldY, int zInChunk, byte type, byte data) { int sectionIndex = Mathf.FloorToInt(worldY / 16f); if (sectionIndex >= 0 && sectionIndex < Sections.Count) { TagNodeCompound section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray Blocks = section["Blocks"] as TagNodeByteArray; TagNodeByteArray Data = section["Data"] as TagNodeByteArray; int yInSection = worldY - sectionIndex * 16; int blockPos = yInSection * 16 * 16 + zInChunk * 16 + xInChunk; if (blockPos >= 0 && blockPos < 4096) { Blocks.Data[blockPos] = type; NBTHelper.SetNibble(Data.Data, blockPos, data); } } }
public static void SetBiomeData(string dest) { NbtWorld world = NbtWorld.Open(dest); IChunkManager cm = world.GetChunkManager(); foreach (ChunkRef chunk in cm) { AnvilChunk anvil_chunk = chunk.GetChunkRef() as AnvilChunk; TagNodeByteArray biomeNode = anvil_chunk.Tree.Root["Level"].ToTagCompound()["Biomes"].ToTagByteArray(); ZXByteArray biomeData = new ZXByteArray(16, 16, biomeNode.Data); for (int x = 0; x <= 15; x++) { for (int y = 0; y <= 15; y++) { biomeData[x, y] = biomes[chunk.X + "." + chunk.Z]; } } chunk.SetChunkRef(anvil_chunk); cm.Save(); } world.Save(); }
/// <summary> /// Builds a Map subtree from the current data. /// </summary> /// <returns>The root node of a Map subtree representing the current data.</returns> public virtual TagNode BuildTree() { TagNodeCompound data = new TagNodeCompound(); data["scale"] = new TagNodeByte(_scale); data["dimension"] = new TagNodeByte(_dimension); data["height"] = new TagNodeShort(_height); data["width"] = new TagNodeShort(_width); data["xCenter"] = new TagNodeInt(_x); data["zCenter"] = new TagNodeInt(_z); data["colors"] = new TagNodeByteArray(_colors); if (_source != null) { data.MergeFrom(_source); } TagNodeCompound tree = new TagNodeCompound(); tree.Add("data", data); return(tree); }
private void BuildNBTTree() { int elements2 = XDIM * ZDIM; _sections = new AnvilSection[16]; TagNodeList sections = new TagNodeList(TagType.TAG_COMPOUND); for (int i = 0; i < _sections.Length; i++) { _sections[i] = new AnvilSection(i); sections.Add(_sections[i].BuildTree()); } FusedDataArray3[] blocksBA = new FusedDataArray3[_sections.Length]; YZXNibbleArray[] dataBA = new YZXNibbleArray[_sections.Length]; YZXNibbleArray[] skyLightBA = new YZXNibbleArray[_sections.Length]; YZXNibbleArray[] blockLightBA = new YZXNibbleArray[_sections.Length]; for (int i = 0; i < _sections.Length; i++) { blocksBA[i] = new FusedDataArray3(_sections[i].AddBlocks, _sections[i].Blocks); dataBA[i] = _sections[i].Data; skyLightBA[i] = _sections[i].SkyLight; blockLightBA[i] = _sections[i].BlockLight; } _blocks = new CompositeDataArray3(blocksBA); _data = new CompositeDataArray3(dataBA); _skyLight = new CompositeDataArray3(skyLightBA); _blockLight = new CompositeDataArray3(blockLightBA); TagNodeIntArray heightMap = new TagNodeIntArray(new int[elements2]); _heightMap = new ZXIntArray(XDIM, ZDIM, heightMap); TagNodeByteArray biomes = new TagNodeByteArray(new byte[elements2]); _biomes = new ZXByteArray(XDIM, ZDIM, biomes); for (int x = 0; x < XDIM; x++) { for (int z = 0; z < ZDIM; z++) { _biomes[x, z] = BiomeType.Default; } } _entities = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _tileTicks = new TagNodeList(TagType.TAG_COMPOUND); TagNodeCompound level = new TagNodeCompound(); level.Add("Sections", sections); level.Add("HeightMap", heightMap); level.Add("Biomes", biomes); level.Add("Entities", _entities); level.Add("TileEntities", _tileEntities); level.Add("TileTicks", _tileTicks); level.Add("LastUpdate", new TagNodeLong(Timestamp())); level.Add("xPos", new TagNodeInt(_cx)); level.Add("zPos", new TagNodeInt(_cz)); level.Add("TerrainPopulated", new TagNodeByte()); _tree = new NbtTree(); _tree.Root.Add("Level", level); _blockManager = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities); _entityManager = new EntityCollection(_entities); }
public byte GetLightByte(int xInChunk, int yInChunk, int zInChunk, bool extends = false) { if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15) { if (extends) { int xOffset = 0; int zOffset = 0; if (xInChunk < 0) { xOffset = -1; } else if (xInChunk > 15) { xOffset = 1; } if (zInChunk < 0) { zOffset = -1; } else if (zInChunk > 15) { zOffset = 1; } NBTChunk chunk = NBTHelper.GetChunk(x + xOffset, z + zOffset); if (chunk != null) { return(chunk.GetLightByte(xInChunk - xOffset * 16, yInChunk, zInChunk - zOffset * 16)); } else { return(15); } } else { return(15); } } int sectionIndex = yInChunk / 16; if (sectionIndex >= Sections.Count || yInChunk < 0 || yInChunk > 255) { return(15); } int yInSection = yInChunk % 16; int blockPos = yInSection * 16 * 16 + zInChunk * 16 + xInChunk; TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray SkyLight = Section["SkyLight"] as TagNodeByteArray; byte skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos); TagNodeByteArray BlockLight = Section["BlockLight"] as TagNodeByteArray; byte blockLight = NBTHelper.GetNibble(BlockLight.Data, blockPos); //Debug.Log("y=" + x + "," + z + ",section=" + sectionIndex); return(skyLight > blockLight ? skyLight : blockLight); }
public TagByteArrayDataNode(TagNodeByteArray tag) : base(tag) { }
public void RefreshMeshData(UpdateFlags updateFlag = UpdateFlags.All) { //Debug.Log("RefreshMeshData,chunk=" + x + ",z=" + z); UnityEngine.Profiling.Profiler.BeginSample("RefreshMeshData"); if (updateFlag.HasFlag(UpdateFlags.Collidable)) { collidable.Clear(); } if (updateFlag.HasFlag(UpdateFlags.NotCollidable)) { notCollidable.Clear(); } if (updateFlag.HasFlag(UpdateFlags.Water)) { water.Clear(); } for (int sectionIndex = 0; sectionIndex < Sections.Count; sectionIndex++) { TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray Blocks = Section["Blocks"] as TagNodeByteArray; TagNodeByteArray Data = Section["Data"] as TagNodeByteArray; for (int yInSection = 0; yInSection < 16; yInSection++) { for (int zInSection = 0; zInSection < 16; zInSection++) { for (int xInSection = 0; xInSection < 16; xInSection++) { int blockPos = yInSection * 16 * 16 + zInSection * 16 + xInSection; byte rawType = Blocks.Data[blockPos]; NBTBlock generator = NBTGeneratorManager.GetMeshGenerator(rawType); int worldY = yInSection + sectionIndex * 16; if (generator != null) { pos.Set(xInSection, worldY, zInSection); byte blockData = NBTHelper.GetNibble(Data.Data, blockPos); try { if (generator.isTileEntity) { tileEntityList.Add(pos); } else { AddCube(generator, blockData, updateFlag); } } catch (System.Exception e) { int worldX = x * 16 + xInSection; int worldZ = z * 16 + zInSection; Vector3Int worldPos = new Vector3Int(worldX, worldY, worldZ); Debug.LogError(generator.GetType() + ",pos=" + worldPos + "\n" + e.ToString()); } } else if (rawType != 0 && rawType != 11) { int worldX = x * 16 + xInSection; int worldZ = z * 16 + zInSection; Vector3Int worldPos = new Vector3Int(worldX, worldY, worldZ); Debug.LogWarning("generator not exist" + ",pos=" + worldPos + ", type=" + rawType); } } } } } UnityEngine.Profiling.Profiler.EndSample(); }
private static void RunOptionsAndReturnExitCode(CliOptions opts) { Console.Clear(); var cgui = new ConsoleGui(); var pbBlocks = new ConsoleGuiProgressBar(0, 0, Console.WindowWidth, 0, 1) { ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGray }; var lBlocksTotal = new ConsoleGuiLabel(0, 1, "Total Blocks : {0}"); var lBlocksRemaining = new ConsoleGuiLabel(0, 2, "Remaining Blocks: {0}"); var lBlocksFailed = new ConsoleGuiLabel(0, 3, "Failed Blocks : {0}"); var lStatus = new ConsoleGuiLabel(0, 4, "Status : {0}"); cgui.Add(pbBlocks); cgui.Add(lBlocksTotal); cgui.Add(lBlocksRemaining); cgui.Add(lBlocksFailed); cgui.Add(lStatus); var failed = new List <int>(); var inputMap = NbtMap.Load(opts.InputMap); var outputMap = NbtMap.Load(opts.OutputMap); var inputSchematic = new NBTFile(opts.InputSchematic); var tag = new NbtTree(inputSchematic.GetDataInputStream()).Root; var bLower = tag["Blocks"].ToTagByteArray().Data; var addBlocks = new byte[(bLower.Length >> 1) + 1]; if (tag.ContainsKey("AddBlocks")) { addBlocks = tag["AddBlocks"].ToTagByteArray().Data; } lStatus.Value = "Processing..."; for (var index = 0; index < bLower.Length; index++) { short oldId; if ((index & 1) == 1) { oldId = (short)(((addBlocks[index >> 1] & 0x0F) << 8) + (bLower[index] & 0xFF)); } else { oldId = (short)(((addBlocks[index >> 1] & 0xF0) << 4) + (bLower[index] & 0xFF)); } if (!TranslateId(oldId, inputMap, outputMap, out var newId)) { failed.Add(oldId); } bLower[index] = (byte)(newId & 0xFF); addBlocks[index >> 1] = (byte)(((index & 1) == 1) ? addBlocks[index >> 1] & 0xF0 | (newId >> 8) & 0xF : addBlocks[index >> 1] & 0xF | ((newId >> 8) & 0xF) << 4); // Gui lBlocksTotal.Value = index + 1; lBlocksRemaining.Value = bLower.Length - index - 1; lBlocksFailed.Value = failed.Count; pbBlocks.Value = (float)index / bLower.Length; if (index % 10000 == 0) { cgui.Render(); } } cgui.Render(); tag["Blocks"] = new TagNodeByteArray(bLower); if (!tag.ContainsKey("AddBlocks")) { tag.Add("AddBlocks", new TagNodeByteArray(addBlocks)); } else { tag["AddBlocks"] = new TagNodeByteArray(addBlocks); } lStatus.Value = "Saving..."; cgui.Render(); var schematicFile = new NBTFile(opts.OutputSchematic); using (var nbtStream = schematicFile.GetDataOutputStream()) { if (nbtStream == null) { return; } var tree = new NbtTree(tag, "Schematic"); tree.WriteTo(nbtStream); } lStatus.Value = "Done. Press Enter."; cgui.Render(); Console.WriteLine(); foreach (var i in failed) { Console.WriteLine($"Failed ID: {i}"); } Console.ReadKey(); }
private void OnGUI() { save = EditorGUILayout.TextField("save", save); pos = EditorGUILayout.Vector3IntField("pos", pos); GUILayout.Label("type=" + type); GUILayout.Label("data=" + blockdata); GUILayout.Label("biome=" + biomeType); GUILayout.Label("skyLight=" + skyLight); if (GUILayout.Button("Update")) { int chunkX = Mathf.FloorToInt(pos.x / 16f); int chunkY = Mathf.FloorToInt(pos.y / 16f); int chunkZ = Mathf.FloorToInt(pos.z / 16f); int xInChunk = pos.x - chunkX * 16; int yInChunk = pos.y - chunkY * 16; int zInChunk = pos.z - chunkZ * 16; TagNodeCompound Chunk = null; int regionX = NBTHelper.GetRegionCoordinate(chunkX); int regionZ = NBTHelper.GetRegionCoordinate(chunkZ); string path = Environment.ExpandEnvironmentVariables("%APPDATA%"); if (!Directory.Exists(path)) { path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } path = Path.Combine(path, ".minecraft"); path = Path.Combine(path, "saves"); path = Path.Combine(path, save); path = Path.Combine(path, "region"); path = Path.Combine(path, "r." + regionX + "." + regionZ + ".mca"); RegionFile region = new RegionFile(path); if (region != null) { int _x = chunkX - regionX * 32; int _z = chunkZ - regionZ * 32; if (region.HasChunk(_x, _z)) { NbtTree _tree = new NbtTree(); using (Stream stream = region.GetChunkDataInputStream(_x, _z)) { _tree.ReadFrom(stream); } Chunk = _tree.Root; } } if (Chunk != null) { TagNodeCompound Level = Chunk["Level"] as TagNodeCompound; TagNodeList Sections = Level["Sections"] as TagNodeList; if (chunkY < Sections.Count) { TagNodeCompound section = Sections[chunkY] as TagNodeCompound; TagNodeByteArray Blocks = section["Blocks"] as TagNodeByteArray; byte[] blocks = new byte[4096]; Buffer.BlockCopy(Blocks, 0, blocks, 0, 4096); int blockPos = yInChunk * 16 * 16 + zInChunk * 16 + xInChunk; type = blocks[blockPos]; TagNodeByteArray Data = section["Data"] as TagNodeByteArray; blockdata = NBTHelper.GetNibble(Data.Data, blockPos); TagNodeByteArray SkyLight = section["SkyLight"] as TagNodeByteArray; skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos); } TagNodeByteArray Biomes = Level["Biomes"] as TagNodeByteArray; biomeType = Biomes[xInChunk * 16 + zInChunk]; } Biome biome; if (biomeType < 6) { biome = gBiomes[biomeType]; } else { biome = gBiomes[0]; Debug.Log("no biome,type=" + biomeType); } float temp = biome.temp - Mathf.Max(pos.y - 64, 0) * 0.0016f; AdjTemp = Mathf.Clamp01(temp); AdjRainfall = Mathf.Clamp01(biome.rainfall) * AdjTemp; Vector2 uv = new Vector2(AdjTemp, AdjRainfall); Texture2D grass = Resources.Load <Texture2D>("GUI/grass"); c = grass.GetPixelBilinear(1 - AdjTemp, AdjRainfall); } GUILayout.Label("temp=" + AdjTemp); GUILayout.Label("rainfall=" + AdjRainfall); EditorGUILayout.ColorField(c, GUILayout.Height(30)); }
public AnvilChunk LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return(null); } _tree = new NbtTree(ctree); TagNodeCompound level = _tree.Root["Level"] as TagNodeCompound; TagNodeList sections = level["Sections"] as TagNodeList; foreach (TagNodeCompound section in sections) { AnvilSection anvilSection = new AnvilSection(section); if (anvilSection.Y < 0 || anvilSection.Y >= _sections.Length) { continue; } _sections[anvilSection.Y] = anvilSection; } FusedDataArray3[] blocksBA = new FusedDataArray3[_sections.Length]; YZXNibbleArray[] dataBA = new YZXNibbleArray[_sections.Length]; YZXNibbleArray[] skyLightBA = new YZXNibbleArray[_sections.Length]; YZXNibbleArray[] blockLightBA = new YZXNibbleArray[_sections.Length]; for (int i = 0; i < _sections.Length; i++) { if (_sections[i] == null) { _sections[i] = new AnvilSection(i); } blocksBA[i] = new FusedDataArray3(_sections[i].AddBlocks, _sections[i].Blocks); dataBA[i] = _sections[i].Data; skyLightBA[i] = _sections[i].SkyLight; blockLightBA[i] = _sections[i].BlockLight; } _blocks = new CompositeDataArray3(blocksBA); _data = new CompositeDataArray3(dataBA); _skyLight = new CompositeDataArray3(skyLightBA); _blockLight = new CompositeDataArray3(blockLightBA); _heightMap = new ZXIntArray(XDIM, ZDIM, level["HeightMap"] as TagNodeIntArray); if (level.ContainsKey("Biomes")) { _biomes = new ZXByteArray(XDIM, ZDIM, level["Biomes"] as TagNodeByteArray); } else { level["Biomes"] = new TagNodeByteArray(new byte[256]); _biomes = new ZXByteArray(XDIM, ZDIM, level["Biomes"] as TagNodeByteArray); for (int x = 0; x < XDIM; x++) { for (int z = 0; z < ZDIM; z++) { _biomes[x, z] = BiomeType.Default; } } } _entities = level["Entities"] as TagNodeList; _tileEntities = level["TileEntities"] as TagNodeList; if (level.ContainsKey("TileTicks")) { _tileTicks = level["TileTicks"] as TagNodeList; } else { _tileTicks = new TagNodeList(TagType.TAG_COMPOUND); } // List-type patch up if (_entities.Count == 0) { level["Entities"] = new TagNodeList(TagType.TAG_COMPOUND); _entities = level["Entities"] as TagNodeList; } if (_tileEntities.Count == 0) { level["TileEntities"] = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = level["TileEntities"] as TagNodeList; } if (_tileTicks.Count == 0) { level["TileTicks"] = new TagNodeList(TagType.TAG_COMPOUND); _tileTicks = level["TileTicks"] as TagNodeList; } _cx = level["xPos"].ToTagInt(); _cz = level["zPos"].ToTagInt(); _blockManager = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities, _tileTicks); _entityManager = new EntityCollection(_entities); _biomeManager = new AnvilBiomeCollection(_biomes); return(this); }
/// <summary> /// Exports the <see cref="Schematic"/> object to a schematic file. /// </summary> /// <param name="path">The path to write out the schematic file to.</param> public void Export(string path) { int xdim = _blockset.XDim; int ydim = _blockset.YDim; int zdim = _blockset.ZDim; byte[] blockData = new byte[xdim * ydim * zdim]; byte[] dataData = new byte[xdim * ydim * zdim]; YZXByteArray schemaBlocks = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, blockData); YZXByteArray schemaData = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, dataData); TagNodeList entities = new TagNodeList(TagType.TAG_COMPOUND); TagNodeList tileEntities = new TagNodeList(TagType.TAG_COMPOUND); for (int x = 0; x < xdim; x++) { for (int z = 0; z < zdim; z++) { for (int y = 0; y < ydim; y++) { AlphaBlock block = _blockset.GetBlock(x, y, z); schemaBlocks[x, y, z] = (byte)block.ID; schemaData[x, y, z] = (byte)block.Data; TileEntity te = block.GetTileEntity(); if (te != null) { te.X = x; te.Y = y; te.Z = z; tileEntities.Add(te.BuildTree()); } } } } foreach (EntityTyped e in _entityset) { entities.Add(e.BuildTree()); } TagNodeCompound schematic = new TagNodeCompound(); schematic["Width"] = new TagNodeShort((short)xdim); schematic["Length"] = new TagNodeShort((short)zdim); schematic["Height"] = new TagNodeShort((short)ydim); schematic["Entities"] = entities; schematic["TileEntities"] = tileEntities; schematic["Materials"] = new TagNodeString("Alpha"); schematic["Blocks"] = new TagNodeByteArray(blockData); schematic["Data"] = new TagNodeByteArray(dataData); NBTFile schematicFile = new NBTFile(path); Stream nbtStream = schematicFile.GetDataOutputStream(); if (nbtStream == null) { return; } NbtTree tree = new NbtTree(schematic, "Schematic"); tree.WriteTo(nbtStream); nbtStream.Close(); }
public void RefreshMeshData() { //Debug.Log("RefreshMeshData,chunk=" + x + ",z=" + z); collidable.Clear(); notCollidable.Clear(); water.Clear(); Vector3Int pos = new Vector3Int(); for (int sectionIndex = 0; sectionIndex < Sections.Count; sectionIndex++) { TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound; TagNodeByteArray Blocks = Section["Blocks"] as TagNodeByteArray; TagNodeByteArray Data = Section["Data"] as TagNodeByteArray; TagNodeByteArray SkyLight = Section["SkyLight"] as TagNodeByteArray; for (int yInSection = 0; yInSection < 16; yInSection++) { for (int zInSection = 0; zInSection < 16; zInSection++) { for (int xInSection = 0; xInSection < 16; xInSection++) { int blockPos = yInSection * 16 * 16 + zInSection * 16 + xInSection; byte rawType = Blocks.Data[blockPos]; NBTBlock generator = NBTGeneratorManager.GetMeshGenerator(rawType); if (generator != null) { int worldY = yInSection + sectionIndex * 16; pos.Set(xInSection, worldY, zInSection); byte blockData = NBTHelper.GetNibble(Data.Data, blockPos); byte skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos); try { if (generator is NBTStationaryWater) { //generator.GenerateMeshInChunk(this, blockData, pos, water); } else if (generator is NBTPlant) { generator.AddCube(this, blockData, skyLight, pos, notCollidable); } else { generator.AddCube(this, blockData, skyLight, pos, collidable); } } catch (System.Exception e) { Debug.LogWarning(generator.GetType() + "\n" + e.ToString()); } } else if (rawType != 0 && rawType != 11) { Debug.LogWarning("generator not exist, type=" + rawType); } } } } } hasBuiltMesh = true; isDirty = false; }