diff --git a/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs b/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs index 42bba32..59b8c66 100644 --- a/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs +++ b/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs @@ -35,15 +35,15 @@ namespace PurgeEntities // Remove entities foreach (ChunkRef chunk in cm) { // Skip chunks that don't cover our selected area - if (((chunk.X + 1) * chunk.XDim < x1) || - (chunk.X * chunk.XDim >= x2) || - ((chunk.Z + 1) * chunk.ZDim < z1) || - (chunk.Z * chunk.ZDim >= z2)) { + if (((chunk.X + 1) * chunk.Blocks.XDim < x1) || + (chunk.X * chunk.Blocks.XDim >= x2) || + ((chunk.Z + 1) * chunk.Blocks.ZDim < z1) || + (chunk.Z * chunk.Blocks.ZDim >= z2)) { continue; } // Delete the specified entities - chunk.RemoveEntities(eid); + chunk.Entities.RemoveAll(eid); cm.Save(); } } diff --git a/Substrate/SubstrateCS/Source/EntityCollection.cs b/Substrate/SubstrateCS/Source/EntityCollection.cs index df6c309..ab2b0e3 100644 --- a/Substrate/SubstrateCS/Source/EntityCollection.cs +++ b/Substrate/SubstrateCS/Source/EntityCollection.cs @@ -6,7 +6,7 @@ namespace Substrate { using NBT; - public class EntityCollection + public class EntityCollection : IEnumerable { private TagList _entities; @@ -23,7 +23,7 @@ namespace Substrate _entities = entities; } - public List FindEntities (string id) + public List FindAll (string id) { List set = new List(); @@ -46,7 +46,7 @@ namespace Substrate return set; } - public List FindEntities (Predicate match) + public List FindAll (Predicate match) { List set = new List(); @@ -64,7 +64,7 @@ namespace Substrate return set; } - public bool AddEntity (Entity ent) + public bool Add (Entity ent) { /*double xlow = _cx * XDim; double xhigh = xlow + XDim; @@ -82,7 +82,7 @@ namespace Substrate return true; } - public int RemoveEntities (string id) + public int RemoveAll (string id) { int rem = _entities.RemoveAll(val => { @@ -102,11 +102,11 @@ namespace Substrate if (rem > 0) { _dirty = true; } - + return rem; } - public int RemoveEntities (Predicate match) + public int RemoveAll (Predicate match) { int rem = _entities.RemoveAll(val => { @@ -129,5 +129,83 @@ namespace Substrate return rem; } + + #region IEnumerable Members + + public IEnumerator GetEnumerator () + { + return new EntityEnumerator(_entities); + } + + #endregion + + #region IEnumerable Members + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () + { + return new EntityEnumerator(_entities); + } + + #endregion + + public class EntityEnumerator : IEnumerator + { + private TagList _entities; + private IEnumerator _enum; + + private Entity _cur; + + public EntityEnumerator (TagList entities) + { + _entities = entities; + _enum = entities.GetEnumerator(); + } + + #region IEnumerator Members + + public Entity Current + { + get + { + if (_cur == null) { + throw new InvalidOperationException(); + } + return _cur; + } + } + + #endregion + + #region IDisposable Members + + public void Dispose () { } + + #endregion + + #region IEnumerator Members + + object System.Collections.IEnumerator.Current + { + get { return Current; } + } + + public bool MoveNext () + { + if (!_enum.MoveNext()) { + return false; + } + + _cur = EntityFactory.Create(_enum.Current.ToTagCompound()); + return true; + } + + public void Reset () + { + _cur = null; + _enum.Reset(); + } + + #endregion + } } } diff --git a/Substrate/SubstrateCS/Source/Region.cs b/Substrate/SubstrateCS/Source/Region.cs index fc5cf54..f101ac1 100644 --- a/Substrate/SubstrateCS/Source/Region.cs +++ b/Substrate/SubstrateCS/Source/Region.cs @@ -367,41 +367,6 @@ namespace Substrate #endregion - - #region IChunkCache Members - - /*public bool MarkChunkDirty (ChunkRef chunk) - { - int cx = chunk.X; - int cz = chunk.Z; - int lcx = cx - _rx * ChunkManager.REGION_XLEN; - int lcz = cz - _rz * ChunkManager.REGION_ZLEN; - - ChunkKey k = new ChunkKey(lcx, lcz); - if (!_dirty.ContainsKey(k)) { - _dirty.Add(k, GetChunkRef(lcx, lcz)); - return true; - } - return false; - } - - public bool MarkChunkClean (ChunkRef chunk) - { - int cx = chunk.X; - int cz = chunk.Z; - int lcx = cx - _rx * ChunkManager.REGION_XLEN; - int lcz = cz - _rz * ChunkManager.REGION_ZLEN; - - ChunkKey k = new ChunkKey(lcx, lcx); - if (_dirty.ContainsKey(k)) { - _dirty.Remove(k); - return true; - } - return false; - }*/ - - #endregion - private bool LocalBoundsCheck (int lcx, int lcz) { return (lcx >= 0 && lcx < XDIM && lcz >= 0 && lcz < ZDIM); diff --git a/Substrate/SubstrateCS/Source/World.cs b/Substrate/SubstrateCS/Source/World.cs index f6e98df..79aebd7 100644 --- a/Substrate/SubstrateCS/Source/World.cs +++ b/Substrate/SubstrateCS/Source/World.cs @@ -19,6 +19,8 @@ namespace Substrate Level Level { get; } + void Save (); + IBlockManager GetBlockManager (); IBlockManager GetBlockManager (int dim);