/// <summary> /// Loads the Chunk from an NBT tree rooted at the given TagValue node. /// </summary> /// <param name="tree">Root node of an NBT tree.</param> /// <returns>A reference to the current Chunk, or null if the tree is unparsable.</returns> public Chunk LoadTree(TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return(null); } _tree = new NbtTree(ctree); TagNodeCompound level = _tree.Root["Level"] as TagNodeCompound; _blocks = new XZYByteArray(XDIM, YDIM, ZDIM, level["Blocks"] as TagNodeByteArray); _data = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["Data"] as TagNodeByteArray); _blockLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["BlockLight"] as TagNodeByteArray); _skyLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["SkyLight"] as TagNodeByteArray); _heightMap = new ZXByteArray(XDIM, ZDIM, level["HeightMap"] as TagNodeByteArray); _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); return(this); }
/// <summary> /// Create an empty, exportable schematic of given dimensions. /// </summary> /// <param name="xdim">The length of the X-dimension in blocks.</param> /// <param name="ydim">The length of the Y-dimension in blocks.</param> /// <param name="zdim">The length of the Z-dimension in blocks.</param> public Schematic(int xdim, int ydim, int zdim) { _blocks = new XZYByteArray(xdim, ydim, zdim); _data = new XZYNibbleArray(xdim, ydim, zdim); _blockLight = new XZYNibbleArray(xdim, ydim, zdim); _skyLight = new XZYNibbleArray(xdim, ydim, zdim); _heightMap = new ZXByteArray(xdim, zdim); _entities = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _blockset = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities); _entityset = new EntityCollection(_entities); }
/// <summary> /// Create an empty, exportable schematic of given dimensions. /// </summary> /// <param name="xdim">The length of the X-dimension in blocks.</param> /// <param name="ydim">The length of the Y-dimension in blocks.</param> /// <param name="zdim">The length of the Z-dimension in blocks.</param> public Schematic(int xdim, int ydim, int zdim) { _blocks = new XZYByteArray(xdim, ydim, zdim); _data = new XZYNibbleArray(xdim, ydim, zdim); _blockLight = new XZYNibbleArray(xdim, ydim, zdim); _skyLight = new XZYNibbleArray(xdim, ydim, zdim); _heightMap = new ZXByteArray(xdim, zdim); _entities = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _blockset = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities); _entityset = new EntityCollection(_entities); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> of a given dimension. /// </summary> /// <param name="xdim">The length of the X-dimension of the collection.</param> /// <param name="ydim">The length of the Y-dimension of the collection.</param> /// <param name="zdim">The length of the Z-dimension of the collection.</param> public AlphaBlockCollection(int xdim, int ydim, int zdim) { _blocks = new XZYByteArray(xdim, ydim, zdim); _data = new XZYNibbleArray(xdim, ydim, zdim); _blockLight = new XZYNibbleArray(xdim, ydim, zdim); _skyLight = new XZYNibbleArray(xdim, ydim, zdim); _heightMap = new ZXByteArray(xdim, zdim); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _xdim = xdim; _ydim = ydim; _zdim = zdim; Refresh(); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> of a given dimension. /// </summary> /// <param name="xdim">The length of the X-dimension of the collection.</param> /// <param name="ydim">The length of the Y-dimension of the collection.</param> /// <param name="zdim">The length of the Z-dimension of the collection.</param> public AlphaBlockCollection(int xdim, int ydim, int zdim) { _blocks = new XZYByteArray(xdim, ydim, zdim); _data = new XZYNibbleArray(xdim, ydim, zdim); _blockLight = new XZYNibbleArray(xdim, ydim, zdim); _skyLight = new XZYNibbleArray(xdim, ydim, zdim); _heightMap = new ZXByteArray(xdim, zdim); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _xdim = xdim; _ydim = ydim; _zdim = zdim; Refresh(); }
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); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> overlay on top of Alpha-specific units of data. /// </summary> /// <param name="blocks">An array of Block IDs.</param> /// <param name="data">An array of data nibbles.</param> /// <param name="blockLight">An array of block light nibbles.</param> /// <param name="skyLight">An array of sky light nibbles.</param> /// <param name="heightMap">An array of height map values.</param> /// <param name="tileEntities">A list of tile entities corresponding to blocks in this collection.</param> public AlphaBlockCollection( XZYByteArray blocks, XZYNibbleArray data, XZYNibbleArray blockLight, XZYNibbleArray skyLight, ZXByteArray heightMap, TagNodeList tileEntities) { _blocks = blocks; _data = data; _blockLight = blockLight; _skyLight = skyLight; _heightMap = heightMap; _tileEntities = tileEntities; _xdim = _blocks.XDim; _ydim = _blocks.YDim; _zdim = _blocks.ZDim; Refresh(); }
/// <summary> /// Creates a new <see cref="AlphaBlockCollection"/> overlay on top of Alpha-specific units of data. /// </summary> /// <param name="blocks">An array of Block IDs.</param> /// <param name="data">An array of data nibbles.</param> /// <param name="blockLight">An array of block light nibbles.</param> /// <param name="skyLight">An array of sky light nibbles.</param> /// <param name="heightMap">An array of height map values.</param> /// <param name="tileEntities">A list of tile entities corresponding to blocks in this collection.</param> public AlphaBlockCollection( XZYByteArray blocks, XZYNibbleArray data, XZYNibbleArray blockLight, XZYNibbleArray skyLight, ZXByteArray heightMap, TagNodeList tileEntities) { _blocks = blocks; _data = data; _blockLight = blockLight; _skyLight = skyLight; _heightMap = heightMap; _tileEntities = tileEntities; _xdim = _blocks.XDim; _ydim = _blocks.YDim; _zdim = _blocks.ZDim; Refresh(); }
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(); }
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 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); }