From c10ee4215f0146b3d351a12aa82a7850a9b9ca1a Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sat, 5 Nov 2011 14:30:59 -0400 Subject: [PATCH] Factored TypeId out of TileEntity types, added Piston to TileEntity registry --- .../TileEntities/TileEntityBrewingStand.cs | 16 +++++++++++--- .../Source/TileEntities/TileEntityChest.cs | 16 +++++++++++--- .../TileEntityEnchantmentTable.cs | 14 +++++++++++-- .../TileEntities/TileEntityEndPortal.cs | 14 +++++++++++-- .../Source/TileEntities/TileEntityFurnace.cs | 16 +++++++++++--- .../TileEntities/TileEntityMobSpawner.cs | 14 +++++++++++-- .../Source/TileEntities/TileEntityMusic.cs | 14 +++++++++++-- .../Source/TileEntities/TileEntityPiston.cs | 14 +++++++++++-- .../TileEntities/TileEntityRecordPlayer.cs | 14 +++++++++++-- .../Source/TileEntities/TileEntitySign.cs | 14 +++++++++++-- .../Source/TileEntities/TileEntityTrap.cs | 16 +++++++++++--- SubstrateCS/Source/TileEntityFactory.cs | 21 ++++++++++--------- 12 files changed, 147 insertions(+), 36 deletions(-) diff --git a/SubstrateCS/Source/TileEntities/TileEntityBrewingStand.cs b/SubstrateCS/Source/TileEntities/TileEntityBrewingStand.cs index e3baace..176780a 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityBrewingStand.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityBrewingStand.cs @@ -9,22 +9,32 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound BrewingStandSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Cauldron"), + new SchemaNodeString("id", TypeId), new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.Schema), new SchemaNodeScaler("BrewTime", TagType.TAG_SHORT), }); + public static string TypeId + { + get { return "Cauldron"; } + } + private const int _CAPACITY = 4; private ItemCollection _items; private short _brewTime; - public TileEntityBrewingStand () - : base("Cauldron") + protected TileEntityBrewingStand (string id) + : base(id) { _items = new ItemCollection(_CAPACITY); } + public TileEntityBrewingStand () + : this(TypeId) + { + } + public TileEntityBrewingStand (TileEntity te) : base(te) { diff --git a/SubstrateCS/Source/TileEntities/TileEntityChest.cs b/SubstrateCS/Source/TileEntities/TileEntityChest.cs index 39c4ddd..38efcb3 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityChest.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityChest.cs @@ -9,20 +9,30 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound ChestSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Chest"), + new SchemaNodeString("id", TypeId), new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.Schema), }); + public static string TypeId + { + get { return "Chest"; } + } + private const int _CAPACITY = 27; private ItemCollection _items; - public TileEntityChest () - : base("Chest") + protected TileEntityChest (string id) + : base(id) { _items = new ItemCollection(_CAPACITY); } + public TileEntityChest () + : this(TypeId) + { + } + public TileEntityChest (TileEntity te) : base(te) { diff --git a/SubstrateCS/Source/TileEntities/TileEntityEnchantmentTable.cs b/SubstrateCS/Source/TileEntities/TileEntityEnchantmentTable.cs index 8fc69d8..0147efa 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityEnchantmentTable.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityEnchantmentTable.cs @@ -10,11 +10,21 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound EnchantTableSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "EnchantTable"), + new SchemaNodeString("id", TypeId), }); + public static string TypeId + { + get { return "EnchantTable"; } + } + + protected TileEntityEnchantmentTable (string id) + : base(id) + { + } + public TileEntityEnchantmentTable () - : base("EnchantTable") + : this(TypeId) { } diff --git a/SubstrateCS/Source/TileEntities/TileEntityEndPortal.cs b/SubstrateCS/Source/TileEntities/TileEntityEndPortal.cs index 4804841..30345fa 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityEndPortal.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityEndPortal.cs @@ -10,11 +10,21 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound EndPortalSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Airportal"), + new SchemaNodeString("id", TypeId), }); + public static string TypeId + { + get { return "Airportal"; } + } + + protected TileEntityEndPortal (string id) + : base(id) + { + } + public TileEntityEndPortal () - : base("Airportal") + : this(TypeId) { } diff --git a/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs b/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs index c025773..b25c030 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs @@ -9,12 +9,17 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound FurnaceSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Furnace"), + new SchemaNodeString("id", TypeId), new SchemaNodeScaler("BurnTime", TagType.TAG_SHORT), new SchemaNodeScaler("CookTime", TagType.TAG_SHORT), new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.Schema), }); + public static string TypeId + { + get { return "Furnace"; } + } + private const int _CAPACITY = 3; private short _burnTime; @@ -34,12 +39,17 @@ namespace Substrate.TileEntities set { _cookTime = (short)value; } } - public TileEntityFurnace () - : base("Furnace") + protected TileEntityFurnace (string id) + : base(id) { _items = new ItemCollection(_CAPACITY); } + public TileEntityFurnace () + : this(TypeId) + { + } + public TileEntityFurnace (TileEntity te) : base(te) { diff --git a/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs b/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs index c59850d..b301b8f 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs @@ -10,11 +10,16 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound MobSpawnerSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "MobSpawner"), + new SchemaNodeString("id", TypeId), new SchemaNodeScaler("EntityId", TagType.TAG_STRING), new SchemaNodeScaler("Delay", TagType.TAG_SHORT), }); + public static string TypeId + { + get { return "MobSpawner"; } + } + private short _delay; private string _entityID; @@ -30,8 +35,13 @@ namespace Substrate.TileEntities set { _entityID = value; } } + protected TileEntityMobSpawner (string id) + : base(id) + { + } + public TileEntityMobSpawner () - : base("MobSpawner") + : this(TypeId) { } diff --git a/SubstrateCS/Source/TileEntities/TileEntityMusic.cs b/SubstrateCS/Source/TileEntities/TileEntityMusic.cs index 29fdbac..5113096 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityMusic.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityMusic.cs @@ -10,10 +10,15 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound MusicSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Music"), + new SchemaNodeString("id", TypeId), new SchemaNodeScaler("note", TagType.TAG_BYTE), }); + public static string TypeId + { + get { return "Music"; } + } + private byte _note; public int Note @@ -22,8 +27,13 @@ namespace Substrate.TileEntities set { _note = (byte)value; } } + protected TileEntityMusic (string id) + : base(id) + { + } + public TileEntityMusic () - : base("Music") + : this(TypeId) { } diff --git a/SubstrateCS/Source/TileEntities/TileEntityPiston.cs b/SubstrateCS/Source/TileEntities/TileEntityPiston.cs index d140819..153e5dc 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityPiston.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityPiston.cs @@ -10,7 +10,7 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound PistonSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Piston"), + new SchemaNodeString("id", TypeId), new SchemaNodeScaler("blockId", TagType.TAG_INT), new SchemaNodeScaler("blockData", TagType.TAG_INT), new SchemaNodeScaler("facing", TagType.TAG_INT), @@ -18,6 +18,11 @@ namespace Substrate.TileEntities new SchemaNodeScaler("extending", TagType.TAG_BYTE), }); + public static string TypeId + { + get { return "Piston"; } + } + private int? _record = null; private byte _extending; @@ -56,8 +61,13 @@ namespace Substrate.TileEntities set { _progress = value; } } + protected TileEntityPiston (string id) + : base(id) + { + } + public TileEntityPiston () - : base("Piston") + : this(TypeId) { } diff --git a/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs b/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs index 3d6d5df..8bb51f3 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs @@ -10,10 +10,15 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound RecordPlayerSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "RecordPlayer"), + new SchemaNodeString("id", TypeId), new SchemaNodeScaler("Record", TagType.TAG_INT, SchemaOptions.OPTIONAL), }); + public static string TypeId + { + get { return "RecordPlayer"; } + } + private int? _record = null; public int? Record @@ -22,8 +27,13 @@ namespace Substrate.TileEntities set { _record = value; } } + protected TileEntityRecordPlayer (string id) + : base(id) + { + } + public TileEntityRecordPlayer () - : base("RecordPlayer") + : this(TypeId) { } diff --git a/SubstrateCS/Source/TileEntities/TileEntitySign.cs b/SubstrateCS/Source/TileEntities/TileEntitySign.cs index 9e54185..70caab1 100644 --- a/SubstrateCS/Source/TileEntities/TileEntitySign.cs +++ b/SubstrateCS/Source/TileEntities/TileEntitySign.cs @@ -10,13 +10,18 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound SignSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Sign"), + new SchemaNodeString("id", TypeId), new SchemaNodeScaler("Text1", TagType.TAG_STRING), new SchemaNodeScaler("Text2", TagType.TAG_STRING), new SchemaNodeScaler("Text3", TagType.TAG_STRING), new SchemaNodeScaler("Text4", TagType.TAG_STRING), }); + public static string TypeId + { + get { return "Sign"; } + } + private string _text1 = ""; private string _text2 = ""; private string _text3 = ""; @@ -46,8 +51,13 @@ namespace Substrate.TileEntities set { _text4 = value.Substring(0, 14); } } + protected TileEntitySign (string id) + : base(id) + { + } + public TileEntitySign () - : base("Sign") + : this(TypeId) { } diff --git a/SubstrateCS/Source/TileEntities/TileEntityTrap.cs b/SubstrateCS/Source/TileEntities/TileEntityTrap.cs index 91bf0ad..69637ae 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityTrap.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityTrap.cs @@ -9,20 +9,30 @@ namespace Substrate.TileEntities { public static readonly SchemaNodeCompound TrapSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("") { - new SchemaNodeString("id", "Trap"), + new SchemaNodeString("id", TypeId), new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.Schema), }); + public static string TypeId + { + get { return "Trap"; } + } + private const int _CAPACITY = 8; private ItemCollection _items; - public TileEntityTrap () - : base("Trap") + protected TileEntityTrap (string id) + : base(id) { _items = new ItemCollection(_CAPACITY); } + public TileEntityTrap () + : this(TypeId) + { + } + public TileEntityTrap (TileEntity te) : base(te) { diff --git a/SubstrateCS/Source/TileEntityFactory.cs b/SubstrateCS/Source/TileEntityFactory.cs index 2f1dd87..a9619eb 100644 --- a/SubstrateCS/Source/TileEntityFactory.cs +++ b/SubstrateCS/Source/TileEntityFactory.cs @@ -77,16 +77,17 @@ namespace Substrate static TileEntityFactory () { - _registry["Airportal"] = typeof(TileEntityEndPortal); - _registry["Cauldron"] = typeof(TileEntityBrewingStand); - _registry["Chest"] = typeof(TileEntityChest); - _registry["EnchantTable"] = typeof(TileEntityEnchantmentTable); - _registry["Furnace"] = typeof(TileEntityFurnace); - _registry["MobSpawner"] = typeof(TileEntityMobSpawner); - _registry["Music"] = typeof(TileEntityMusic); - _registry["RecordPlayer"] = typeof(TileEntityRecordPlayer); - _registry["Sign"] = typeof(TileEntitySign); - _registry["Trap"] = typeof(TileEntityTrap); + _registry[TileEntityEndPortal.TypeId] = typeof(TileEntityEndPortal); + _registry[TileEntityBrewingStand.TypeId] = typeof(TileEntityBrewingStand); + _registry[TileEntityChest.TypeId] = typeof(TileEntityChest); + _registry[TileEntityEnchantmentTable.TypeId] = typeof(TileEntityEnchantmentTable); + _registry[TileEntityFurnace.TypeId] = typeof(TileEntityFurnace); + _registry[TileEntityMobSpawner.TypeId] = typeof(TileEntityMobSpawner); + _registry[TileEntityMusic.TypeId] = typeof(TileEntityMusic); + _registry[TileEntityPiston.TypeId] = typeof(TileEntityPiston); + _registry[TileEntityRecordPlayer.TypeId] = typeof(TileEntityRecordPlayer); + _registry[TileEntitySign.TypeId] = typeof(TileEntitySign); + _registry[TileEntityTrap.TypeId] = typeof(TileEntityTrap); } }