2011-04-06 21:18:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2011-04-06 22:01:22 +00:00
|
|
|
|
namespace Substrate.Entities
|
2011-04-06 21:18:48 +00:00
|
|
|
|
{
|
2011-06-30 04:41:29 +00:00
|
|
|
|
using Substrate.Nbt;
|
2011-04-06 21:18:48 +00:00
|
|
|
|
|
2011-06-30 03:59:20 +00:00
|
|
|
|
public class EntityItem : EntityTyped
|
2011-04-06 21:18:48 +00:00
|
|
|
|
{
|
2011-06-30 03:59:20 +00:00
|
|
|
|
public static readonly SchemaNodeCompound ItemSchema = EntityTyped.Schema.MergeInto(new SchemaNodeCompound("")
|
2011-04-06 21:18:48 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
new SchemaNodeString("id", "Item"),
|
|
|
|
|
new SchemaNodeScaler("Health", TagType.TAG_SHORT),
|
|
|
|
|
new SchemaNodeScaler("Age", TagType.TAG_SHORT),
|
|
|
|
|
new SchemaNodeCompound("Item", Item.ItemSchema),
|
2011-04-06 21:18:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private short _health;
|
|
|
|
|
private short _age;
|
|
|
|
|
|
|
|
|
|
private Item _item;
|
|
|
|
|
|
|
|
|
|
public int Health
|
|
|
|
|
{
|
|
|
|
|
get { return _health; }
|
|
|
|
|
set { _health = (short)value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Age
|
|
|
|
|
{
|
|
|
|
|
get { return _age; }
|
|
|
|
|
set { _age = (short)value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Item Item
|
|
|
|
|
{
|
|
|
|
|
get { return _item; }
|
|
|
|
|
set { _item = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EntityItem ()
|
|
|
|
|
: base("Item")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-30 03:59:20 +00:00
|
|
|
|
public EntityItem (EntityTyped e)
|
2011-04-06 21:18:48 +00:00
|
|
|
|
: base(e)
|
|
|
|
|
{
|
|
|
|
|
EntityItem e2 = e as EntityItem;
|
|
|
|
|
if (e2 != null) {
|
|
|
|
|
_health = e2._health;
|
|
|
|
|
_age = e2._age;
|
|
|
|
|
_item = e2._item.Copy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region INBTObject<Entity> Members
|
|
|
|
|
|
2011-06-30 03:59:20 +00:00
|
|
|
|
public override EntityTyped LoadTree (TagNode tree)
|
2011-04-06 21:18:48 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound ctree = tree as TagNodeCompound;
|
2011-04-06 21:18:48 +00:00
|
|
|
|
if (ctree == null || base.LoadTree(tree) == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
_health = ctree["Health"].ToTagShort();
|
|
|
|
|
_age = ctree["Age"].ToTagShort();
|
2011-04-06 21:18:48 +00:00
|
|
|
|
|
|
|
|
|
_item = new Item().LoadTree(ctree["Item"]);
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override TagNode BuildTree ()
|
2011-04-06 21:18:48 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
|
|
|
|
tree["Health"] = new TagNodeShort(_health);
|
|
|
|
|
tree["Age"] = new TagNodeShort(_age);
|
2011-04-06 21:18:48 +00:00
|
|
|
|
tree["Item"] = _item.BuildTree();
|
|
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override bool ValidateTree (TagNode tree)
|
2011-04-06 21:18:48 +00:00
|
|
|
|
{
|
|
|
|
|
return new NBTVerifier(tree, ItemSchema).Verify();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region ICopyable<Entity> Members
|
|
|
|
|
|
2011-06-30 03:59:20 +00:00
|
|
|
|
public override EntityTyped Copy ()
|
2011-04-06 21:18:48 +00:00
|
|
|
|
{
|
|
|
|
|
return new EntityItem(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|