NBTExplorer/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs

95 lines
2.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate.Entities
{
2011-06-30 04:41:29 +00:00
using Substrate.Nbt;
2011-08-14 19:34:49 +00:00
public class EntityMinecart : TypedEntity
{
public enum CartType
{
EMPTY = 0,
CHEST = 1,
FURNACE = 2,
}
2011-08-14 19:34:49 +00:00
public static readonly SchemaNodeCompound MinecartSchema = TypedEntity.Schema.MergeInto(new SchemaNodeCompound("")
{
new SchemaNodeString("id", "Minecart"),
new SchemaNodeScaler("Type", TagType.TAG_INT),
});
private CartType _type;
public CartType Type
{
get { return _type; }
}
public EntityMinecart ()
: base("Minecart")
{
}
2011-08-14 19:34:49 +00:00
public EntityMinecart (TypedEntity e)
: base(e)
{
EntityMinecart e2 = e as EntityMinecart;
if (e2 != null) {
_type = e2._type;
}
}
#region INBTObject<Entity> Members
2011-08-14 19:34:49 +00:00
public override TypedEntity LoadTree (TagNode tree)
{
TagNodeCompound ctree = tree as TagNodeCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_type = (CartType)ctree["Type"].ToTagInt().Data;
switch (_type) {
case CartType.EMPTY:
return this;
case CartType.CHEST:
return new EntityMinecartChest().LoadTreeSafe(tree);
case CartType.FURNACE:
return new EntityMinecartFurnace().LoadTreeSafe(tree);
default:
return this;
}
}
public override TagNode BuildTree ()
{
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
tree["Type"] = new TagNodeInt((int)_type);
return tree;
}
public override bool ValidateTree (TagNode tree)
{
2011-06-30 04:57:18 +00:00
return new NbtVerifier(tree, MinecartSchema).Verify();
}
#endregion
#region ICopyable<Entity> Members
2011-08-14 19:34:49 +00:00
public override TypedEntity Copy ()
{
return new EntityMinecart(this);
}
#endregion
}
}