forked from mirrors/NBTExplorer
Fixed enumeration bug in EntityCollection
This commit is contained in:
parent
4d4a14b866
commit
37739af562
2 changed files with 27 additions and 1 deletions
|
@ -188,12 +188,14 @@ namespace Substrate
|
|||
{
|
||||
private IEnumerator<TagNode> _enum;
|
||||
|
||||
private bool _next;
|
||||
private TypedEntity _cur;
|
||||
|
||||
internal Enumerator (TagNodeList entities)
|
||||
{
|
||||
_enum = entities.GetEnumerator();
|
||||
_cur = null;
|
||||
_next = false;
|
||||
}
|
||||
|
||||
#region IEnumerator<Entity> Members
|
||||
|
@ -205,7 +207,7 @@ namespace Substrate
|
|||
{
|
||||
get
|
||||
{
|
||||
if (_cur == null) {
|
||||
if (_next == false) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
return _cur;
|
||||
|
@ -240,10 +242,16 @@ namespace Substrate
|
|||
public bool MoveNext ()
|
||||
{
|
||||
if (!_enum.MoveNext()) {
|
||||
_next = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
_cur = EntityFactory.Create(_enum.Current.ToTagCompound());
|
||||
if (_cur == null)
|
||||
_cur = EntityFactory.CreateGeneric(_enum.Current.ToTagCompound());
|
||||
|
||||
_next = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -253,6 +261,7 @@ namespace Substrate
|
|||
void System.Collections.IEnumerator.Reset ()
|
||||
{
|
||||
_cur = null;
|
||||
_next = false;
|
||||
_enum.Reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,23 @@ namespace Substrate
|
|||
return te.LoadTreeSafe(tree);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of a nonspecific <see cref="TypedEntity"/> object by NBT node.
|
||||
/// </summary>
|
||||
/// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field.</param>
|
||||
/// <returns>A new instance of a <see cref="TypedEntity"/> object, or null if the entity is not typed.</returns>
|
||||
public static TypedEntity CreateGeneric (TagNodeCompound tree)
|
||||
{
|
||||
TagNode type;
|
||||
if (!tree.TryGetValue("id", out type)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TypedEntity te = new TypedEntity(type.ToTagString().Data);
|
||||
|
||||
return te.LoadTreeSafe(tree);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lookup a concrete <see cref="TypedEntity"/> type by name.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in a new issue