From 50375d326d91879fed15302aa00b726b44eacc83 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 6 Apr 2011 22:01:22 +0000 Subject: [PATCH] Added remaining entities. Fixed a few remaining namespace inconsistencies. --- .../SubstrateCS/Source/Entities/EntityBoat.cs | 46 ++++++++ .../Source/Entities/EntityFallingSand.cs | 79 ++++++++++++++ .../SubstrateCS/Source/Entities/EntityItem.cs | 4 +- .../Source/Entities/EntityMinecart.cs | 94 ++++++++++++++++ .../Source/Entities/EntityMinecartChest.cs | 85 +++++++++++++++ .../Source/Entities/EntityMinecartFurnace.cs | 100 ++++++++++++++++++ .../SubstrateCS/Source/Entities/EntityMob.cs | 4 +- .../Source/Entities/EntityPainting.cs | 8 +- .../Source/Entities/EntityPrimedTnt.cs | 79 ++++++++++++++ .../Source/Entities/EntityThrowable.cs | 4 +- Substrate/SubstrateCS/Source/Entity.cs | 2 +- Substrate/SubstrateCS/Source/EntityFactory.cs | 6 +- Substrate/SubstrateCS/Source/Item.cs | 2 +- Substrate/SubstrateCS/Source/NBT/NBT.cs | 2 +- Substrate/SubstrateCS/Source/NBT/NBTSchema.cs | 2 +- Substrate/SubstrateCS/Source/NBT/NBTValues.cs | 2 +- Substrate/SubstrateCS/Source/TileEntity.cs | 2 +- .../SubstrateCS/Source/TileEntityFactory.cs | 2 +- 18 files changed, 505 insertions(+), 18 deletions(-) create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityBoat.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs diff --git a/Substrate/SubstrateCS/Source/Entities/EntityBoat.cs b/Substrate/SubstrateCS/Source/Entities/EntityBoat.cs new file mode 100644 index 0000000..c954c46 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityBoat.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.NBT; + + public class EntityBoat : Entity + { + public static readonly NBTCompoundNode BoatSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "Boat"), + }); + + public EntityBoat () + : base("Boat") + { + } + + public EntityBoat (Entity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, BoatSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityBoat(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs b/Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs new file mode 100644 index 0000000..30300d1 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.NBT; + + public class EntityFallingSand : Entity + { + public static readonly NBTCompoundNode FallingSandSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "FallingSand"), + new NBTScalerNode("Tile", NBT_Type.TAG_BYTE), + }); + + private byte _tile; + + public int Tile + { + get { return _tile; } + set { _tile = (byte)value; } + } + + public EntityFallingSand () + : base("PrimedTnt") + { + } + + public EntityFallingSand (Entity e) + : base(e) + { + EntityFallingSand e2 = e as EntityFallingSand; + if (e2 != null) { + _tile = e2._tile; + } + } + + + #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; + } + + _tile = ctree["Tile"].ToNBTByte(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Tile"] = new NBT_Byte(_tile); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, FallingSandSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityFallingSand(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityItem.cs b/Substrate/SubstrateCS/Source/Entities/EntityItem.cs index 038bafe..1f95ab3 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityItem.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityItem.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map.Entities +namespace Substrate.Entities { - using Substrate.Map.NBT; + using Substrate.NBT; public class EntityItem : Entity { diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs b/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs new file mode 100644 index 0000000..844bf02 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs @@ -0,0 +1,94 @@ +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"), + new NBTScalerNode("Type", NBT_Type.TAG_BYTE), + }); + + 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 Members + + public override Entity LoadTree (NBT_Value tree) + { + NBT_Compound ctree = tree as NBT_Compound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _type = (CartType)ctree["Type"].ToNBTByte().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 NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Type"] = new NBT_Byte((byte)_type); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, MinecartSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityMinecart(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs b/Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs new file mode 100644 index 0000000..2e2cd89 --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.NBT; + + public class EntityMinecartChest : EntityMinecart, IItemContainer + { + public static readonly NBTCompoundNode MinecartChestSchema = MinecartSchema.MergeInto(new NBTCompoundNode("") + { + new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.InventorySchema), + }); + + private static int _CAPACITY = 27; + + private ItemCollection _items; + + public EntityMinecartChest () + : base() + { + _items = new ItemCollection(_CAPACITY); + } + + public EntityMinecartChest (Entity e) + : base(e) + { + EntityMinecartChest e2 = e as EntityMinecartChest; + if (e2 != null) { + _items = e2._items.Copy(); + } + } + + #region IItemContainer Members + + public ItemCollection Items + { + get { return _items; } + } + + #endregion + + + #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; + } + + NBT_List items = ctree["Items"].ToNBTList(); + _items = _items.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, MinecartChestSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityMinecartChest(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs b/Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs new file mode 100644 index 0000000..78ead9b --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.NBT; + + public class EntityMinecartFurnace : EntityMinecart + { + public static readonly NBTCompoundNode MinecartFurnaceSchema = MinecartSchema.MergeInto(new NBTCompoundNode("") + { + new NBTScalerNode("PushX", NBT_Type.TAG_DOUBLE), + new NBTScalerNode("PushZ", NBT_Type.TAG_DOUBLE), + new NBTScalerNode("Fuel", NBT_Type.TAG_SHORT), + }); + + private double _pushX; + private double _pushZ; + private short _fuel; + + public double PushX + { + get { return _pushX; } + set { _pushX = value; } + } + + public double PushZ + { + get { return _pushZ; } + set { _pushZ = value; } + } + + public int Fuel + { + get { return _fuel; } + set { _fuel = (short)value; } + } + + public EntityMinecartFurnace () + : base() + { + } + + public EntityMinecartFurnace (Entity e) + : base(e) + { + EntityMinecartFurnace e2 = e as EntityMinecartFurnace; + if (e2 != null) { + _pushX = e2._pushX; + _pushZ = e2._pushZ; + _fuel = e2._fuel; + } + } + + + #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; + } + + _pushX = ctree["PushX"].ToNBTDouble(); + _pushZ = ctree["PushZ"].ToNBTDouble(); + _fuel = ctree["Fuel"].ToNBTShort(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["PushX"] = new NBT_Double(_pushX); + tree["PushZ"] = new NBT_Double(_pushZ); + tree["Fuel"] = new NBT_Short(_fuel); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, MinecartFurnaceSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityMinecartFurnace(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMob.cs b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs index 8319c5a..89cdb58 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityMob.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map.Entities +namespace Substrate.Entities { - using Substrate.Map.NBT; + using Substrate.NBT; public class EntityMob : Entity { diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs b/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs index aae69da..7081276 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs @@ -8,7 +8,7 @@ namespace Substrate.Entities public class EntityPainting : Entity { - public enum Direction + public enum DirectionType { EAST = 0, NORTH = 1, @@ -26,13 +26,13 @@ namespace Substrate.Entities new NBTScalerNode("Motive", NBT_Type.TAG_STRING), }); - private Direction _dir; + private DirectionType _dir; private string _motive; private short _xTile; private short _yTile; private short _zTile; - public Direction Direction + public DirectionType Direction { get { return _dir; } set { _dir = value; } @@ -90,7 +90,7 @@ namespace Substrate.Entities return null; } - _dir = (Direction) ctree["Dir"].ToNBTByte().Data; + _dir = (DirectionType) ctree["Dir"].ToNBTByte().Data; _motive = ctree["Motive"].ToNBTString(); _xTile = ctree["TileX"].ToNBTShort(); _yTile = ctree["TileY"].ToNBTShort(); diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs b/Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs new file mode 100644 index 0000000..a39e7dd --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.NBT; + + public class EntityPrimedTnt : Entity + { + public static readonly NBTCompoundNode PrimedTntSchema = BaseSchema.MergeInto(new NBTCompoundNode("") + { + new NBTStringNode("id", "PrimedTnt"), + new NBTScalerNode("Fuse", NBT_Type.TAG_BYTE), + }); + + private byte _fuse; + + public int Fuse + { + get { return _fuse; } + set { _fuse = (byte)value; } + } + + public EntityPrimedTnt () + : base("PrimedTnt") + { + } + + public EntityPrimedTnt (Entity e) + : base(e) + { + EntityPrimedTnt e2 = e as EntityPrimedTnt; + if (e2 != null) { + _fuse = e2._fuse; + } + } + + + #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; + } + + _fuse = ctree["Fuse"].ToNBTByte(); + + return this; + } + + public override NBT_Value BuildTree () + { + NBT_Compound tree = base.BuildTree() as NBT_Compound; + tree["Fuse"] = new NBT_Byte(_fuse); + + return tree; + } + + public override bool ValidateTree (NBT_Value tree) + { + return new NBTVerifier(tree, PrimedTntSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override Entity Copy () + { + return new EntityPrimedTnt(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs b/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs index 2a5e136..eeb3a80 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map.Entities +namespace Substrate.Entities { - using Substrate.Map.NBT; + using Substrate.NBT; public class EntityThrowable : Entity { diff --git a/Substrate/SubstrateCS/Source/Entity.cs b/Substrate/SubstrateCS/Source/Entity.cs index 1adddae..3e56083 100644 --- a/Substrate/SubstrateCS/Source/Entity.cs +++ b/Substrate/SubstrateCS/Source/Entity.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map +namespace Substrate { using NBT; using Utility; diff --git a/Substrate/SubstrateCS/Source/EntityFactory.cs b/Substrate/SubstrateCS/Source/EntityFactory.cs index 797681f..cb709d9 100644 --- a/Substrate/SubstrateCS/Source/EntityFactory.cs +++ b/Substrate/SubstrateCS/Source/EntityFactory.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map +namespace Substrate { using NBT; using Entities; @@ -55,18 +55,22 @@ namespace Substrate.Map _registry = new Dictionary(); _registry["Arrow"] = typeof(EntityArrow); + _registry["Boat"] = typeof(EntityBoat); _registry["Chicken"] = typeof(EntityChicken); _registry["Cow"] = typeof(EntityCow); _registry["Creeper"] = typeof(EntityCreeper); _registry["Egg"] = typeof(EntityEgg); + _registry["FallingSand"] = typeof(EntityFallingSand); _registry["Ghast"] = typeof(EntityGhast); _registry["Giant"] = typeof(EntityGiant); _registry["Item"] = typeof(EntityItem); + _registry["Minecart"] = typeof(EntityMinecart); _registry["Mob"] = typeof(EntityMob); _registry["Monster"] = typeof(EntityMonster); _registry["Painting"] = typeof(EntityPainting); _registry["Pig"] = typeof(EntityPig); _registry["PigZombie"] = typeof(EntityPigZombie); + _registry["PrimedTnt"] = typeof(EntityPrimedTnt); _registry["Sheep"] = typeof(EntitySheep); _registry["Skeleton"] = typeof(EntitySkeleton); _registry["Slime"] = typeof(EntitySlime); diff --git a/Substrate/SubstrateCS/Source/Item.cs b/Substrate/SubstrateCS/Source/Item.cs index 57777fa..29b76f5 100644 --- a/Substrate/SubstrateCS/Source/Item.cs +++ b/Substrate/SubstrateCS/Source/Item.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map +namespace Substrate { using NBT; using Utility; diff --git a/Substrate/SubstrateCS/Source/NBT/NBT.cs b/Substrate/SubstrateCS/Source/NBT/NBT.cs index be98862..af1e8cf 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBT.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBT.cs @@ -6,7 +6,7 @@ using System.IO.Compression; namespace Substrate.NBT { - using Map.Utility; + using Substrate.Utility; public interface INBTObject { diff --git a/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs b/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs index d80731a..1fbc881 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map.NBT +namespace Substrate.NBT { public abstract class NBTSchemaNode { diff --git a/Substrate/SubstrateCS/Source/NBT/NBTValues.cs b/Substrate/SubstrateCS/Source/NBT/NBTValues.cs index 33b33cf..9c3c807 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBTValues.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBTValues.cs @@ -4,7 +4,7 @@ using System.Text; namespace Substrate.NBT { - using Map.Utility; + using Substrate.Utility; /// /// Describes the type of value held by an NBT_Tag diff --git a/Substrate/SubstrateCS/Source/TileEntity.cs b/Substrate/SubstrateCS/Source/TileEntity.cs index 1fb32ca..ee11a00 100644 --- a/Substrate/SubstrateCS/Source/TileEntity.cs +++ b/Substrate/SubstrateCS/Source/TileEntity.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map +namespace Substrate { using NBT; using Utility; diff --git a/Substrate/SubstrateCS/Source/TileEntityFactory.cs b/Substrate/SubstrateCS/Source/TileEntityFactory.cs index c705a77..ee612ee 100644 --- a/Substrate/SubstrateCS/Source/TileEntityFactory.cs +++ b/Substrate/SubstrateCS/Source/TileEntityFactory.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Substrate.Map +namespace Substrate { using NBT; using TileEntities;