2011-04-06 19:41:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2011-04-06 21:20:35 +00:00
|
|
|
|
namespace Substrate.TileEntities
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-30 04:41:29 +00:00
|
|
|
|
using Substrate.Nbt;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
|
|
|
|
|
public class TileEntityMobSpawner : TileEntity
|
|
|
|
|
{
|
2011-06-28 03:41:44 +00:00
|
|
|
|
public static readonly SchemaNodeCompound MobSpawnerSchema = TileEntity.Schema.MergeInto(new SchemaNodeCompound("")
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-11-05 18:30:59 +00:00
|
|
|
|
new SchemaNodeString("id", TypeId),
|
2011-06-20 03:51:40 +00:00
|
|
|
|
new SchemaNodeScaler("EntityId", TagType.TAG_STRING),
|
|
|
|
|
new SchemaNodeScaler("Delay", TagType.TAG_SHORT),
|
2012-09-22 15:43:07 +00:00
|
|
|
|
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))
|
2011-04-06 19:41:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-11-05 18:30:59 +00:00
|
|
|
|
public static string TypeId
|
|
|
|
|
{
|
|
|
|
|
get { return "MobSpawner"; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 19:41:57 +00:00
|
|
|
|
private short _delay;
|
|
|
|
|
private string _entityID;
|
2012-09-22 15:43:07 +00:00
|
|
|
|
private short _maxDelay;
|
|
|
|
|
private short _minDelay;
|
|
|
|
|
private short _spawnCount;
|
|
|
|
|
private Entity _spawnData;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
|
|
|
|
|
public int Delay
|
|
|
|
|
{
|
|
|
|
|
get { return _delay; }
|
|
|
|
|
set { _delay = (short)value; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-22 15:43:07 +00:00
|
|
|
|
public Entity SpawnData
|
|
|
|
|
{
|
|
|
|
|
get { return _spawnData; }
|
|
|
|
|
set { _spawnData = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 19:41:57 +00:00
|
|
|
|
public string EntityID
|
|
|
|
|
{
|
|
|
|
|
get { return _entityID; }
|
|
|
|
|
set { _entityID = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-22 15:43:07 +00:00
|
|
|
|
public short MaxSpawnDelay
|
|
|
|
|
{
|
|
|
|
|
get { return _maxDelay; }
|
|
|
|
|
set { _maxDelay = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public short MinSpawnDelay
|
|
|
|
|
{
|
|
|
|
|
get { return _minDelay; }
|
|
|
|
|
set { _minDelay = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public short SpawnCount
|
|
|
|
|
{
|
|
|
|
|
get { return _spawnCount; }
|
|
|
|
|
set { _spawnCount = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 18:30:59 +00:00
|
|
|
|
protected TileEntityMobSpawner (string id)
|
|
|
|
|
: base(id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 19:41:57 +00:00
|
|
|
|
public TileEntityMobSpawner ()
|
2011-11-05 18:30:59 +00:00
|
|
|
|
: this(TypeId)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TileEntityMobSpawner (TileEntity te)
|
|
|
|
|
: base(te)
|
|
|
|
|
{
|
|
|
|
|
TileEntityMobSpawner tes = te as TileEntityMobSpawner;
|
|
|
|
|
if (tes != null) {
|
|
|
|
|
_delay = tes._delay;
|
|
|
|
|
_entityID = tes._entityID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region ICopyable<TileEntity> Members
|
|
|
|
|
|
|
|
|
|
public override TileEntity Copy ()
|
|
|
|
|
{
|
|
|
|
|
return new TileEntityMobSpawner(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region INBTObject<TileEntity> Members
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override TileEntity LoadTree (TagNode tree)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound ctree = tree as TagNodeCompound;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
if (ctree == null || base.LoadTree(tree) == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
_delay = ctree["Delay"].ToTagShort();
|
2011-07-24 06:08:31 +00:00
|
|
|
|
_entityID = ctree["EntityId"].ToTagString();
|
2012-09-22 15:43:07 +00:00
|
|
|
|
_maxDelay = ctree["MaxSpawnDelay"].ToTagShort();
|
|
|
|
|
_minDelay = ctree["MinSpawnDelay"].ToTagShort();
|
|
|
|
|
_spawnCount = ctree["SpawnCount"].ToTagShort();
|
|
|
|
|
_spawnData = new Entity().LoadTree(ctree["SpawnData"].ToTagCompound());
|
2011-04-06 19:41:57 +00:00
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override TagNode BuildTree ()
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
2011-07-24 06:08:31 +00:00
|
|
|
|
tree["EntityId"] = new TagNodeString(_entityID);
|
2011-06-20 03:51:40 +00:00
|
|
|
|
tree["Delay"] = new TagNodeShort(_delay);
|
2012-09-22 15:43:07 +00:00
|
|
|
|
tree["MaxSpawnDelay"] = new TagNodeShort(_maxDelay);
|
|
|
|
|
tree["MinSpawnDelay"] = new TagNodeShort(_minDelay);
|
|
|
|
|
tree["SpawnCount"] = new TagNodeShort(_spawnCount);
|
|
|
|
|
tree["SpawnData"] = _spawnData.BuildTree();
|
2011-04-06 19:41:57 +00:00
|
|
|
|
return tree;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override bool ValidateTree (TagNode tree)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-30 04:57:18 +00:00
|
|
|
|
return new NbtVerifier(tree, MobSpawnerSchema).Verify();
|
2011-04-06 19:41:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|