2011-04-06 19:41:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2011-04-06 21:20:35 +00:00
|
|
|
|
namespace Substrate.TileEntities
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-04-06 21:20:35 +00:00
|
|
|
|
using Substrate.NBT;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
|
|
|
|
|
public class TileEntityTrap : TileEntity, IItemContainer
|
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public static readonly SchemaNodeCompound TrapSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
new SchemaNodeString("id", "Trap"),
|
|
|
|
|
new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
2011-04-06 19:41:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private const int _CAPACITY = 8;
|
|
|
|
|
|
|
|
|
|
private ItemCollection _items;
|
|
|
|
|
|
|
|
|
|
public TileEntityTrap ()
|
|
|
|
|
: base("Trap")
|
|
|
|
|
{
|
|
|
|
|
_items = new ItemCollection(_CAPACITY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TileEntityTrap (TileEntity te)
|
|
|
|
|
: base(te)
|
|
|
|
|
{
|
|
|
|
|
TileEntityTrap tec = te as TileEntityTrap;
|
|
|
|
|
if (tec != null) {
|
|
|
|
|
_items = tec._items.Copy();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_items = new ItemCollection(_CAPACITY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region ICopyable<TileEntity> Members
|
|
|
|
|
|
|
|
|
|
public override TileEntity Copy ()
|
|
|
|
|
{
|
|
|
|
|
return new TileEntityTrap(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region IItemContainer Members
|
|
|
|
|
|
|
|
|
|
public ItemCollection Items
|
|
|
|
|
{
|
|
|
|
|
get { return _items; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region INBTObject<TileEntity> Members
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override TileEntity LoadTree (TagNode tree)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound ctree = tree as TagNodeCompound;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
if (ctree == null || base.LoadTree(tree) == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeList items = ctree["Items"].ToTagList();
|
2011-04-06 19:41:57 +00:00
|
|
|
|
_items = new ItemCollection(_CAPACITY).LoadTree(items);
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override TagNode BuildTree ()
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
tree["Items"] = _items.BuildTree();
|
|
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override bool ValidateTree (TagNode tree)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
|
|
|
|
return new NBTVerifier(tree, TrapSchema).Verify();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|