Some entity updates

This commit is contained in:
Justin Aquadro 2011-06-01 06:11:50 +00:00
parent bffc44c9ae
commit bb4950d896
4 changed files with 92 additions and 47 deletions

View file

@ -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();
}
}

View file

@ -6,7 +6,7 @@ namespace Substrate
{
using NBT;
public class EntityCollection
public class EntityCollection : IEnumerable<Entity>
{
private TagList _entities;
@ -23,7 +23,7 @@ namespace Substrate
_entities = entities;
}
public List<Entity> FindEntities (string id)
public List<Entity> FindAll (string id)
{
List<Entity> set = new List<Entity>();
@ -46,7 +46,7 @@ namespace Substrate
return set;
}
public List<Entity> FindEntities (Predicate<Entity> match)
public List<Entity> FindAll (Predicate<Entity> match)
{
List<Entity> set = new List<Entity>();
@ -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<Entity> match)
public int RemoveAll (Predicate<Entity> match)
{
int rem = _entities.RemoveAll(val =>
{
@ -129,5 +129,83 @@ namespace Substrate
return rem;
}
#region IEnumerable<Entity> Members
public IEnumerator<Entity> 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<Entity>
{
private TagList _entities;
private IEnumerator<TagValue> _enum;
private Entity _cur;
public EntityEnumerator (TagList entities)
{
_entities = entities;
_enum = entities.GetEnumerator();
}
#region IEnumerator<Entity> 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
}
}
}

View file

@ -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);

View file

@ -19,6 +19,8 @@ namespace Substrate
Level Level { get; }
void Save ();
IBlockManager GetBlockManager ();
IBlockManager GetBlockManager (int dim);