From e3192f7a647e415aed9e6df419bfd20407ae1409 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 12 Mar 2012 23:40:38 -0400 Subject: [PATCH] Fixed some bugs, Anvil support kinda works okay now? --- SubstrateCS/Source/AnvilChunk.cs | 48 ++++++++++++++++++++--------- SubstrateCS/Source/RegionManager.cs | 2 +- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/SubstrateCS/Source/AnvilChunk.cs b/SubstrateCS/Source/AnvilChunk.cs index 26e8961..35b9159 100644 --- a/SubstrateCS/Source/AnvilChunk.cs +++ b/SubstrateCS/Source/AnvilChunk.cs @@ -130,7 +130,7 @@ namespace Substrate _blockLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["BlockLight"] as TagNodeByteArray); if (!ctree.ContainsKey("AddBlocks")) - _ctree["AddBlocks"] = new TagNodeByteArray(new byte[2048]); + ctree["AddBlocks"] = new TagNodeByteArray(new byte[2048]); _addBlocks = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["AddBlocks"] as TagNodeByteArray); return this; @@ -147,9 +147,15 @@ namespace Substrate public TagNode BuildTree () { - BuildConditional(); + TagNodeCompound copy = new TagNodeCompound(); + foreach (KeyValuePair node in _tree) { + copy.Add(node.Key, node.Value); + } - return _tree; + if (CheckAddBlocksEmpty()) + copy.Remove("AddBlocks"); + + return copy; } public bool ValidateTree (TagNode tree) @@ -160,13 +166,6 @@ namespace Substrate #endregion - private void BuildConditional () - { - if (CheckAddBlocksEmpty()) { - _tree.Remove("AddBlocks"); - } - } - #region ICopyable Members public AnvilSection Copy () @@ -253,7 +252,7 @@ namespace Substrate public int YDim { - get { return _sections[0].YDim; } + get { return _sections[0].YDim * _sections.Length; } } public int ZDim @@ -356,7 +355,7 @@ namespace Substrate public int YDim { - get { return _sections[0].YDim; } + get { return _sections[0].YDim * _sections.Length; } } public int ZDim @@ -455,6 +454,7 @@ namespace Substrate private IDataArray3 _skyLight; private ZXIntArray _heightMap; + private ZXByteArray _biomes; private TagNodeList _entities; private TagNodeList _tileEntities; @@ -604,7 +604,10 @@ namespace Substrate BuildConditional(); - _tree.WriteTo(outStream); + NbtTree tree = new NbtTree(); + tree.Root["Level"] = BuildTree(); + + tree.WriteTo(outStream); outStream.Close(); return true; @@ -652,6 +655,7 @@ namespace Substrate _blockLight = new CompositeYZXNibbleArray(blockLightBA); _heightMap = new ZXIntArray(XDIM, ZDIM, level["HeightMap"] as TagNodeIntArray); + _biomes = new ZXByteArray(XDIM, ZDIM, level["Biomes"] as TagNodeByteArray); _entities = level["Entities"] as TagNodeList; _tileEntities = level["TileEntities"] as TagNodeList; @@ -697,9 +701,19 @@ namespace Substrate public TagNode BuildTree () { - BuildConditional(); + TagNodeCompound level = _tree.Root["Level"] as TagNodeCompound; + TagNodeCompound levelCopy = new TagNodeCompound(); + foreach (KeyValuePair node in level) + levelCopy.Add(node.Key, node.Value); - return _tree.Root; + TagNodeList sections = new TagNodeList(TagType.TAG_COMPOUND); + for (int i = 0; i < _sections.Length; i++) + if (!_sections[i].CheckEmpty()) + sections.Add(_sections[i].BuildTree()); + + levelCopy["Sections"] = sections; + + return levelCopy; } public bool ValidateTree (TagNode tree) @@ -760,6 +774,9 @@ namespace Substrate 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); + _entities = new TagNodeList(TagType.TAG_COMPOUND); _tileEntities = new TagNodeList(TagType.TAG_COMPOUND); _tileTicks = new TagNodeList(TagType.TAG_COMPOUND); @@ -767,6 +784,7 @@ namespace Substrate 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); diff --git a/SubstrateCS/Source/RegionManager.cs b/SubstrateCS/Source/RegionManager.cs index c8e7a6e..74040e6 100644 --- a/SubstrateCS/Source/RegionManager.cs +++ b/SubstrateCS/Source/RegionManager.cs @@ -75,7 +75,7 @@ namespace Substrate { Region r = GetRegion(rx, rz); if (r == null) { - string fp = "r." + rx + "." + rz + ".mcr"; + string fp = "r." + rx + "." + rz + ".mca"; using (RegionFile rf = new RegionFile(Path.Combine(_regionPath, fp))) { }