From a002336603988a5a01835945ea960cbbcfa52469 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Tue, 13 Nov 2012 23:38:43 -0500 Subject: [PATCH] Fixed handling of MobSpawnerTileEntities --- .../TileEntities/TileEntityMobSpawner.cs | 163 +++++++++++++++--- 1 file changed, 143 insertions(+), 20 deletions(-) diff --git a/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs b/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs index 4464a80..9ea5ec0 100644 --- a/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs +++ b/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs @@ -13,10 +13,18 @@ namespace Substrate.TileEntities new SchemaNodeString("id", TypeId), new SchemaNodeScaler("EntityId", TagType.TAG_STRING), new SchemaNodeScaler("Delay", TagType.TAG_SHORT), - new SchemaNodeScaler("MaxSpawnDelay", TagType.TAG_SHORT, SchemaOptions.CREATE_ON_MISSING), - new SchemaNodeScaler("MinSpawnDelay", TagType.TAG_SHORT, SchemaOptions.CREATE_ON_MISSING), - new SchemaNodeScaler("SpawnCount", TagType.TAG_SHORT), - Entity.Schema.MergeInto(new SchemaNodeCompound("SpawnData", SchemaOptions.OPTIONAL)) + new SchemaNodeScaler("MaxSpawnDelay", TagType.TAG_SHORT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("MinSpawnDelay", TagType.TAG_SHORT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("SpawnCount", TagType.TAG_SHORT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("SpawnRange", TagType.TAG_SHORT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("MaxNearbyEnemies", TagType.TAG_SHORT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("RequiredPlayerRange", TagType.TAG_SHORT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("MaxExperience", TagType.TAG_INT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("RemainingExperience", TagType.TAG_INT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("ExperienceRegenTick", TagType.TAG_INT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("ExperienceRegenRate", TagType.TAG_INT, SchemaOptions.OPTIONAL), + new SchemaNodeScaler("ExperienceRegenAmount", TagType.TAG_INT, SchemaOptions.OPTIONAL), + new SchemaNodeCompound("SpawnData", SchemaOptions.OPTIONAL), }); public static string TypeId @@ -26,10 +34,18 @@ namespace Substrate.TileEntities private short _delay; private string _entityID; - private short _maxDelay; - private short _minDelay; - private short _spawnCount; - private Entity _spawnData; + private short? _maxDelay; + private short? _minDelay; + private short? _spawnCount; + private short? _spawnRange; + private short? _maxNearbyEnemies; + private short? _requiredPlayerRange; + private int? _maxExperience; + private int? _remainingExperience; + private int? _experienceRegenTick; + private int? _experienceRegenRate; + private int? _experienceRegenAmount; + private TagNodeCompound _spawnData; public int Delay { @@ -37,7 +53,7 @@ namespace Substrate.TileEntities set { _delay = (short)value; } } - public Entity SpawnData + public TagNodeCompound SpawnData { get { return _spawnData; } set { _spawnData = value; } @@ -51,22 +67,70 @@ namespace Substrate.TileEntities public short MaxSpawnDelay { - get { return _maxDelay; } + get { return _maxDelay ?? 0; } set { _maxDelay = value; } } public short MinSpawnDelay { - get { return _minDelay; } + get { return _minDelay ?? 0; } set { _minDelay = value; } } public short SpawnCount { - get { return _spawnCount; } + get { return _spawnCount ?? 0; } set { _spawnCount = value; } } + public short SpawnRange + { + get { return _spawnRange ?? 0; } + set { _spawnRange = value; } + } + + public short MaxNearbyEnemies + { + get { return _maxNearbyEnemies ?? 0; } + set { _maxNearbyEnemies = value; } + } + + public short RequiredPlayerRange + { + get { return _requiredPlayerRange ?? 0; } + set { _requiredPlayerRange = value; } + } + + public int MaxExperience + { + get { return _maxExperience ?? 0; } + set { _maxExperience = value; } + } + + public int RemainingExperience + { + get { return _remainingExperience ?? 0; } + set { _remainingExperience = value; } + } + + public int ExperienceRegenTick + { + get { return _experienceRegenTick ?? 0; } + set { _experienceRegenTick = value; } + } + + public int ExperienceRegenRate + { + get { return _experienceRegenRate ?? 0; } + set { _experienceRegenRate = value; } + } + + public int ExperienceRegenAmount + { + get { return _experienceRegenAmount ?? 0; } + set { _experienceRegenAmount = value; } + } + protected TileEntityMobSpawner (string id) : base(id) { @@ -84,6 +148,20 @@ namespace Substrate.TileEntities if (tes != null) { _delay = tes._delay; _entityID = tes._entityID; + _maxDelay = tes._maxDelay; + _minDelay = tes._minDelay; + _spawnCount = tes._spawnCount; + _spawnRange = tes._spawnRange; + _maxNearbyEnemies = tes._maxNearbyEnemies; + _requiredPlayerRange = tes._requiredPlayerRange; + _maxExperience = tes._maxExperience; + _remainingExperience = tes._remainingExperience; + _experienceRegenTick = tes._experienceRegenTick; + _experienceRegenRate = tes._experienceRegenRate; + _experienceRegenAmount = tes._experienceRegenAmount; + + if (tes._spawnData != null) + _spawnData = tes._spawnData.Copy() as TagNodeCompound; } } @@ -109,10 +187,32 @@ namespace Substrate.TileEntities _delay = ctree["Delay"].ToTagShort(); _entityID = ctree["EntityId"].ToTagString(); - _maxDelay = ctree["MaxSpawnDelay"].ToTagShort(); - _minDelay = ctree["MinSpawnDelay"].ToTagShort(); - _spawnCount = ctree["SpawnCount"].ToTagShort(); - _spawnData = new Entity().LoadTree(ctree["SpawnData"].ToTagCompound()); + + if (ctree.ContainsKey("MaxSpawnDelay")) + _maxDelay = ctree["MaxSpawnDelay"].ToTagShort(); + if (ctree.ContainsKey("MinSpawnDelay")) + _minDelay = ctree["MinSpawnDelay"].ToTagShort(); + if (ctree.ContainsKey("SpawnCount")) + _spawnCount = ctree["SpawnCount"].ToTagShort(); + if (ctree.ContainsKey("SpawnRange")) + _spawnRange = ctree["SpawnRange"].ToTagShort(); + if (ctree.ContainsKey("MaxNearbyEnemies")) + _maxNearbyEnemies = ctree["MaxNearbyEnemies"].ToTagShort(); + if (ctree.ContainsKey("RequiredPlayerRange")) + _requiredPlayerRange = ctree["RequiredPlayerRange"].ToTagShort(); + if (ctree.ContainsKey("MaxExperience")) + _maxExperience = ctree["MaxExperience"].ToTagInt(); + if (ctree.ContainsKey("RemainingExperience")) + _remainingExperience = ctree["RemainingExperience"].ToTagInt(); + if (ctree.ContainsKey("ExperienceRegenTick")) + _experienceRegenTick = ctree["ExperienceRegenTick"].ToTagInt(); + if (ctree.ContainsKey("ExperienceRegenRate")) + _experienceRegenRate = ctree["ExperienceRegenRate"].ToTagInt(); + if (ctree.ContainsKey("ExperienceRegenAmount")) + _experienceRegenRate = ctree["ExperienceRegenAmount"].ToTagInt(); + + if (ctree.ContainsKey("SpawnData")) + _spawnData = ctree["SpawnData"].ToTagCompound(); return this; } @@ -122,10 +222,33 @@ namespace Substrate.TileEntities TagNodeCompound tree = base.BuildTree() as TagNodeCompound; tree["EntityId"] = new TagNodeString(_entityID); tree["Delay"] = new TagNodeShort(_delay); - tree["MaxSpawnDelay"] = new TagNodeShort(_maxDelay); - tree["MinSpawnDelay"] = new TagNodeShort(_minDelay); - tree["SpawnCount"] = new TagNodeShort(_spawnCount); - tree["SpawnData"] = _spawnData.BuildTree(); + + if (_maxDelay != null) + tree["MaxSpawnDelay"] = new TagNodeShort(_maxDelay ?? 0); + if (_minDelay != null) + tree["MinSpawnDelay"] = new TagNodeShort(_minDelay ?? 0); + if (_spawnCount != null) + tree["SpawnCount"] = new TagNodeShort(_spawnCount ?? 0); + if (_spawnRange != null) + tree["SpawnRange"] = new TagNodeShort(_spawnRange ?? 0); + if (_maxNearbyEnemies != null) + tree["MaxNearbyEnemies"] = new TagNodeShort(_maxNearbyEnemies ?? 0); + if (_requiredPlayerRange != null) + tree["RequiredPlayerRange"] = new TagNodeShort(_requiredPlayerRange ?? 0); + if (_maxExperience != null) + tree["MaxExperience"] = new TagNodeInt(_maxExperience ?? 0); + if (_remainingExperience != null) + tree["RemainingExperience"] = new TagNodeInt(_remainingExperience ?? 0); + if (_experienceRegenTick != null) + tree["ExperienceRegenTick"] = new TagNodeInt(_experienceRegenTick ?? 0); + if (_experienceRegenRate != null) + tree["ExperienceRegenRate"] = new TagNodeInt(_experienceRegenRate ?? 0); + if (_experienceRegenAmount != null) + tree["ExperienceRegenAmount"] = new TagNodeInt(_experienceRegenAmount ?? 0); + + if (_spawnData != null && _spawnData.Count > 0) + tree["SpawnData"] = _spawnData; + return tree; }