From 40ef315b00df257297c7a03be914eef955a328d4 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 6 Nov 2011 12:32:43 -0500 Subject: [PATCH] Introduced MoveBy virtual method to Entity and TileEntity types to handle additional relocation requirements. Fixed relocation of paintings. --- SubstrateCS/Properties/AssemblyInfo.cs | 4 +- SubstrateCS/Source/Chunk.cs | 32 +++++++++------ SubstrateCS/Source/Entities/EntityPainting.cs | 10 ++++- SubstrateCS/Source/Entity.cs | 13 ++++++ SubstrateCS/Source/TileEntity.cs | 41 +++++++++++++++++++ 5 files changed, 85 insertions(+), 15 deletions(-) diff --git a/SubstrateCS/Properties/AssemblyInfo.cs b/SubstrateCS/Properties/AssemblyInfo.cs index 0df902e..600767f 100644 --- a/SubstrateCS/Properties/AssemblyInfo.cs +++ b/SubstrateCS/Properties/AssemblyInfo.cs @@ -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)] \ No newline at end of file diff --git a/SubstrateCS/Source/Chunk.cs b/SubstrateCS/Source/Chunk.cs index eb59eda..0a7ef25 100644 --- a/SubstrateCS/Source/Chunk.cs +++ b/SubstrateCS/Source/Chunk.cs @@ -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 tileEntites = new List(); + 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 entities = new List(); + foreach (TypedEntity entity in _entityManager) { + entity.MoveBy(diffx, 0, diffz); + entities.Add(entity); + } + + _entities.Clear(); + foreach (TypedEntity entity in entities) { + _entityManager.Add(entity); } } diff --git a/SubstrateCS/Source/Entities/EntityPainting.cs b/SubstrateCS/Source/Entities/EntityPainting.cs index a6818cf..28444a4 100644 --- a/SubstrateCS/Source/Entities/EntityPainting.cs +++ b/SubstrateCS/Source/Entities/EntityPainting.cs @@ -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 Members diff --git a/SubstrateCS/Source/Entity.cs b/SubstrateCS/Source/Entity.cs index 7788ec3..c2901fc 100644 --- a/SubstrateCS/Source/Entity.cs +++ b/SubstrateCS/Source/Entity.cs @@ -130,6 +130,19 @@ namespace Substrate _onGround = e._onGround; } + /// + /// Moves the by given block offsets. + /// + /// The X-offset to move by, in blocks. + /// The Y-offset to move by, in blocks. + /// The Z-offset to move by, in blocks. + public virtual void MoveBy (int diffX, int diffY, int diffZ) + { + _pos.X += diffX; + _pos.Y += diffY; + _pos.Z += diffZ; + } + #region INBTObject Members diff --git a/SubstrateCS/Source/TileEntity.cs b/SubstrateCS/Source/TileEntity.cs index d6c2104..00dd4d2 100644 --- a/SubstrateCS/Source/TileEntity.cs +++ b/SubstrateCS/Source/TileEntity.cs @@ -60,6 +60,13 @@ namespace Substrate set { _z = value; } } + /// + /// Constructs a blank . + /// + protected TileEntity () + { + } + /// /// Constructs a nonspecific with a given ID. /// @@ -93,6 +100,19 @@ namespace Substrate return _x == x && _y == y && _z == z; } + /// + /// Moves the by given block offsets. + /// + /// The X-offset to move by, in blocks. + /// The Y-offset to move by, in blocks. + /// The Z-offset to move by, in blocks. + public virtual void MoveBy (int diffX, int diffY, int diffZ) + { + _x += diffX; + _y += diffY; + _z += diffZ; + } + #region ICopyable Members @@ -108,6 +128,27 @@ namespace Substrate #endregion + /// + /// Attempt to construct a new from a Tile Entity subtree without validation. + /// + /// The root node of a Tile Entity subtree. + /// A new on success, or null if the tree was unparsable. + public static TileEntity FromTree (TagNode tree) + { + return new TileEntity().LoadTree(tree); + } + + /// + /// Attempt to construct a new from a Tile Entity subtree with validation. + /// + /// The root node of a Tile Entity subtree. + /// A new on success, or null if the tree failed validation. + public static TileEntity FromTreeSafe (TagNode tree) + { + return new TileEntity().LoadTreeSafe(tree); + } + + #region INBTObject Members ///