Introduced MoveBy virtual method to Entity and TileEntity types to handle additional relocation requirements. Fixed relocation of paintings.

This commit is contained in:
Justin Aquadro 2011-11-06 12:32:43 -05:00
parent 73ab937783
commit 40ef315b00
5 changed files with 85 additions and 15 deletions

View file

@ -30,8 +30,8 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("0.8.1.0")] [assembly: AssemblyVersion("0.8.3.0")]
[assembly: AssemblyFileVersion("0.8.1.0")] [assembly: AssemblyFileVersion("0.8.3.0")]
// This library is compatible with all CLS-compliant .NET programming languages. // This library is compatible with all CLS-compliant .NET programming languages.
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View file

@ -171,23 +171,31 @@ namespace Substrate
// Update tile entity coordinates // Update tile entity coordinates
foreach (TagNodeCompound te in _tileEntities) { List<TileEntity> tileEntites = new List<TileEntity>();
if (te != null && te.ContainsKey("x") && te.ContainsKey("z")) { foreach (TagNodeCompound tag in _tileEntities) {
te["x"].ToTagInt().Data += diffx; TileEntity te = TileEntity.FromTreeSafe(tag);
te["z"].ToTagInt().Data += diffz; if (te != null) {
te.MoveBy(diffx, 0, diffz);
tileEntites.Add(te);
} }
} }
_tileEntities.Clear();
foreach (TileEntity te in tileEntites) {
_tileEntities.Add(te.BuildTree());
}
// Update entity coordinates // Update entity coordinates
foreach (TagNodeCompound entity in _entities) { List<TypedEntity> entities = new List<TypedEntity>();
if (entity != null && entity.ContainsKey("Pos")) { foreach (TypedEntity entity in _entityManager) {
TagNodeList pos = entity["Pos"].ToTagList(); entity.MoveBy(diffx, 0, diffz);
if (pos != null && pos.ValueType == TagType.TAG_DOUBLE && pos.Count == 3) { entities.Add(entity);
pos[0].ToTagDouble().Data += diffx; }
pos[2].ToTagDouble().Data += diffz;
} _entities.Clear();
} foreach (TypedEntity entity in entities) {
_entityManager.Add(entity);
} }
} }

View file

@ -32,7 +32,7 @@ namespace Substrate.Entities
} }
private DirectionType _dir; private DirectionType _dir;
private string _motive; private string _motive = "";
private int _xTile; private int _xTile;
private int _yTile; private int _yTile;
private int _zTile; private int _zTile;
@ -90,6 +90,14 @@ namespace Substrate.Entities
} }
} }
public override void MoveBy (int diffX, int diffY, int diffZ)
{
base.MoveBy(diffX, diffY, diffZ);
_xTile += diffX;
_yTile += diffY;
_zTile += diffZ;
}
#region INBTObject<Entity> Members #region INBTObject<Entity> Members

View file

@ -130,6 +130,19 @@ namespace Substrate
_onGround = e._onGround; _onGround = e._onGround;
} }
/// <summary>
/// Moves the <see cref="Entity"/> by given block offsets.
/// </summary>
/// <param name="diffX">The X-offset to move by, in blocks.</param>
/// <param name="diffY">The Y-offset to move by, in blocks.</param>
/// <param name="diffZ">The Z-offset to move by, in blocks.</param>
public virtual void MoveBy (int diffX, int diffY, int diffZ)
{
_pos.X += diffX;
_pos.Y += diffY;
_pos.Z += diffZ;
}
#region INBTObject<Entity> Members #region INBTObject<Entity> Members

View file

@ -60,6 +60,13 @@ namespace Substrate
set { _z = value; } set { _z = value; }
} }
/// <summary>
/// Constructs a blank <see cref="TileEntity"/>.
/// </summary>
protected TileEntity ()
{
}
/// <summary> /// <summary>
/// Constructs a nonspecific <see cref="TileEntity"/> with a given ID. /// Constructs a nonspecific <see cref="TileEntity"/> with a given ID.
/// </summary> /// </summary>
@ -93,6 +100,19 @@ namespace Substrate
return _x == x && _y == y && _z == z; return _x == x && _y == y && _z == z;
} }
/// <summary>
/// Moves the <see cref="TileEntity"/> by given block offsets.
/// </summary>
/// <param name="diffX">The X-offset to move by, in blocks.</param>
/// <param name="diffY">The Y-offset to move by, in blocks.</param>
/// <param name="diffZ">The Z-offset to move by, in blocks.</param>
public virtual void MoveBy (int diffX, int diffY, int diffZ)
{
_x += diffX;
_y += diffY;
_z += diffZ;
}
#region ICopyable<TileEntity> Members #region ICopyable<TileEntity> Members
@ -108,6 +128,27 @@ namespace Substrate
#endregion #endregion
/// <summary>
/// Attempt to construct a new <see cref="TileEntity"/> from a Tile Entity subtree without validation.
/// </summary>
/// <param name="tree">The root node of a Tile Entity subtree.</param>
/// <returns>A new <see cref="TileEntity"/> on success, or null if the tree was unparsable.</returns>
public static TileEntity FromTree (TagNode tree)
{
return new TileEntity().LoadTree(tree);
}
/// <summary>
/// Attempt to construct a new <see cref="TileEntity"/> from a Tile Entity subtree with validation.
/// </summary>
/// <param name="tree">The root node of a Tile Entity subtree.</param>
/// <returns>A new <see cref="TileEntity"/> on success, or null if the tree failed validation.</returns>
public static TileEntity FromTreeSafe (TagNode tree)
{
return new TileEntity().LoadTreeSafe(tree);
}
#region INBTObject<TileEntity> Members #region INBTObject<TileEntity> Members
/// <summary> /// <summary>