Modification to allow force-returning of TileEntity objects via additional param. Useful for dealing with mod-installed TileEntities not natively supported by Substrate

This commit is contained in:
sukasa 2012-11-04 19:33:06 -08:00
parent 700266615f
commit 9fb96750d6
3 changed files with 39 additions and 7 deletions

View file

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

View file

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

View file

@ -41,7 +41,8 @@ namespace Substrate
string type = tree["id"].ToTagString();
Type t;
if (!_registry.TryGetValue(type, out t)) {
if (!_registry.TryGetValue(type, out t))
{
return null;
}
@ -50,6 +51,31 @@ namespace Substrate
return te.LoadTreeSafe(tree);
}
/// <summary>
/// Create a new instance of a <see cref="TileEntity"/> type by NBT node, or a blank TileEntity otherwise.
/// </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>
/// <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)
{
string type = tree["id"].ToTagString();
Type t;
TileEntity te;
if (!_registry.TryGetValue(type, out t))
{
te = new TileEntity("");
}
else
{
te = Activator.CreateInstance(t) as TileEntity;
}
return te.LoadTreeSafe(tree);
}
/// <summary>
/// Lookup a concrete <see cref="TileEntity"/> type by name.
/// </summary>