Undid previous changes. Added CreateGeneric() function to TileEntityFactory that returns a TileEntity class if no registered class exists for a given NBT tree. Changed GetTileEntity to in BlockTileEntities to use the new function.

This commit is contained in:
sukasa 2012-11-05 21:35:57 -08:00
parent aa11b9d38a
commit 46eb7c3244
3 changed files with 10 additions and 20 deletions

View file

@ -679,13 +679,7 @@ namespace Substrate
/// <inheritdoc/> /// <inheritdoc/>
public TileEntity GetTileEntity (int x, int y, int z) public TileEntity GetTileEntity (int x, int y, int z)
{ {
return GetTileEntity(x, y, z, false); return _tileEntityManager.GetTileEntity(x, y, z);
}
/// <inheritdoc/>
public TileEntity GetTileEntity(int x, int y, int z, bool unregistered)
{
return _tileEntityManager.GetTileEntity(x, y, z, unregistered);
} }
internal TileEntity GetTileEntity (int index) internal TileEntity GetTileEntity (int index)
@ -693,7 +687,7 @@ namespace Substrate
int x, y, z; int x, y, z;
_blocks.GetMultiIndex(index, out x, out y, out z); _blocks.GetMultiIndex(index, out x, out y, out z);
return GetTileEntity(x, y, z, false); return _tileEntityManager.GetTileEntity(x, y, z);
} }
/// <inheritdoc/> /// <inheritdoc/>

View file

@ -31,7 +31,7 @@ namespace Substrate.Core
BuildTileEntityCache(); BuildTileEntityCache();
} }
public TileEntity GetTileEntity (int x, int y, int z, bool unregistered) public TileEntity GetTileEntity (int x, int y, int z)
{ {
BlockKey key = (TranslateCoordinates != null) BlockKey key = (TranslateCoordinates != null)
? TranslateCoordinates(x, y, z) ? TranslateCoordinates(x, y, z)
@ -43,7 +43,7 @@ namespace Substrate.Core
return null; return null;
} }
return unregistered ? TileEntityFactory.CreateAlways(te) : TileEntityFactory.Create(te); return TileEntityFactory.CreateGeneric(te);
} }
public void SetTileEntity (int x, int y, int z, TileEntity te) public void SetTileEntity (int x, int y, int z, TileEntity te)

View file

@ -52,27 +52,23 @@ namespace Substrate
} }
/// <summary> /// <summary>
/// Create a new instance of a <see cref="TileEntity"/> type by NBT node, or a blank TileEntity otherwise. /// Create a new instance of a concrete <see cref="TileEntity"/> type by NBT node.
/// </summary> /// </summary>
/// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Tile Entity, containing an 'id' field of the Tile Entity's registered name.</param> /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Tile Entity, containing an 'id' field of the Tile Entity's registered name.</param>
/// <returns>A new instance of a concrete <see cref="TileEntity"/> type, or null if no type was registered with the given name.</returns> /// <returns>A new instance of a concrete <see cref="TileEntity"/> type, or null if no type was registered with the given name.</returns>
public static TileEntity CreateAlways(TagNodeCompound tree) public static TileEntity CreateGeneric(TagNodeCompound tree)
{ {
string type = tree["id"].ToTagString(); string type = tree["id"].ToTagString();
Type t; Type t;
TileEntity te;
if (!_registry.TryGetValue(type, out t)) if (!_registry.TryGetValue(type, out t))
{ {
te = new TileEntity(""); t = typeof (TileEntity);
}
else
{
te = Activator.CreateInstance(t) as TileEntity;
} }
TileEntity te = Activator.CreateInstance(t, true) as TileEntity;
return te.LoadTreeSafe(tree); return te.LoadTreeSafe(tree);
} }