forked from mirrors/NBTExplorer
Additional entities. Additional compound schema constructor.
This commit is contained in:
parent
7d114a2214
commit
334ce12773
8 changed files with 524 additions and 0 deletions
46
Substrate/SubstrateCS/Source/Entities/EntityArrow.cs
Normal file
46
Substrate/SubstrateCS/Source/Entities/EntityArrow.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.Map.Entities
|
||||
{
|
||||
using Substrate.Map.NBT;
|
||||
|
||||
public class EntityArrow : EntityThrowable
|
||||
{
|
||||
public static readonly NBTCompoundNode ArrowSchema = ThrowableSchema.MergeInto(new NBTCompoundNode("")
|
||||
{
|
||||
new NBTStringNode("id", "Arrow"),
|
||||
});
|
||||
|
||||
public EntityArrow ()
|
||||
: base("Arrow")
|
||||
{
|
||||
}
|
||||
|
||||
public EntityArrow (Entity e)
|
||||
: base(e)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (NBT_Value tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ArrowSchema).Verify();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ICopyable<Entity> Members
|
||||
|
||||
public override Entity Copy ()
|
||||
{
|
||||
return new EntityArrow(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
46
Substrate/SubstrateCS/Source/Entities/EntityEgg.cs
Normal file
46
Substrate/SubstrateCS/Source/Entities/EntityEgg.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.Map.Entities
|
||||
{
|
||||
using Substrate.Map.NBT;
|
||||
|
||||
public class EntityEgg : EntityThrowable
|
||||
{
|
||||
public static readonly NBTCompoundNode EggSchema = ThrowableSchema.MergeInto(new NBTCompoundNode("")
|
||||
{
|
||||
new NBTStringNode("id", "Egg"),
|
||||
});
|
||||
|
||||
public EntityEgg ()
|
||||
: base("Egg")
|
||||
{
|
||||
}
|
||||
|
||||
public EntityEgg (Entity e)
|
||||
: base(e)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (NBT_Value tree)
|
||||
{
|
||||
return new NBTVerifier(tree, EggSchema).Verify();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ICopyable<Entity> Members
|
||||
|
||||
public override Entity Copy ()
|
||||
{
|
||||
return new EntityEgg(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
103
Substrate/SubstrateCS/Source/Entities/EntityItem.cs
Normal file
103
Substrate/SubstrateCS/Source/Entities/EntityItem.cs
Normal file
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.Map.Entities
|
||||
{
|
||||
using Substrate.Map.NBT;
|
||||
|
||||
public class EntityItem : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode ItemSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
{
|
||||
new NBTStringNode("id", "Item"),
|
||||
new NBTScalerNode("Health", NBT_Type.TAG_SHORT),
|
||||
new NBTScalerNode("Age", NBT_Type.TAG_SHORT),
|
||||
new NBTCompoundNode("Item", Item.ItemSchema),
|
||||
});
|
||||
|
||||
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")
|
||||
{
|
||||
}
|
||||
|
||||
public EntityItem (Entity e)
|
||||
: base(e)
|
||||
{
|
||||
EntityItem e2 = e as EntityItem;
|
||||
if (e2 != null) {
|
||||
_health = e2._health;
|
||||
_age = e2._age;
|
||||
_item = e2._item.Copy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (NBT_Value tree)
|
||||
{
|
||||
NBT_Compound ctree = tree as NBT_Compound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
_health = ctree["Health"].ToNBTShort();
|
||||
_age = ctree["Age"].ToNBTShort();
|
||||
|
||||
_item = new Item().LoadTree(ctree["Item"]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override NBT_Value BuildTree ()
|
||||
{
|
||||
NBT_Compound tree = base.BuildTree() as NBT_Compound;
|
||||
tree["Health"] = new NBT_Short(_health);
|
||||
tree["Age"] = new NBT_Short(_age);
|
||||
tree["Item"] = _item.BuildTree();
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (NBT_Value tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ItemSchema).Verify();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ICopyable<Entity> Members
|
||||
|
||||
public override Entity Copy ()
|
||||
{
|
||||
return new EntityItem(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
131
Substrate/SubstrateCS/Source/Entities/EntityPainting.cs
Normal file
131
Substrate/SubstrateCS/Source/Entities/EntityPainting.cs
Normal file
|
@ -0,0 +1,131 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.Map.Entities
|
||||
{
|
||||
using Substrate.Map.NBT;
|
||||
|
||||
public class EntityPainting : Entity
|
||||
{
|
||||
public enum Direction
|
||||
{
|
||||
EAST = 0,
|
||||
NORTH = 1,
|
||||
WEST = 2,
|
||||
SOUTH = 3,
|
||||
}
|
||||
|
||||
public static readonly NBTCompoundNode PaintingSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
{
|
||||
new NBTStringNode("id", "Painting"),
|
||||
new NBTScalerNode("Dir", NBT_Type.TAG_BYTE),
|
||||
new NBTScalerNode("TileX", NBT_Type.TAG_SHORT),
|
||||
new NBTScalerNode("TileY", NBT_Type.TAG_SHORT),
|
||||
new NBTScalerNode("TileZ", NBT_Type.TAG_SHORT),
|
||||
new NBTScalerNode("Motive", NBT_Type.TAG_STRING),
|
||||
});
|
||||
|
||||
private Direction _dir;
|
||||
private string _motive;
|
||||
private short _xTile;
|
||||
private short _yTile;
|
||||
private short _zTile;
|
||||
|
||||
public Direction Direction
|
||||
{
|
||||
get { return _dir; }
|
||||
set { _dir = value; }
|
||||
}
|
||||
|
||||
public string Motive
|
||||
{
|
||||
get { return _motive; }
|
||||
set { _motive = value; }
|
||||
}
|
||||
|
||||
public int TileX
|
||||
{
|
||||
get { return _xTile; }
|
||||
set { _xTile = (short)value; }
|
||||
}
|
||||
|
||||
public int TileY
|
||||
{
|
||||
get { return _yTile; }
|
||||
set { _yTile = (short)value; }
|
||||
}
|
||||
|
||||
public int TileZ
|
||||
{
|
||||
get { return _zTile; }
|
||||
set { _zTile = (short)value; }
|
||||
}
|
||||
|
||||
public EntityPainting ()
|
||||
: base("Painting")
|
||||
{
|
||||
}
|
||||
|
||||
public EntityPainting (Entity e)
|
||||
: base(e)
|
||||
{
|
||||
EntityPainting e2 = e as EntityPainting;
|
||||
if (e2 != null) {
|
||||
_xTile = e2._xTile;
|
||||
_yTile = e2._yTile;
|
||||
_zTile = e2._zTile;
|
||||
_dir = e2._dir;
|
||||
_motive = e2._motive;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (NBT_Value tree)
|
||||
{
|
||||
NBT_Compound ctree = tree as NBT_Compound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
_dir = (Direction) ctree["Dir"].ToNBTByte().Data;
|
||||
_motive = ctree["Motive"].ToNBTString();
|
||||
_xTile = ctree["TileX"].ToNBTShort();
|
||||
_yTile = ctree["TileY"].ToNBTShort();
|
||||
_zTile = ctree["TileZ"].ToNBTShort();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override NBT_Value BuildTree ()
|
||||
{
|
||||
NBT_Compound tree = base.BuildTree() as NBT_Compound;
|
||||
tree["Dir"] = new NBT_Byte((byte)_dir);
|
||||
tree["Motive"] = new NBT_String(_motive);
|
||||
tree["TileX"] = new NBT_Short(_xTile);
|
||||
tree["TileY"] = new NBT_Short(_yTile);
|
||||
tree["TileZ"] = new NBT_Short(_zTile);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (NBT_Value tree)
|
||||
{
|
||||
return new NBTVerifier(tree, PaintingSchema).Verify();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ICopyable<Entity> Members
|
||||
|
||||
public override Entity Copy ()
|
||||
{
|
||||
return new EntityPainting(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
46
Substrate/SubstrateCS/Source/Entities/EntitySnowball.cs
Normal file
46
Substrate/SubstrateCS/Source/Entities/EntitySnowball.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.Map.Entities
|
||||
{
|
||||
using Substrate.Map.NBT;
|
||||
|
||||
public class EntitySnowball : EntityThrowable
|
||||
{
|
||||
public static readonly NBTCompoundNode SnowballSchema = ThrowableSchema.MergeInto(new NBTCompoundNode("")
|
||||
{
|
||||
new NBTStringNode("id", "Snowball"),
|
||||
});
|
||||
|
||||
public EntitySnowball ()
|
||||
: base("Snowball")
|
||||
{
|
||||
}
|
||||
|
||||
public EntitySnowball (Entity e)
|
||||
: base(e)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (NBT_Value tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SnowballSchema).Verify();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ICopyable<Entity> Members
|
||||
|
||||
public override Entity Copy ()
|
||||
{
|
||||
return new EntitySnowball(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
133
Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs
Normal file
133
Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs
Normal file
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.Map.Entities
|
||||
{
|
||||
using Substrate.Map.NBT;
|
||||
|
||||
public class EntityThrowable : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode ThrowableSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
{
|
||||
new NBTScalerNode("xTile", NBT_Type.TAG_SHORT),
|
||||
new NBTScalerNode("yTile", NBT_Type.TAG_SHORT),
|
||||
new NBTScalerNode("zTile", NBT_Type.TAG_SHORT),
|
||||
new NBTScalerNode("inTile", NBT_Type.TAG_BYTE),
|
||||
new NBTScalerNode("shake", NBT_Type.TAG_BYTE),
|
||||
new NBTScalerNode("inGround", NBT_Type.TAG_BYTE),
|
||||
});
|
||||
|
||||
private short _xTile;
|
||||
private short _yTile;
|
||||
private short _zTile;
|
||||
private byte _inTile;
|
||||
private byte _shake;
|
||||
private byte _inGround;
|
||||
|
||||
public int XTile
|
||||
{
|
||||
get { return _xTile; }
|
||||
set { _xTile = (short)value; }
|
||||
}
|
||||
|
||||
public int YTile
|
||||
{
|
||||
get { return _yTile; }
|
||||
set { _yTile = (short)value; }
|
||||
}
|
||||
|
||||
public int ZTile
|
||||
{
|
||||
get { return _zTile; }
|
||||
set { _zTile = (short)value; }
|
||||
}
|
||||
|
||||
public bool IsInTile
|
||||
{
|
||||
get { return _inTile == 1; }
|
||||
set { _inTile = (byte)(value ? 1 : 0); }
|
||||
}
|
||||
|
||||
public int Shake
|
||||
{
|
||||
get { return _shake; }
|
||||
set { _shake = (byte)value; }
|
||||
}
|
||||
|
||||
public bool IsInGround
|
||||
{
|
||||
get { return _inGround == 1; }
|
||||
set { _inGround = (byte)(value ? 1 : 0); }
|
||||
}
|
||||
|
||||
public EntityThrowable (string id)
|
||||
: base(id)
|
||||
{
|
||||
}
|
||||
|
||||
public EntityThrowable (Entity e)
|
||||
: base(e)
|
||||
{
|
||||
EntityThrowable e2 = e as EntityThrowable;
|
||||
if (e2 != null) {
|
||||
_xTile = e2._xTile;
|
||||
_yTile = e2._yTile;
|
||||
_zTile = e2._zTile;
|
||||
_inTile = e2._inTile;
|
||||
_inGround = e2._inGround;
|
||||
_shake = e2._shake;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (NBT_Value tree)
|
||||
{
|
||||
NBT_Compound ctree = tree as NBT_Compound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
_xTile = ctree["xTile"].ToNBTShort();
|
||||
_yTile = ctree["yTile"].ToNBTShort();
|
||||
_zTile = ctree["zTile"].ToNBTShort();
|
||||
_inTile = ctree["inTile"].ToNBTByte();
|
||||
_shake = ctree["shake"].ToNBTByte();
|
||||
_inGround = ctree["inGround"].ToNBTByte();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override NBT_Value BuildTree ()
|
||||
{
|
||||
NBT_Compound tree = base.BuildTree() as NBT_Compound;
|
||||
tree["xTile"] = new NBT_Short(_xTile);
|
||||
tree["yTile"] = new NBT_Short(_yTile);
|
||||
tree["zTile"] = new NBT_Short(_zTile);
|
||||
tree["inTile"] = new NBT_Byte(_inTile);
|
||||
tree["shake"] = new NBT_Byte(_shake);
|
||||
tree["inGround"] = new NBT_Byte(_inGround);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (NBT_Value tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ThrowableSchema).Verify();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ICopyable<Entity> Members
|
||||
|
||||
public override Entity Copy ()
|
||||
{
|
||||
return new EntityThrowable(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -54,18 +54,23 @@ namespace Substrate.Map
|
|||
{
|
||||
_registry = new Dictionary<string, Type>();
|
||||
|
||||
_registry["Arrow"] = typeof(EntityArrow);
|
||||
_registry["Chicken"] = typeof(EntityChicken);
|
||||
_registry["Cow"] = typeof(EntityCow);
|
||||
_registry["Creeper"] = typeof(EntityCreeper);
|
||||
_registry["Egg"] = typeof(EntityEgg);
|
||||
_registry["Ghast"] = typeof(EntityGhast);
|
||||
_registry["Giant"] = typeof(EntityGiant);
|
||||
_registry["Item"] = typeof(EntityItem);
|
||||
_registry["Mob"] = typeof(EntityMob);
|
||||
_registry["Monster"] = typeof(EntityMonster);
|
||||
_registry["Painting"] = typeof(EntityPainting);
|
||||
_registry["Pig"] = typeof(EntityPig);
|
||||
_registry["PigZombie"] = typeof(EntityPigZombie);
|
||||
_registry["Sheep"] = typeof(EntitySheep);
|
||||
_registry["Skeleton"] = typeof(EntitySkeleton);
|
||||
_registry["Slime"] = typeof(EntitySlime);
|
||||
_registry["Snowball"] = typeof(EntitySnowball);
|
||||
_registry["Spider"] = typeof(EntitySpider);
|
||||
_registry["Wolf"] = typeof(EntityWolf);
|
||||
_registry["Zombie"] = typeof(EntityZombie);
|
||||
|
|
|
@ -269,6 +269,20 @@ namespace Substrate.Map.NBT
|
|||
_subnodes = new List<NBTSchemaNode>();
|
||||
}
|
||||
|
||||
public NBTCompoundNode (string name, NBTSchemaNode subschema)
|
||||
: base(name)
|
||||
{
|
||||
NBTCompoundNode schema = subschema as NBTCompoundNode;
|
||||
if (schema == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (NBTSchemaNode node in schema._subnodes)
|
||||
{
|
||||
_subnodes.Add(node);
|
||||
}
|
||||
}
|
||||
|
||||
public NBTCompoundNode MergeInto (NBTCompoundNode tree)
|
||||
{
|
||||
foreach (NBTSchemaNode node in _subnodes) {
|
||||
|
|
Loading…
Reference in a new issue