forked from mirrors/NBTExplorer
Introduced MoveBy virtual method to Entity and TileEntity types to handle additional relocation requirements. Fixed relocation of paintings.
This commit is contained in:
parent
73ab937783
commit
40ef315b00
5 changed files with 85 additions and 15 deletions
|
@ -30,8 +30,8 @@ using System.Runtime.InteropServices;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("0.8.1.0")]
|
||||
[assembly: AssemblyFileVersion("0.8.1.0")]
|
||||
[assembly: AssemblyVersion("0.8.3.0")]
|
||||
[assembly: AssemblyFileVersion("0.8.3.0")]
|
||||
|
||||
// This library is compatible with all CLS-compliant .NET programming languages.
|
||||
[assembly: CLSCompliant(true)]
|
|
@ -171,23 +171,31 @@ namespace Substrate
|
|||
|
||||
// Update tile entity coordinates
|
||||
|
||||
foreach (TagNodeCompound te in _tileEntities) {
|
||||
if (te != null && te.ContainsKey("x") && te.ContainsKey("z")) {
|
||||
te["x"].ToTagInt().Data += diffx;
|
||||
te["z"].ToTagInt().Data += diffz;
|
||||
List<TileEntity> tileEntites = new List<TileEntity>();
|
||||
foreach (TagNodeCompound tag in _tileEntities) {
|
||||
TileEntity te = TileEntity.FromTreeSafe(tag);
|
||||
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
|
||||
|
||||
foreach (TagNodeCompound entity in _entities) {
|
||||
if (entity != null && entity.ContainsKey("Pos")) {
|
||||
TagNodeList pos = entity["Pos"].ToTagList();
|
||||
if (pos != null && pos.ValueType == TagType.TAG_DOUBLE && pos.Count == 3) {
|
||||
pos[0].ToTagDouble().Data += diffx;
|
||||
pos[2].ToTagDouble().Data += diffz;
|
||||
}
|
||||
List<TypedEntity> entities = new List<TypedEntity>();
|
||||
foreach (TypedEntity entity in _entityManager) {
|
||||
entity.MoveBy(diffx, 0, diffz);
|
||||
entities.Add(entity);
|
||||
}
|
||||
|
||||
_entities.Clear();
|
||||
foreach (TypedEntity entity in entities) {
|
||||
_entityManager.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Substrate.Entities
|
|||
}
|
||||
|
||||
private DirectionType _dir;
|
||||
private string _motive;
|
||||
private string _motive = "";
|
||||
private int _xTile;
|
||||
private int _yTile;
|
||||
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
|
||||
|
||||
|
|
|
@ -130,6 +130,19 @@ namespace Substrate
|
|||
_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
|
||||
|
||||
|
|
|
@ -60,6 +60,13 @@ namespace Substrate
|
|||
set { _z = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a blank <see cref="TileEntity"/>.
|
||||
/// </summary>
|
||||
protected TileEntity ()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a nonspecific <see cref="TileEntity"/> with a given ID.
|
||||
/// </summary>
|
||||
|
@ -93,6 +100,19 @@ namespace Substrate
|
|||
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
|
||||
|
||||
|
@ -108,6 +128,27 @@ namespace Substrate
|
|||
#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
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue