Fixed tileentity data not being copied with chunks. Updated INbtObject types to roundtrip nonstandard data

This commit is contained in:
Justin Aquadro 2011-11-06 15:34:23 -05:00
parent 40ef315b00
commit 752a375aee
6 changed files with 78 additions and 1 deletions

View file

@ -173,7 +173,11 @@ namespace Substrate
List<TileEntity> tileEntites = new List<TileEntity>(); List<TileEntity> tileEntites = new List<TileEntity>();
foreach (TagNodeCompound tag in _tileEntities) { 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) { if (te != null) {
te.MoveBy(diffx, 0, diffz); te.MoveBy(diffx, 0, diffz);
tileEntites.Add(te); tileEntites.Add(te);

View file

@ -22,6 +22,8 @@ namespace Substrate
new SchemaNodeScaler("OnGround", TagType.TAG_BYTE), new SchemaNodeScaler("OnGround", TagType.TAG_BYTE),
}; };
private TagNodeCompound _source;
private Vector3 _pos; private Vector3 _pos;
private Vector3 _motion; private Vector3 _motion;
private Orientation _rotation; private Orientation _rotation;
@ -128,6 +130,10 @@ namespace Substrate
_fire = e._fire; _fire = e._fire;
_air = e._air; _air = e._air;
_onGround = e._onGround; _onGround = e._onGround;
if (e._source != null) {
_source = e._source.Copy() as TagNodeCompound;
}
} }
/// <summary> /// <summary>
@ -187,6 +193,8 @@ namespace Substrate
_air = ctree["Air"].ToTagShort(); _air = ctree["Air"].ToTagShort();
_onGround = ctree["OnGround"].ToTagByte(); _onGround = ctree["OnGround"].ToTagByte();
_source = ctree.Copy() as TagNodeCompound;
return this; return this;
} }
@ -234,6 +242,10 @@ namespace Substrate
tree["Air"] = new TagNodeShort(_air); tree["Air"] = new TagNodeShort(_air);
tree["OnGround"] = new TagNodeByte(_onGround); tree["OnGround"] = new TagNodeByte(_onGround);
if (_source != null) {
tree.MergeFrom(_source);
}
return tree; return tree;
} }

View file

@ -18,6 +18,8 @@ namespace Substrate
new SchemaNodeScaler("Count", TagType.TAG_BYTE), new SchemaNodeScaler("Count", TagType.TAG_BYTE),
}; };
private TagNodeCompound _source;
private short _id; private short _id;
private byte _count; private byte _count;
private short _damage; private short _damage;
@ -96,6 +98,10 @@ namespace Substrate
item._count = _count; item._count = _count;
item._damage = _damage; item._damage = _damage;
if (_source != null) {
item._source = _source.Copy() as TagNodeCompound;
}
return item; return item;
} }
@ -115,6 +121,8 @@ namespace Substrate
_count = ctree["Count"].ToTagByte(); _count = ctree["Count"].ToTagByte();
_damage = ctree["Damage"].ToTagShort(); _damage = ctree["Damage"].ToTagShort();
_source = ctree.Copy() as TagNodeCompound;
return this; return this;
} }
@ -136,6 +144,10 @@ namespace Substrate
tree["Count"] = new TagNodeByte(_count); tree["Count"] = new TagNodeByte(_count);
tree["Damage"] = new TagNodeShort(_damage); tree["Damage"] = new TagNodeShort(_damage);
if (_source != null) {
tree.MergeFrom(_source);
}
return tree; return tree;
} }

View file

@ -49,6 +49,8 @@ namespace Substrate
}, },
}; };
private TagNodeCompound _source;
private NbtWorld _world; private NbtWorld _world;
private long _time; private long _time;
@ -275,6 +277,10 @@ namespace Substrate
if (p._player != null) { if (p._player != null) {
_player = p._player.Copy(); _player = p._player.Copy();
} }
if (p._source != null) {
_source = p._source.Copy() as TagNodeCompound;
}
} }
/// <summary> /// <summary>
@ -388,6 +394,8 @@ namespace Substrate
_mapFeatures = ctree["MapFeatures"].ToTagByte(); _mapFeatures = ctree["MapFeatures"].ToTagByte();
} }
_source = ctree.Copy() as TagNodeCompound;
return this; return this;
} }
@ -453,6 +461,10 @@ namespace Substrate
data["MapFeatures"] = new TagNodeByte(_mapFeatures ?? 0); data["MapFeatures"] = new TagNodeByte(_mapFeatures ?? 0);
} }
if (_source != null) {
data.MergeFrom(_source);
}
TagNodeCompound tree = new TagNodeCompound(); TagNodeCompound tree = new TagNodeCompound();
tree.Add("Data", data); tree.Add("Data", data);

View file

@ -45,6 +45,21 @@ namespace Substrate.Nbt
_tags = new Dictionary<string, TagNode>(); _tags = new Dictionary<string, TagNode>();
} }
/// <summary>
/// Copies all the elements of <paramref name="tree"/> into this <see cref="TagNodeCompound"/> if they do not already exist.
/// </summary>
/// <param name="tree">The source <see cref="TagNodeCompound"/> to copy elements from.</param>
public void MergeFrom (TagNodeCompound tree)
{
foreach (KeyValuePair<string, TagNode> node in tree) {
if (_tags.ContainsKey(node.Key)) {
continue;
}
_tags.Add(node.Key, node.Value);
}
}
/// <summary> /// <summary>
/// Makes a deep copy of the node. /// Makes a deep copy of the node.
/// </summary> /// </summary>

View file

@ -20,6 +20,8 @@ namespace Substrate
new SchemaNodeScaler("z", TagType.TAG_INT), new SchemaNodeScaler("z", TagType.TAG_INT),
}; };
private TagNodeCompound _source;
private string _id; private string _id;
private int _x; private int _x;
private int _y; private int _y;
@ -60,6 +62,14 @@ namespace Substrate
set { _z = value; } set { _z = value; }
} }
/// <summary>
/// Gets the source <see cref="TagNodeCompound"/> used to create this <see cref="TileEntity"/> if it exists.
/// </summary>
protected TagNodeCompound Source
{
get { return _source; }
}
/// <summary> /// <summary>
/// Constructs a blank <see cref="TileEntity"/>. /// Constructs a blank <see cref="TileEntity"/>.
/// </summary> /// </summary>
@ -86,6 +96,10 @@ namespace Substrate
_x = te._x; _x = te._x;
_y = te._y; _y = te._y;
_z = te._z; _z = te._z;
if (te._source != null) {
_source = te._source.Copy() as TagNodeCompound;
}
} }
/// <summary> /// <summary>
@ -176,6 +190,8 @@ namespace Substrate
_y = ctree["y"].ToTagInt(); _y = ctree["y"].ToTagInt();
_z = ctree["z"].ToTagInt(); _z = ctree["z"].ToTagInt();
_source = ctree.Copy() as TagNodeCompound;
return this; return this;
} }
@ -205,6 +221,10 @@ namespace Substrate
tree["y"] = new TagNodeInt(_y); tree["y"] = new TagNodeInt(_y);
tree["z"] = new TagNodeInt(_z); tree["z"] = new TagNodeInt(_z);
if (_source != null) {
tree.MergeFrom(_source);
}
return tree; return tree;
} }
@ -218,6 +238,8 @@ namespace Substrate
return new NbtVerifier(tree, _schema).Verify(); return new NbtVerifier(tree, _schema).Verify();
} }
#endregion #endregion
} }