Documentation, tweaking (get used to this...)

This commit is contained in:
Justin Aquadro 2011-06-28 03:41:44 +00:00
parent c1d2f053df
commit 8cfbd26f6b
11 changed files with 100 additions and 15 deletions

View file

@ -32,7 +32,7 @@ namespace Substrate
new SchemaNodeArray("BlockLight", 16384),
new SchemaNodeArray("HeightMap", 256),
new SchemaNodeList("Entities", TagType.TAG_COMPOUND, 0, SchemaOptions.CREATE_ON_MISSING),
new SchemaNodeList("TileEntities", TagType.TAG_COMPOUND, TileEntity.BaseSchema, SchemaOptions.CREATE_ON_MISSING),
new SchemaNodeList("TileEntities", TagType.TAG_COMPOUND, TileEntity.Schema, SchemaOptions.CREATE_ON_MISSING),
new SchemaNodeScaler("LastUpdate", TagType.TAG_LONG, SchemaOptions.CREATE_ON_MISSING),
new SchemaNodeScaler("xPos", TagType.TAG_INT),
new SchemaNodeScaler("zPos", TagType.TAG_INT),

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate.NBT
{

View file

@ -8,7 +8,7 @@ namespace Substrate.TileEntities
public class TileEntityChest : TileEntity, IItemContainer
{
public static readonly SchemaNodeCompound ChestSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
public static readonly SchemaNodeCompound ChestSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "Chest"),
new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),

View file

@ -8,7 +8,7 @@ namespace Substrate.TileEntities
public class TileEntityFurnace : TileEntity, IItemContainer
{
public static readonly SchemaNodeCompound FurnaceSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
public static readonly SchemaNodeCompound FurnaceSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "Furnace"),
new SchemaNodeScaler("BurnTime", TagType.TAG_SHORT),

View file

@ -8,7 +8,7 @@ namespace Substrate.TileEntities
public class TileEntityMobSpawner : TileEntity
{
public static readonly SchemaNodeCompound MobSpawnerSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
public static readonly SchemaNodeCompound MobSpawnerSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "MobSpawner"),
new SchemaNodeScaler("EntityId", TagType.TAG_STRING),

View file

@ -8,7 +8,7 @@ namespace Substrate.TileEntities
public class TileEntityMusic : TileEntity
{
public static readonly SchemaNodeCompound MusicSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
public static readonly SchemaNodeCompound MusicSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "Music"),
new SchemaNodeScaler("note", TagType.TAG_BYTE),

View file

@ -8,7 +8,7 @@ namespace Substrate.TileEntities
public class TileEntityRecordPlayer : TileEntity
{
public static readonly SchemaNodeCompound RecordPlayerSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
public static readonly SchemaNodeCompound RecordPlayerSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "RecordPlayer"),
new SchemaNodeScaler("Record", TagType.TAG_INT, SchemaOptions.OPTIONAL),

View file

@ -8,7 +8,7 @@ namespace Substrate.TileEntities
public class TileEntitySign : TileEntity
{
public static readonly SchemaNodeCompound SignSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
public static readonly SchemaNodeCompound SignSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "Sign"),
new SchemaNodeScaler("Text1", TagType.TAG_STRING),

View file

@ -8,7 +8,7 @@ namespace Substrate.TileEntities
public class TileEntityTrap : TileEntity, IItemContainer
{
public static readonly SchemaNodeCompound TrapSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
public static readonly SchemaNodeCompound TrapSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "Trap"),
new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),

View file

@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate
{
using NBT;
using Utility;
/// <summary>
/// Represents a Tile Entity record, which provides additional data to a block.
/// </summary>
/// <remarks>Generally, this class should be subtyped into new concrete Tile Entity types, as this generic type is unable to
/// capture any of the custom data fields that make Tile Entities useful in the first place. It is however still possible to
/// create instances of <see cref="TileEntity"/> objects, which may allow for graceful handling of unknown Tile Entities.</remarks>
public class TileEntity : INBTObject<TileEntity>, ICopyable<TileEntity>
{
public static readonly SchemaNodeCompound BaseSchema = new SchemaNodeCompound("")
private static readonly SchemaNodeCompound _schema = new SchemaNodeCompound("")
{
new SchemaNodeScaler("id", TagType.TAG_STRING),
new SchemaNodeScaler("x", TagType.TAG_INT),
@ -22,34 +26,54 @@ namespace Substrate
private int _y;
private int _z;
/// <summary>
/// Gets the id (name) of the Tile Entity.
/// </summary>
public string ID
{
get { return _id; }
}
/// <summary>
/// Gets or sets the global X-coordinate of the block that this Tile Entity is associated with.
/// </summary>
public int X
{
get { return _x; }
set { _x = value; }
}
/// <summary>
/// Gets or sets the global Y-coordinate of the block that this Tile Entity is associated with.
/// </summary>
public int Y
{
get { return _y; }
set { _y = value; }
}
/// <summary>
/// Gets or sets the global Z-coordinate of the block that this Tile Entity is associated with.
/// </summary>
public int Z
{
get { return _z; }
set { _z = value; }
}
/// <summary>
/// Constructs a nonspecific <see cref="TileEntity"/> with a given ID.
/// </summary>
/// <param name="id">The id (name) of the Tile Entity.</param>
public TileEntity (string id)
{
_id = id;
}
/// <summary>
/// Constructs a <see cref="TileEntity"/> by copying an existing one.
/// </summary>
/// <param name="te">The <see cref="TileEntity"/> to copy.</param>
public TileEntity (TileEntity te)
{
_id = te._id;
@ -58,6 +82,13 @@ namespace Substrate
_z = te._z;
}
/// <summary>
/// Checks whether the Tile Entity is located (associated with a block) at the specific global coordinates.
/// </summary>
/// <param name="x">The global X-coordinate to test.</param>
/// <param name="y">The global Y-coordinate to test.</param>
/// <param name="z">The global Z-coordinate to test.</param>
/// <returns>Status indicating whether the Tile Entity is located at the specified global coordinates.</returns>
public bool LocatedAt (int x, int y, int z)
{
return _x == x && _y == y && _z == z;
@ -66,6 +97,10 @@ namespace Substrate
#region ICopyable<TileEntity> Members
/// <summary>
/// Creates a deep-copy of the <see cref="TileEntity"/> including any data defined in a subtype.
/// </summary>
/// <returns>A deep-copy of the <see cref="TileEntity"/>.</returns>
public virtual TileEntity Copy ()
{
return new TileEntity(this);
@ -76,6 +111,19 @@ namespace Substrate
#region INBTObject<TileEntity> Members
/// <summary>
/// Gets a <see cref="SchemaNode"/> representing the basic schema of a Tile Entity.
/// </summary>
public static SchemaNodeCompound Schema
{
get { return _schema; }
}
/// <summary>
/// Attempt to load a Tile Entity subtree into the <see cref="TileEntity"/> without validation.
/// </summary>
/// <param name="tree">The root node of a Tile Entity subtree.</param>
/// <returns>The <see cref="TileEntity"/> returns itself on success, or null if the tree was unparsable.</returns>
public virtual TileEntity LoadTree (TagNode tree)
{
TagNodeCompound ctree = tree as TagNodeCompound;
@ -91,6 +139,11 @@ namespace Substrate
return this;
}
/// <summary>
/// Attempt to load a Tile Entity subtree into the <see cref="TileEntity"/> with validation.
/// </summary>
/// <param name="tree">The root node of a Tile Entity subtree.</param>
/// <returns>The <see cref="TileEntity"/> returns itself on success, or null if the tree failed validation.</returns>
public virtual TileEntity LoadTreeSafe (TagNode tree)
{
if (!ValidateTree(tree)) {
@ -100,6 +153,10 @@ namespace Substrate
return LoadTree(tree);
}
/// <summary>
/// Builds a Tile Entity subtree from the current data.
/// </summary>
/// <returns>The root node of a Tile Entity subtree representing the current data.</returns>
public virtual TagNode BuildTree ()
{
TagNodeCompound tree = new TagNodeCompound();
@ -111,9 +168,14 @@ namespace Substrate
return tree;
}
/// <summary>
/// Validate a Tile Entity subtree against a basic schema.
/// </summary>
/// <param name="tree">The root node of a Tile Entity subtree.</param>
/// <returns>Status indicating whether the tree was valid against the internal schema.</returns>
public virtual bool ValidateTree (TagNode tree)
{
return new NBTVerifier(tree, BaseSchema).Verify();
return new NBTVerifier(tree, _schema).Verify();
}
#endregion

View file

@ -1,16 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate
{
using NBT;
using TileEntities;
/// <summary>
/// Creates new instances of concrete <see cref="TileEntity"/> types from a dynamic registry.
/// </summary>
/// <remarks>This factory allows specific <see cref="TileEntity"/> objects to be generated as an NBT tree is parsed. New types can be
/// registered with the factory at any time, so that custom <see cref="TileEntity"/> types can be supported. By default, the standard
/// Tile Entities of Minecraft are registered with the factory at startup and bound to their respective 'id' fields.</remarks>
public class TileEntityFactory
{
private static Dictionary<string, Type> _registry;
/// <summary>
/// Create a new instance of a concrete <see cref="TileEntity"/> type by name.
/// </summary>
/// <param name="type">The name that a concrete <see cref="TileEntity"/> type was registered with.</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 Create (string type)
{
Type t;
@ -21,6 +31,11 @@ namespace Substrate
return Activator.CreateInstance(t) as TileEntity;
}
/// <summary>
/// Create a new instance of a concrete <see cref="TileEntity"/> type by NBT node.
/// </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 Create (TagNodeCompound tree)
{
string type = tree["id"].ToTagString();
@ -35,6 +50,11 @@ namespace Substrate
return te.LoadTreeSafe(tree);
}
/// <summary>
/// Lookup a concrete <see cref="TileEntity"/> type by name.
/// </summary>
/// <param name="type">The name that a concrete <see cref="TileEntity"/> type was registered with.</param>
/// <returns>The <see cref="Type"/> of a concrete <see cref="TileEntity"/> type, or null if no type was registered with the given name.</returns>
public static Type Lookup (string type)
{
Type t;
@ -45,6 +65,11 @@ namespace Substrate
return t;
}
/// <summary>
/// Registers a new concrete <see cref="TileEntity"/> type with the <see cref="TileEntityFactory"/>, binding it to a given name.
/// </summary>
/// <param name="id">The name to bind to a concrete <see cref="TileEntity"/> type.</param>
/// <param name="subtype">The <see cref="Type"/> of a concrete <see cref="TileEntity"/> type.</param>
public static void Register (string id, Type subtype)
{
_registry[id] = subtype;