2011-04-06 22:01:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Substrate.Entities
|
|
|
|
|
{
|
|
|
|
|
using Substrate.NBT;
|
|
|
|
|
|
|
|
|
|
public class EntityMinecart : Entity
|
|
|
|
|
{
|
|
|
|
|
public enum CartType
|
|
|
|
|
{
|
|
|
|
|
EMPTY = 0,
|
|
|
|
|
CHEST = 1,
|
|
|
|
|
FURNACE = 2,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly NBTCompoundNode MinecartSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
|
|
|
|
{
|
|
|
|
|
new NBTStringNode("id", "Minecart"),
|
2011-04-09 02:50:42 +00:00
|
|
|
|
new NBTScalerNode("Type", TagType.TAG_BYTE),
|
2011-04-06 22:01:22 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private CartType _type;
|
|
|
|
|
|
|
|
|
|
public CartType Type
|
|
|
|
|
{
|
|
|
|
|
get { return _type; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EntityMinecart ()
|
|
|
|
|
: base("Minecart")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EntityMinecart (Entity e)
|
|
|
|
|
: base(e)
|
|
|
|
|
{
|
|
|
|
|
EntityMinecart e2 = e as EntityMinecart;
|
|
|
|
|
if (e2 != null) {
|
|
|
|
|
_type = e2._type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region INBTObject<Entity> Members
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override Entity LoadTree (TagValue tree)
|
2011-04-06 22:01:22 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
TagCompound ctree = tree as TagCompound;
|
2011-04-06 22:01:22 +00:00
|
|
|
|
if (ctree == null || base.LoadTree(tree) == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
_type = (CartType)ctree["Type"].ToTagByte().Data;
|
2011-04-06 22:01:22 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue BuildTree ()
|
2011-04-06 22:01:22 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
TagCompound tree = base.BuildTree() as TagCompound;
|
|
|
|
|
tree["Type"] = new TagByte((byte)_type);
|
2011-04-06 22:01:22 +00:00
|
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override bool ValidateTree (TagValue tree)
|
2011-04-06 22:01:22 +00:00
|
|
|
|
{
|
|
|
|
|
return new NBTVerifier(tree, MinecartSchema).Verify();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region ICopyable<Entity> Members
|
|
|
|
|
|
|
|
|
|
public override Entity Copy ()
|
|
|
|
|
{
|
|
|
|
|
return new EntityMinecart(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|