diff --git a/SubstrateCS/Source/Chunk.cs b/SubstrateCS/Source/Chunk.cs index 0a7ef25..f5fb8fe 100644 --- a/SubstrateCS/Source/Chunk.cs +++ b/SubstrateCS/Source/Chunk.cs @@ -173,7 +173,11 @@ namespace Substrate List tileEntites = new List(); foreach (TagNodeCompound tag in _tileEntities) { - TileEntity te = TileEntity.FromTreeSafe(tag); + TileEntity te = TileEntityFactory.Create(tag); + if (te == null) { + te = TileEntity.FromTreeSafe(tag); + } + if (te != null) { te.MoveBy(diffx, 0, diffz); tileEntites.Add(te); diff --git a/SubstrateCS/Source/Entity.cs b/SubstrateCS/Source/Entity.cs index c2901fc..99ee315 100644 --- a/SubstrateCS/Source/Entity.cs +++ b/SubstrateCS/Source/Entity.cs @@ -22,6 +22,8 @@ namespace Substrate new SchemaNodeScaler("OnGround", TagType.TAG_BYTE), }; + private TagNodeCompound _source; + private Vector3 _pos; private Vector3 _motion; private Orientation _rotation; @@ -128,6 +130,10 @@ namespace Substrate _fire = e._fire; _air = e._air; _onGround = e._onGround; + + if (e._source != null) { + _source = e._source.Copy() as TagNodeCompound; + } } /// @@ -187,6 +193,8 @@ namespace Substrate _air = ctree["Air"].ToTagShort(); _onGround = ctree["OnGround"].ToTagByte(); + _source = ctree.Copy() as TagNodeCompound; + return this; } @@ -234,6 +242,10 @@ namespace Substrate tree["Air"] = new TagNodeShort(_air); tree["OnGround"] = new TagNodeByte(_onGround); + if (_source != null) { + tree.MergeFrom(_source); + } + return tree; } diff --git a/SubstrateCS/Source/Item.cs b/SubstrateCS/Source/Item.cs index dafc6f0..2346259 100644 --- a/SubstrateCS/Source/Item.cs +++ b/SubstrateCS/Source/Item.cs @@ -18,6 +18,8 @@ namespace Substrate new SchemaNodeScaler("Count", TagType.TAG_BYTE), }; + private TagNodeCompound _source; + private short _id; private byte _count; private short _damage; @@ -96,6 +98,10 @@ namespace Substrate item._count = _count; item._damage = _damage; + if (_source != null) { + item._source = _source.Copy() as TagNodeCompound; + } + return item; } @@ -115,6 +121,8 @@ namespace Substrate _count = ctree["Count"].ToTagByte(); _damage = ctree["Damage"].ToTagShort(); + _source = ctree.Copy() as TagNodeCompound; + return this; } @@ -136,6 +144,10 @@ namespace Substrate tree["Count"] = new TagNodeByte(_count); tree["Damage"] = new TagNodeShort(_damage); + if (_source != null) { + tree.MergeFrom(_source); + } + return tree; } diff --git a/SubstrateCS/Source/Level.cs b/SubstrateCS/Source/Level.cs index f0fb4c4..aa9ab94 100644 --- a/SubstrateCS/Source/Level.cs +++ b/SubstrateCS/Source/Level.cs @@ -49,6 +49,8 @@ namespace Substrate }, }; + private TagNodeCompound _source; + private NbtWorld _world; private long _time; @@ -275,6 +277,10 @@ namespace Substrate if (p._player != null) { _player = p._player.Copy(); } + + if (p._source != null) { + _source = p._source.Copy() as TagNodeCompound; + } } /// @@ -388,6 +394,8 @@ namespace Substrate _mapFeatures = ctree["MapFeatures"].ToTagByte(); } + _source = ctree.Copy() as TagNodeCompound; + return this; } @@ -453,6 +461,10 @@ namespace Substrate data["MapFeatures"] = new TagNodeByte(_mapFeatures ?? 0); } + if (_source != null) { + data.MergeFrom(_source); + } + TagNodeCompound tree = new TagNodeCompound(); tree.Add("Data", data); diff --git a/SubstrateCS/Source/Nbt/TagNodeCompound.cs b/SubstrateCS/Source/Nbt/TagNodeCompound.cs index 11b716a..3045f90 100644 --- a/SubstrateCS/Source/Nbt/TagNodeCompound.cs +++ b/SubstrateCS/Source/Nbt/TagNodeCompound.cs @@ -45,6 +45,21 @@ namespace Substrate.Nbt _tags = new Dictionary(); } + /// + /// Copies all the elements of into this if they do not already exist. + /// + /// The source to copy elements from. + public void MergeFrom (TagNodeCompound tree) + { + foreach (KeyValuePair node in tree) { + if (_tags.ContainsKey(node.Key)) { + continue; + } + + _tags.Add(node.Key, node.Value); + } + } + /// /// Makes a deep copy of the node. /// diff --git a/SubstrateCS/Source/TileEntity.cs b/SubstrateCS/Source/TileEntity.cs index 00dd4d2..5fa3abb 100644 --- a/SubstrateCS/Source/TileEntity.cs +++ b/SubstrateCS/Source/TileEntity.cs @@ -20,6 +20,8 @@ namespace Substrate new SchemaNodeScaler("z", TagType.TAG_INT), }; + private TagNodeCompound _source; + private string _id; private int _x; private int _y; @@ -60,6 +62,14 @@ namespace Substrate set { _z = value; } } + /// + /// Gets the source used to create this if it exists. + /// + protected TagNodeCompound Source + { + get { return _source; } + } + /// /// Constructs a blank . /// @@ -86,6 +96,10 @@ namespace Substrate _x = te._x; _y = te._y; _z = te._z; + + if (te._source != null) { + _source = te._source.Copy() as TagNodeCompound; + } } /// @@ -176,6 +190,8 @@ namespace Substrate _y = ctree["y"].ToTagInt(); _z = ctree["z"].ToTagInt(); + _source = ctree.Copy() as TagNodeCompound; + return this; } @@ -205,6 +221,10 @@ namespace Substrate tree["y"] = new TagNodeInt(_y); tree["z"] = new TagNodeInt(_z); + if (_source != null) { + tree.MergeFrom(_source); + } + return tree; } @@ -218,6 +238,8 @@ namespace Substrate return new NbtVerifier(tree, _schema).Verify(); } + + #endregion }