diff --git a/Substrate/SubstrateCS/Source/Entities/EntityChicken.cs b/Substrate/SubstrateCS/Source/Entities/EntityChicken.cs new file mode 100644 index 0000000..13c7f65 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityChicken.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityChicken : EntityMob + { + public static readonly NBTCompoundNode ChickenSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Chicken"), + }); + + public EntityChicken () + : base("Chicken") + { + } + + public EntityChicken (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, ChickenSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityChicken(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityCow.cs b/Substrate/SubstrateCS/Source/Entities/EntityCow.cs new file mode 100644 index 0000000..de09529 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityCow.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityCow : EntityMob + { + public static readonly NBTCompoundNode CowSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Cow"), + }); + + public EntityCow () + : base("Cow") + { + } + + public EntityCow (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, CowSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityCow(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityCreeper.cs b/Substrate/SubstrateCS/Source/Entities/EntityCreeper.cs new file mode 100644 index 0000000..3022046 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityCreeper.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityCreeper : EntityMob + { + public static readonly NBTCompoundNode CreeperSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Creeper"), + }); + + public EntityCreeper () + : base("Creeper") + { + } + + public EntityCreeper (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, CreeperSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityCreeper(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityGhast.cs b/Substrate/SubstrateCS/Source/Entities/EntityGhast.cs new file mode 100644 index 0000000..61375ed --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityGhast.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityGhast : EntityMob + { + public static readonly NBTCompoundNode GhastSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Ghast"), + }); + + public EntityGhast () + : base("Ghast") + { + } + + public EntityGhast (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, GhastSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityGhast(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityGiant.cs b/Substrate/SubstrateCS/Source/Entities/EntityGiant.cs new file mode 100644 index 0000000..b2c9aa2 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityGiant.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityGiant : EntityMob + { + public static readonly NBTCompoundNode GiantSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Giant"), + }); + + public EntityGiant () + : base("Giant") + { + } + + public EntityGiant (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, GiantSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityGiant(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMob.cs b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs new file mode 100644 index 0000000..8319c5a --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityMob : Entity + { + public static readonly NBTCompoundNode MobSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Mob"), + new NBTScalerNode("AttackTime", NBT_Type.TAG_SHORT), + new NBTScalerNode("DeathTime", NBT_Type.TAG_SHORT), + new NBTScalerNode("Health", NBT_Type.TAG_SHORT), + new NBTScalerNode("HurtTime", NBT_Type.TAG_SHORT), + }); + + private short _attackTime; + private short _deathTime; + private short _health; + private short _hurtTime; + + public int AttackTime + { + get { return _attackTime; } + set { _attackTime = (short)value; } + } + + public int DeathTime + { + get { return _deathTime; } + set { _deathTime = (short)value; } + } + + public int Health + { + get { return _health; } + set { _health = (short)value; } + } + + public int HurtTime + { + get { return _hurtTime; } + set { _hurtTime = (short)value; } + } + + public EntityMob () + : base("Mob") + { + } + + public EntityMob (string id) + : base(id) + { + } + + public EntityMob (Entity e) + : base(e) + { + EntityMob e2 = e as EntityMob; + if (e2 != null) { + _attackTime = e2._attackTime; + _deathTime = e2._deathTime; + _health = e2._health; + _hurtTime = e2._hurtTime; + } + } + + + #region INBTObject Members + + public override Entity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _attackTime = ctree["AttackTime"].ToNBTShort(); + _deathTime = ctree["DeathTime"].ToNBTShort(); + _health = ctree["Health"].ToNBTShort(); + _hurtTime = ctree["HurtTime"].ToNBTShort(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["AttackTime"] = new NBT_Short(_attackTime); + tree["DeathTime"] = new NBT_Short(_deathTime); + tree["Health"] = new NBT_Short(_health); + tree["HurtTime"] = new NBT_Short(_hurtTime); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, MobSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityMob(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMonster.cs b/Substrate/SubstrateCS/Source/Entities/EntityMonster.cs new file mode 100644 index 0000000..6193c97 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityMonster.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityMonster : EntityMob + { + public static readonly NBTCompoundNode MonsterSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Monster"), + }); + + public EntityMonster () + : base("Monster") + { + } + + public EntityMonster (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, MonsterSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityMonster(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPig.cs b/Substrate/SubstrateCS/Source/Entities/EntityPig.cs new file mode 100644 index 0000000..9443f2b --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityPig.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityPig : EntityMob + { + public static readonly NBTCompoundNode PigSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Pig"), + new NBTScalerNode("Saddle", NBT_Type.TAG_BYTE), + }); + + private bool _saddle; + + public bool HasSaddle + { + get { return _saddle; } + set { _saddle = value; } + } + + public EntityPig () + : base("Pig") + { + } + + public EntityPig (Entity e) + : base(e) + { + EntityPig e2 = e as EntityPig; + if (e2 != null) { + _saddle = e2._saddle; + } + } + + + #region INBTObject Members + + public override Entity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _saddle = ctree["Saddle"].ToNBTByte() == 1; + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Saddle"] = new NBT_Byte((byte)(_saddle ? 1 : 0)); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, PigSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityPig(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPigZombie.cs b/Substrate/SubstrateCS/Source/Entities/EntityPigZombie.cs new file mode 100644 index 0000000..9f5f737 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityPigZombie.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityPigZombie : EntityMob + { + public static readonly NBTCompoundNode PigZombieSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "PigZombie"), + }); + + public EntityPigZombie () + : base("PigZombie") + { + } + + public EntityPigZombie (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, PigZombieSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityPigZombie(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySheep.cs b/Substrate/SubstrateCS/Source/Entities/EntitySheep.cs new file mode 100644 index 0000000..1da9cfa --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntitySheep.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntitySheep : EntityMob + { + public static readonly NBTCompoundNode SheepSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Pig"), + new NBTScalerNode("Sheared", NBT_Type.TAG_BYTE), + new NBTScalerNode("Color", NBT_Type.TAG_BYTE), + }); + + private bool _sheared; + private byte _color; + + public bool IsSheared + { + get { return _sheared; } + set { _sheared = value; } + } + + public int Color + { + get { return _color; } + set { _color = (byte)value; } + } + + public EntitySheep () + : base("Sheep") + { + } + + public EntitySheep (Entity e) + : base(e) + { + EntitySheep e2 = e as EntitySheep; + if (e2 != null) { + _sheared = e2._sheared; + _color = e2._color; + } + } + + + #region INBTObject Members + + public override Entity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _sheared = ctree["Sheared"].ToNBTByte() == 1; + _color = ctree["Color"].ToNBTByte(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Sheared"] = new NBT_Byte((byte)(_sheared ? 1 : 0)); + tree["Color"] = new NBT_Byte(_color); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, SheepSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntitySheep(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySkeleton.cs b/Substrate/SubstrateCS/Source/Entities/EntitySkeleton.cs new file mode 100644 index 0000000..9b6078b --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntitySkeleton.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntitySkeleton : EntityMob + { + public static readonly NBTCompoundNode SkeletonSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Skeleton"), + }); + + public EntitySkeleton () + : base("Skeleton") + { + } + + public EntitySkeleton (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, SkeletonSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntitySkeleton(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySlime.cs b/Substrate/SubstrateCS/Source/Entities/EntitySlime.cs new file mode 100644 index 0000000..4b10d3d --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntitySlime.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntitySlime : EntityMob + { + public static readonly NBTCompoundNode SlimeSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Slime"), + new NBTScalerNode("Size", NBT_Type.TAG_INT), + }); + + private int _size; + + public int Size + { + get { return _size; } + set { _size = value; } + } + + public EntitySlime () + : base("Slime") + { + } + + public EntitySlime (Entity e) + : base(e) + { + EntitySlime e2 = e as EntitySlime; + if (e2 != null) { + _size = e2._size; + } + } + + + #region INBTObject Members + + public override Entity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _size = ctree["Size"].ToNBTInt(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Size"] = new NBT_Int(_size); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, SlimeSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntitySlime(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySpider.cs b/Substrate/SubstrateCS/Source/Entities/EntitySpider.cs new file mode 100644 index 0000000..20e04ad --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntitySpider.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntitySpider : EntityMob + { + public static readonly NBTCompoundNode SpiderSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Spider"), + }); + + public EntitySpider () + : base("Spider") + { + } + + public EntitySpider (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, SpiderSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntitySpider(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityWolf.cs b/Substrate/SubstrateCS/Source/Entities/EntityWolf.cs new file mode 100644 index 0000000..780773b --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityWolf.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityWolf : EntityMob + { + public static readonly NBTCompoundNode WolfSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Wolf"), + new NBTScalerNode("Owner", NBT_Type.TAG_STRING), + new NBTScalerNode("Sitting", NBT_Type.TAG_BYTE), + new NBTScalerNode("Angry", NBT_Type.TAG_BYTE), + }); + + private string _owner; + private bool _sitting; + private bool _angry; + + public string Owner + { + get { return _owner; } + set { _owner = value; } + } + + public bool IsSitting + { + get { return _sitting; } + set { _sitting = value; } + } + + public bool IsAngry + { + get { return _angry; } + set { _angry = value; } + } + + public EntityWolf () + : base("Wolf") + { + } + + public EntityWolf (Entity e) + : base(e) + { + EntityWolf e2 = e as EntityWolf; + if (e2 != null) { + _owner = e2._owner; + _sitting = e2._sitting; + _angry = e2._angry; + } + } + + + #region INBTObject Members + + public override Entity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _owner = ctree["Owner"].ToNBTString(); + _sitting = ctree["Sitting"].ToNBTByte() == 1; + _angry = ctree["Angry"].ToNBTByte() == 1; + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Owner"] = new NBT_String(_owner); + tree["Sitting"] = new NBT_Byte((byte)(_sitting ? 1 : 0)); + tree["Angry"] = new NBT_Byte((byte)(_angry ? 1 : 0)); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, WolfSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityPig(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityZombie.cs b/Substrate/SubstrateCS/Source/Entities/EntityZombie.cs new file mode 100644 index 0000000..8884a80 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityZombie.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.Entities +{ + using Substrate.Map.NBT; + + public class EntityZombie : EntityMob + { + public static readonly NBTCompoundNode ZombieSchema = MobSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Zombie"), + }); + + public EntityZombie () + : base("Zombie") + { + } + + public EntityZombie (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, ZombieSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityZombie(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entity.cs b/Substrate/SubstrateCS/Source/Entity.cs index 7ee19fc..1adddae 100644 --- a/Substrate/SubstrateCS/Source/Entity.cs +++ b/Substrate/SubstrateCS/Source/Entity.cs @@ -227,809 +227,4 @@ namespace Substrate.Map #endregion } - public class EntityMob : Entity - { - public static readonly NBTCompoundNode MobSchema = BaseSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Mob"), - new NBTScalerNode("AttackTime", NBT_Type.TAG_SHORT), - new NBTScalerNode("DeathTime", NBT_Type.TAG_SHORT), - new NBTScalerNode("Health", NBT_Type.TAG_SHORT), - new NBTScalerNode("HurtTime", NBT_Type.TAG_SHORT), - }); - - private short _attackTime; - private short _deathTime; - private short _health; - private short _hurtTime; - - public int AttackTime - { - get { return _attackTime; } - set { _attackTime = (short)value; } - } - - public int DeathTime - { - get { return _deathTime; } - set { _deathTime = (short)value; } - } - - public int Health - { - get { return _health; } - set { _health = (short)value; } - } - - public int HurtTime - { - get { return _hurtTime; } - set { _hurtTime = (short)value; } - } - - public EntityMob () - : base("Mob") - { - } - - public EntityMob (string id) - : base(id) - { - } - - public EntityMob (Entity e) - : base(e) - { - EntityMob e2 = e as EntityMob; - if (e2 != null) { - _attackTime = e2._attackTime; - _deathTime = e2._deathTime; - _health = e2._health; - _hurtTime = e2._hurtTime; - } - } - - - #region INBTObject Members - - public override Entity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _attackTime = ctree["AttackTime"].ToNBTShort(); - _deathTime = ctree["DeathTime"].ToNBTShort(); - _health = ctree["Health"].ToNBTShort(); - _hurtTime = ctree["HurtTime"].ToNBTShort(); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["AttackTime"] = new NBT_Short(_attackTime); - tree["DeathTime"] = new NBT_Short(_deathTime); - tree["Health"] = new NBT_Short(_health); - tree["HurtTime"] = new NBT_Short(_hurtTime); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, MobSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityMob(this); - } - - #endregion - } - - public class EntityMonster : EntityMob - { - public static readonly NBTCompoundNode MonsterSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Monster"), - }); - - public EntityMonster () - : base("Monster") - { - } - - public EntityMonster (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, MonsterSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityMonster(this); - } - - #endregion - } - - public class EntityCreeper : EntityMob - { - public static readonly NBTCompoundNode CreeperSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Creeper"), - }); - - public EntityCreeper () - : base("Creeper") - { - } - - public EntityCreeper (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, CreeperSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityCreeper(this); - } - - #endregion - } - - public class EntitySkeleton : EntityMob - { - public static readonly NBTCompoundNode SkeletonSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Skeleton"), - }); - - public EntitySkeleton () - : base("Skeleton") - { - } - - public EntitySkeleton (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, SkeletonSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntitySkeleton(this); - } - - #endregion - } - - public class EntitySpider : EntityMob - { - public static readonly NBTCompoundNode SpiderSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Spider"), - }); - - public EntitySpider () - : base("Spider") - { - } - - public EntitySpider (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, SpiderSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntitySpider(this); - } - - #endregion - } - - public class EntityGiant : EntityMob - { - public static readonly NBTCompoundNode GiantSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Giant"), - }); - - public EntityGiant () - : base("Giant") - { - } - - public EntityGiant (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, GiantSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityGiant(this); - } - - #endregion - } - - public class EntityZombie : EntityMob - { - public static readonly NBTCompoundNode ZombieSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Zombie"), - }); - - public EntityZombie () - : base("Zombie") - { - } - - public EntityZombie (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, ZombieSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityZombie(this); - } - - #endregion - } - - public class EntitySlime : EntityMob - { - public static readonly NBTCompoundNode SlimeSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Slime"), - new NBTScalerNode("Size", NBT_Type.TAG_INT), - }); - - private int _size; - - public int Size - { - get { return _size; } - set { _size = value; } - } - - public EntitySlime () - : base("Slime") - { - } - - public EntitySlime (Entity e) - : base(e) - { - EntitySlime e2 = e as EntitySlime; - if (e2 != null) { - _size = e2._size; - } - } - - - #region INBTObject Members - - public override Entity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _size = ctree["Size"].ToNBTInt(); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Size"] = new NBT_Int(_size); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, SlimeSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntitySlime(this); - } - - #endregion - } - - public class EntityPigZombie : EntityMob - { - public static readonly NBTCompoundNode PigZombieSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "PigZombie"), - }); - - public EntityPigZombie () - : base("PigZombie") - { - } - - public EntityPigZombie (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, PigZombieSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityPigZombie(this); - } - - #endregion - } - - public class EntityGhast : EntityMob - { - public static readonly NBTCompoundNode GhastSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Ghast"), - }); - - public EntityGhast () - : base("Ghast") - { - } - - public EntityGhast (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, GhastSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityGhast(this); - } - - #endregion - } - - public class EntityPig : EntityMob - { - public static readonly NBTCompoundNode PigSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Pig"), - new NBTScalerNode("Saddle", NBT_Type.TAG_BYTE), - }); - - private bool _saddle; - - public bool HasSaddle - { - get { return _saddle; } - set { _saddle = value; } - } - - public EntityPig () - : base("Pig") - { - } - - public EntityPig (Entity e) - : base(e) - { - EntityPig e2 = e as EntityPig; - if (e2 != null) { - _saddle = e2._saddle; - } - } - - - #region INBTObject Members - - public override Entity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _saddle = ctree["Saddle"].ToNBTByte() == 1; - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Saddle"] = new NBT_Byte((byte)(_saddle ? 1 : 0)); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, PigSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityPig(this); - } - - #endregion - } - - public class EntitySheep : EntityMob - { - public static readonly NBTCompoundNode SheepSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Pig"), - new NBTScalerNode("Sheared", NBT_Type.TAG_BYTE), - new NBTScalerNode("Color", NBT_Type.TAG_BYTE), - }); - - private bool _sheared; - private byte _color; - - public bool IsSheared - { - get { return _sheared; } - set { _sheared = value; } - } - - public int Color - { - get { return _color; } - set { _color = (byte)value; } - } - - public EntitySheep () - : base("Sheep") - { - } - - public EntitySheep (Entity e) - : base(e) - { - EntitySheep e2 = e as EntitySheep; - if (e2 != null) { - _sheared = e2._sheared; - _color = e2._color; - } - } - - - #region INBTObject Members - - public override Entity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _sheared = ctree["Sheared"].ToNBTByte() == 1; - _color = ctree["Color"].ToNBTByte(); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Sheared"] = new NBT_Byte((byte)(_sheared ? 1 : 0)); - tree["Color"] = new NBT_Byte(_color); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, SheepSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntitySheep(this); - } - - #endregion - } - - public class EntityCow : EntityMob - { - public static readonly NBTCompoundNode CowSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Cow"), - }); - - public EntityCow () - : base("Cow") - { - } - - public EntityCow (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, CowSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityCow(this); - } - - #endregion - } - - public class EntityChicken : EntityMob - { - public static readonly NBTCompoundNode ChickenSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Chicken"), - }); - - public EntityChicken () - : base("Chicken") - { - } - - public EntityChicken (Entity e) - : base(e) - { - } - - - #region INBTObject Members - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, ChickenSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityChicken(this); - } - - #endregion - } - - public class EntityWolf : EntityMob - { - public static readonly NBTCompoundNode WolfSchema = MobSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Wolf"), - new NBTScalerNode("Owner", NBT_Type.TAG_STRING), - new NBTScalerNode("Sitting", NBT_Type.TAG_BYTE), - new NBTScalerNode("Angry", NBT_Type.TAG_BYTE), - }); - - private string _owner; - private bool _sitting; - private bool _angry; - - public string Owner - { - get { return _owner; } - set { _owner = value; } - } - - public bool IsSitting - { - get { return _sitting; } - set { _sitting = value; } - } - - public bool IsAngry - { - get { return _angry; } - set { _angry = value; } - } - - public EntityWolf () - : base("Wolf") - { - } - - public EntityWolf (Entity e) - : base(e) - { - EntityWolf e2 = e as EntityWolf; - if (e2 != null) { - _owner = e2._owner; - _sitting = e2._sitting; - _angry = e2._angry; - } - } - - - #region INBTObject Members - - public override Entity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _owner = ctree["Owner"].ToNBTString(); - _sitting = ctree["Sitting"].ToNBTByte() == 1; - _angry = ctree["Angry"].ToNBTByte() == 1; - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Owner"] = new NBT_String(_owner); - tree["Sitting"] = new NBT_Byte((byte)(_sitting ? 1 : 0)); - tree["Angry"] = new NBT_Byte((byte)(_angry ? 1 : 0)); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, WolfSchema).Verify(); - } - - #endregion - - - #region ICopyable Members - - public override Entity Copy () - { - return new EntityPig(this); - } - - #endregion - } } \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/EntityFactory.cs b/Substrate/SubstrateCS/Source/EntityFactory.cs index 848dd4b..47cc52c 100644 --- a/Substrate/SubstrateCS/Source/EntityFactory.cs +++ b/Substrate/SubstrateCS/Source/EntityFactory.cs @@ -5,6 +5,7 @@ using System.Text; namespace Substrate.Map { using NBT; + using Entities; public class EntityFactory { diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityChest.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityChest.cs new file mode 100644 index 0000000..f4a450f --- /dev/null +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityChest.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.TileEntities +{ + using Substrate.Map.NBT; + + public class TileEntityChest : TileEntity, IItemContainer + { + public static readonly NBTCompoundNode ChestSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Chest"), + new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema), + }); + + private const int _CAPACITY = 27; + + private ItemCollection _items; + + public TileEntityChest () + : base("Chest") + { + _items = new ItemCollection(_CAPACITY); + } + + public TileEntityChest (TileEntity te) + : base(te) + { + TileEntityChest tec = te as TileEntityChest; + if (tec != null) { + _items = tec._items.Copy(); + } + else { + _items = new ItemCollection(_CAPACITY); + } + } + + #region ICopyable Members + + public override TileEntity Copy () + { + return new TileEntityChest(this); + } + + #endregion + + + #region IItemContainer Members + + public ItemCollection Items + { + get { return _items; } + } + + #endregion + + + #region INBTObject Members + + public override TileEntity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + NBT_List items = ctree["Items"].ToNBTList(); + _items = new ItemCollection(_CAPACITY).LoadTree(items); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Items"] = _items.BuildTree(); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, ChestSchema).Verify(); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs new file mode 100644 index 0000000..f55c14a --- /dev/null +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.TileEntities +{ + using Substrate.Map.NBT; + + public class TileEntityFurnace : TileEntity, IItemContainer + { + public static readonly NBTCompoundNode FurnaceSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Furnace"), + new NBTScalerNode("BurnTime", NBT_Type.TAG_SHORT), + new NBTScalerNode("CookTime", NBT_Type.TAG_SHORT), + new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema), + }); + + private const int _CAPACITY = 3; + + private short _burnTime; + private short _cookTime; + + private ItemCollection _items; + + public int BurnTime + { + get { return _burnTime; } + set { _burnTime = (short)value; } + } + + public int CookTime + { + get { return _cookTime; } + set { _cookTime = (short)value; } + } + + public TileEntityFurnace () + : base("Furnace") + { + _items = new ItemCollection(_CAPACITY); + } + + public TileEntityFurnace (TileEntity te) + : base(te) + { + TileEntityFurnace tec = te as TileEntityFurnace; + if (tec != null) { + _cookTime = tec._cookTime; + _burnTime = tec._burnTime; + _items = tec._items.Copy(); + } + else { + _items = new ItemCollection(_CAPACITY); + } + } + + + #region ICopyable Members + + public override TileEntity Copy () + { + return new TileEntityFurnace(this); + } + + #endregion + + + #region IItemContainer Members + + public ItemCollection Items + { + get { return _items; } + } + + #endregion + + + #region INBTObject Members + + public override TileEntity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _burnTime = ctree["BurnTime"].ToNBTShort(); + _cookTime = ctree["CookTime"].ToNBTShort(); + + NBT_List items = ctree["Items"].ToNBTList(); + _items = new ItemCollection(_CAPACITY).LoadTree(items); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["BurnTime"] = new NBT_Short(_burnTime); + tree["CookTime"] = new NBT_Short(_cookTime); + tree["Items"] = _items.BuildTree(); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, FurnaceSchema).Verify(); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs new file mode 100644 index 0000000..18ccb4f --- /dev/null +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.TileEntities +{ + using Substrate.Map.NBT; + + public class TileEntityMobSpawner : TileEntity + { + public static readonly NBTCompoundNode MobSpawnerSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "MobSpawner"), + new NBTScalerNode("EntityId", NBT_Type.TAG_STRING), + new NBTScalerNode("Delay", NBT_Type.TAG_SHORT), + }); + + private short _delay; + private string _entityID; + + public int Delay + { + get { return _delay; } + set { _delay = (short)value; } + } + + public string EntityID + { + get { return _entityID; } + set { _entityID = value; } + } + + public TileEntityMobSpawner () + : base("MobSpawner") + { + } + + public TileEntityMobSpawner (TileEntity te) + : base(te) + { + TileEntityMobSpawner tes = te as TileEntityMobSpawner; + if (tes != null) { + _delay = tes._delay; + _entityID = tes._entityID; + } + } + + + #region ICopyable Members + + public override TileEntity Copy () + { + return new TileEntityMobSpawner(this); + } + + #endregion + + + #region INBTObject Members + + public override TileEntity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _delay = ctree["Delay"].ToNBTShort(); + _entityID = ctree["EntityID"].ToNBTString(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["EntityID"] = new NBT_String(_entityID); + tree["Delay"] = new NBT_Short(_delay); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, MobSpawnerSchema).Verify(); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityMusic.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMusic.cs new file mode 100644 index 0000000..f6c5b6a --- /dev/null +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMusic.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.TileEntities +{ + using Substrate.Map.NBT; + + public class TileEntityMusic : TileEntity + { + public static readonly NBTCompoundNode MusicSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Music"), + new NBTScalerNode("note", NBT_Type.TAG_BYTE), + }); + + private byte _note; + + public int Note + { + get { return _note; } + set { _note = (byte)value; } + } + + public TileEntityMusic () + : base("Music") + { + } + + public TileEntityMusic (TileEntity te) + : base(te) + { + TileEntityMusic tes = te as TileEntityMusic; + if (tes != null) { + _note = tes._note; + } + } + + + #region ICopyable Members + + public override TileEntity Copy () + { + return new TileEntityMusic(this); + } + + #endregion + + + #region INBTObject Members + + public override TileEntity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _note = ctree["Note"].ToNBTByte(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Note"] = new NBT_Byte(_note); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, MusicSchema).Verify(); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntitySign.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntitySign.cs new file mode 100644 index 0000000..0ad892c --- /dev/null +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntitySign.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.TileEntities +{ + using Substrate.Map.NBT; + + public class TileEntitySign : TileEntity + { + public static readonly NBTCompoundNode SignSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Sign"), + new NBTScalerNode("Text1", NBT_Type.TAG_STRING), + new NBTScalerNode("Text2", NBT_Type.TAG_STRING), + new NBTScalerNode("Text3", NBT_Type.TAG_STRING), + new NBTScalerNode("Text4", NBT_Type.TAG_STRING), + }); + + private string _text1 = ""; + private string _text2 = ""; + private string _text3 = ""; + private string _text4 = ""; + + public string Text1 + { + get { return _text1; } + set { _text1 = value.Substring(0, 12); } + } + + public string Text2 + { + get { return _text2; } + set { _text2 = value.Substring(0, 12); } + } + + public string Text3 + { + get { return _text3; } + set { _text3 = value.Substring(0, 12); } + } + + public string Text4 + { + get { return _text4; } + set { _text4 = value.Substring(0, 12); } + } + + public TileEntitySign () + : base("Sign") + { + } + + public TileEntitySign (TileEntity te) + : base(te) + { + TileEntitySign tes = te as TileEntitySign; + if (tes != null) { + _text1 = tes._text1; + _text2 = tes._text2; + _text3 = tes._text3; + _text4 = tes._text4; + } + } + + + #region ICopyable Members + + public override TileEntity Copy () + { + return new TileEntitySign(this); + } + + #endregion + + + #region INBTObject Members + + public override TileEntity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _text1 = ctree["Text1"].ToNBTString(); + _text2 = ctree["Text2"].ToNBTString(); + _text3 = ctree["Text3"].ToNBTString(); + _text4 = ctree["Text4"].ToNBTString(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Text1"] = new NBT_String(_text1); + tree["Text2"] = new NBT_String(_text2); + tree["Text3"] = new NBT_String(_text3); + tree["Text4"] = new NBT_String(_text4); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, SignSchema).Verify(); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityTrap.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityTrap.cs new file mode 100644 index 0000000..c19de16 --- /dev/null +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityTrap.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Map.TileEntities +{ + using Substrate.Map.NBT; + + public class TileEntityTrap : TileEntity, IItemContainer + { + public static readonly NBTCompoundNode TrapSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Trap"), + new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema), + }); + + 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 Members + + public override TileEntity Copy () + { + return new TileEntityTrap(this); + } + + #endregion + + + #region IItemContainer Members + + public ItemCollection Items + { + get { return _items; } + } + + #endregion + + + #region INBTObject Members + + public override TileEntity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + NBT_List items = ctree["Items"].ToNBTList(); + _items = new ItemCollection(_CAPACITY).LoadTree(items); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Items"] = _items.BuildTree(); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, TrapSchema).Verify(); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/TileEntity.cs b/Substrate/SubstrateCS/Source/TileEntity.cs index d6dc0c6..1fb32ca 100644 --- a/Substrate/SubstrateCS/Source/TileEntity.cs +++ b/Substrate/SubstrateCS/Source/TileEntity.cs @@ -63,6 +63,7 @@ namespace Substrate.Map return _x == x && _y == y && _z == z; } + #region ICopyable Members public virtual TileEntity Copy () @@ -72,6 +73,7 @@ namespace Substrate.Map #endregion + #region INBTObject Members public virtual TileEntity LoadTree (NBT_Value tree) @@ -117,515 +119,4 @@ namespace Substrate.Map #endregion } - public class TileEntityFurnace : TileEntity, IItemContainer - { - public static readonly NBTCompoundNode FurnaceSchema = BaseSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Furnace"), - new NBTScalerNode("BurnTime", NBT_Type.TAG_SHORT), - new NBTScalerNode("CookTime", NBT_Type.TAG_SHORT), - new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema), - }); - - private const int _CAPACITY = 3; - - private short _burnTime; - private short _cookTime; - - private ItemCollection _items; - - public int BurnTime - { - get { return _burnTime; } - set { _burnTime = (short)value; } - } - - public int CookTime - { - get { return _cookTime; } - set { _cookTime = (short)value; } - } - - public TileEntityFurnace () - : base("Furnace") - { - _items = new ItemCollection(_CAPACITY); - } - - public TileEntityFurnace (TileEntity te) - : base (te) - { - TileEntityFurnace tec = te as TileEntityFurnace; - if (tec != null) { - _cookTime = tec._cookTime; - _burnTime = tec._burnTime; - _items = tec._items.Copy(); - } - else { - _items = new ItemCollection(_CAPACITY); - } - } - - #region ICopyable Members - - public override TileEntity Copy () - { - return new TileEntityFurnace(this); - } - - #endregion - - #region IItemContainer Members - - public ItemCollection Items - { - get { return _items; } - } - - #endregion - - #region INBTObject Members - - public override TileEntity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _burnTime = ctree["BurnTime"].ToNBTShort(); - _cookTime = ctree["CookTime"].ToNBTShort(); - - NBT_List items = ctree["Items"].ToNBTList(); - _items = new ItemCollection(_CAPACITY).LoadTree(items); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["BurnTime"] = new NBT_Short(_burnTime); - tree["CookTime"] = new NBT_Short(_cookTime); - tree["Items"] = _items.BuildTree(); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, FurnaceSchema).Verify(); - } - - #endregion - } - - public class TileEntitySign : TileEntity - { - public static readonly NBTCompoundNode SignSchema = BaseSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Sign"), - new NBTScalerNode("Text1", NBT_Type.TAG_STRING), - new NBTScalerNode("Text2", NBT_Type.TAG_STRING), - new NBTScalerNode("Text3", NBT_Type.TAG_STRING), - new NBTScalerNode("Text4", NBT_Type.TAG_STRING), - }); - - private string _text1 = ""; - private string _text2 = ""; - private string _text3 = ""; - private string _text4 = ""; - - public string Text1 - { - get { return _text1; } - set { _text1 = value.Substring(0, 12); } - } - - public string Text2 - { - get { return _text2; } - set { _text2 = value.Substring(0, 12); } - } - - public string Text3 - { - get { return _text3; } - set { _text3 = value.Substring(0, 12); } - } - - public string Text4 - { - get { return _text4; } - set { _text4 = value.Substring(0, 12); } - } - - public TileEntitySign () - : base("Sign") - { - } - - public TileEntitySign (TileEntity te) - : base(te) - { - TileEntitySign tes = te as TileEntitySign; - if (tes != null) { - _text1 = tes._text1; - _text2 = tes._text2; - _text3 = tes._text3; - _text4 = tes._text4; - } - } - - #region ICopyable Members - - public override TileEntity Copy () - { - return new TileEntitySign(this); - } - - #endregion - - #region INBTObject Members - - public override TileEntity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _text1 = ctree["Text1"].ToNBTString(); - _text2 = ctree["Text2"].ToNBTString(); - _text3 = ctree["Text3"].ToNBTString(); - _text4 = ctree["Text4"].ToNBTString(); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Text1"] = new NBT_String(_text1); - tree["Text2"] = new NBT_String(_text2); - tree["Text3"] = new NBT_String(_text3); - tree["Text4"] = new NBT_String(_text4); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, SignSchema).Verify(); - } - - #endregion - } - - public class TileEntityMobSpawner : TileEntity - { - public static readonly NBTCompoundNode MobSpawnerSchema = BaseSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "MobSpawner"), - new NBTScalerNode("EntityId", NBT_Type.TAG_STRING), - new NBTScalerNode("Delay", NBT_Type.TAG_SHORT), - }); - - private short _delay; - private string _entityID; - - public int Delay - { - get { return _delay; } - set { _delay = (short)value; } - } - - public string EntityID - { - get { return _entityID; } - set { _entityID = value; } - } - - public TileEntityMobSpawner () - : base("MobSpawner") - { - } - - public TileEntityMobSpawner (TileEntity te) - : base(te) - { - TileEntityMobSpawner tes = te as TileEntityMobSpawner; - if (tes != null) { - _delay = tes._delay; - _entityID = tes._entityID; - } - } - - #region ICopyable Members - - public override TileEntity Copy () - { - return new TileEntityMobSpawner(this); - } - - #endregion - - #region INBTObject Members - - public override TileEntity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _delay = ctree["Delay"].ToNBTShort(); - _entityID = ctree["EntityID"].ToNBTString(); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["EntityID"] = new NBT_String(_entityID); - tree["Delay"] = new NBT_Short(_delay); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, MobSpawnerSchema).Verify(); - } - - #endregion - } - - public class TileEntityChest : TileEntity, IItemContainer - { - public static readonly NBTCompoundNode ChestSchema = BaseSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Chest"), - new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema), - }); - - private const int _CAPACITY = 27; - - private ItemCollection _items; - - public TileEntityChest () - : base("Chest") - { - _items = new ItemCollection(_CAPACITY); - } - - public TileEntityChest (TileEntity te) - : base(te) - { - TileEntityChest tec = te as TileEntityChest; - if (tec != null) { - _items = tec._items.Copy(); - } - else { - _items = new ItemCollection(_CAPACITY); - } - } - - #region ICopyable Members - - public override TileEntity Copy () - { - return new TileEntityChest(this); - } - - #endregion - - #region IItemContainer Members - - public ItemCollection Items - { - get { return _items; } - } - - #endregion - - #region INBTObject Members - - public override TileEntity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - NBT_List items = ctree["Items"].ToNBTList(); - _items = new ItemCollection(_CAPACITY).LoadTree(items); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Items"] = _items.BuildTree(); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, ChestSchema).Verify(); - } - - #endregion - } - - public class TileEntityMusic : TileEntity - { - public static readonly NBTCompoundNode MusicSchema = BaseSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Music"), - new NBTScalerNode("note", NBT_Type.TAG_BYTE), - }); - - private byte _note; - - public int Note - { - get { return _note; } - set { _note = (byte)value; } - } - - public TileEntityMusic () - : base("Music") - { - } - - public TileEntityMusic (TileEntity te) - : base(te) - { - TileEntityMusic tes = te as TileEntityMusic; - if (tes != null) { - _note = tes._note; - } - } - - #region ICopyable Members - - public override TileEntity Copy () - { - return new TileEntityMusic(this); - } - - #endregion - - #region INBTObject Members - - public override TileEntity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - _note = ctree["Note"].ToNBTByte(); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Note"] = new NBT_Byte(_note); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, MusicSchema).Verify(); - } - - #endregion - } - - public class TileEntityTrap : TileEntity, IItemContainer - { - public static readonly NBTCompoundNode TrapSchema = BaseSchema.MergeInto(new NBTCompoundNode("") - { - new NBTStringNode("id", "Trap"), - new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema), - }); - - 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 Members - - public override TileEntity Copy () - { - return new TileEntityTrap(this); - } - - #endregion - - #region IItemContainer Members - - public ItemCollection Items - { - get { return _items; } - } - - #endregion - - #region INBTObject Members - - public override TileEntity LoadTree (NBT_Value tree) - { - NBT_Compound ctree = tree as NBT_Compound; - if (ctree == null || base.LoadTree(tree) == null) { - return null; - } - - NBT_List items = ctree["Items"].ToNBTList(); - _items = new ItemCollection(_CAPACITY).LoadTree(items); - - return this; - } - - public override NBT_Value BuildTree () - { - NBT_Compound tree = base.BuildTree() as NBT_Compound; - tree["Items"] = _items.BuildTree(); - - return tree; - } - - public override bool ValidateTree (NBT_Value tree) - { - return new NBTVerifier(tree, TrapSchema).Verify(); - } - - #endregion - } } diff --git a/Substrate/SubstrateCS/Source/TileEntityFactory.cs b/Substrate/SubstrateCS/Source/TileEntityFactory.cs index 56726cf..c705a77 100644 --- a/Substrate/SubstrateCS/Source/TileEntityFactory.cs +++ b/Substrate/SubstrateCS/Source/TileEntityFactory.cs @@ -5,6 +5,7 @@ using System.Text; namespace Substrate.Map { using NBT; + using TileEntities; public class TileEntityFactory {