From 77f9519ba22d4cde4e940b0d5c7ea880fc56f45b Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 21 Sep 2011 04:38:34 +0000 Subject: [PATCH] Entity updates, including 1.8 entities and additional fields in some existing entities. --- .../SubstrateCS/Properties/AssemblyInfo.cs | 4 +- .../Source/Entities/EntityArrow.cs | 44 ++++++++ .../Source/Entities/EntityCaveSpider.cs | 46 ++++++++ .../Source/Entities/EntityEnderman.cs | 94 ++++++++++++++++ .../SubstrateCS/Source/Entities/EntityMob.cs | 61 +++++++++++ .../Source/Entities/EntitySilverfish.cs | 63 +++++++++++ .../Source/Entities/EntityThrowable.cs | 6 +- .../Source/Entities/EntityXPOrb.cs | 100 ++++++++++++++++++ Substrate/SubstrateCS/Source/EntityFactory.cs | 4 + Substrate/SubstrateCS/Substrate.csproj | 4 + 10 files changed, 421 insertions(+), 5 deletions(-) create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityCaveSpider.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityEnderman.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntitySilverfish.cs create mode 100644 Substrate/SubstrateCS/Source/Entities/EntityXPOrb.cs diff --git a/Substrate/SubstrateCS/Properties/AssemblyInfo.cs b/Substrate/SubstrateCS/Properties/AssemblyInfo.cs index dcc633a..2e4611e 100644 --- a/Substrate/SubstrateCS/Properties/AssemblyInfo.cs +++ b/Substrate/SubstrateCS/Properties/AssemblyInfo.cs @@ -30,8 +30,8 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("0.7.1.0")] -[assembly: AssemblyFileVersion("0.7.1.0")] +[assembly: AssemblyVersion("0.7.2.0")] +[assembly: AssemblyFileVersion("0.7.2.0")] // This library is compatible with all CLS-compliant .NET programming languages. [assembly: CLSCompliant(true)] \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs b/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs index 3403e31..35f9cb7 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs @@ -11,8 +11,25 @@ namespace Substrate.Entities public static readonly SchemaNodeCompound ArrowSchema = ThrowableSchema.MergeInto(new SchemaNodeCompound("") { new SchemaNodeString("id", "Arrow"), + new SchemaNodeScaler("inData", TagType.TAG_BYTE, SchemaOptions.CREATE_ON_MISSING), + new SchemaNodeScaler("player", TagType.TAG_BYTE, SchemaOptions.CREATE_ON_MISSING), }); + private byte _inData; + private byte _player; + + public int InData + { + get { return _inData; } + set { _inData = (byte)value; } + } + + public bool IsPlayerArrow + { + get { return _player != 0; } + set { _player = (byte)(value ? 1 : 0); } + } + public EntityArrow () : base("Arrow") { @@ -21,11 +38,38 @@ namespace Substrate.Entities public EntityArrow (TypedEntity e) : base(e) { + EntityArrow e2 = e as EntityArrow; + if (e2 != null) { + _inData = e2._inData; + _player = e2._player; + } } #region INBTObject Members + public override TypedEntity LoadTree (TagNode tree) + { + TagNodeCompound ctree = tree as TagNodeCompound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _inData = ctree["inData"].ToTagByte(); + _player = ctree["player"].ToTagByte(); + + return this; + } + + public override TagNode BuildTree () + { + TagNodeCompound tree = base.BuildTree() as TagNodeCompound; + tree["inData"] = new TagNodeShort(_inData); + tree["player"] = new TagNodeShort(_player); + + return tree; + } + public override bool ValidateTree (TagNode tree) { return new NbtVerifier(tree, ArrowSchema).Verify(); diff --git a/Substrate/SubstrateCS/Source/Entities/EntityCaveSpider.cs b/Substrate/SubstrateCS/Source/Entities/EntityCaveSpider.cs new file mode 100644 index 0000000..b0c161d --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityCaveSpider.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.Nbt; + + public class EntityCaveSpider : EntityMob + { + public static readonly SchemaNodeCompound CaveSpiderSchema = MobSchema.MergeInto(new SchemaNodeCompound("") + { + new SchemaNodeString("id", "CaveSpider"), + }); + + public EntityCaveSpider () + : base("CaveSpider") + { + } + + public EntityCaveSpider (TypedEntity e) + : base(e) + { + } + + + #region INBTObject Members + + public override bool ValidateTree (TagNode tree) + { + return new NbtVerifier(tree, CaveSpiderSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override TypedEntity Copy () + { + return new EntityCaveSpider(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityEnderman.cs b/Substrate/SubstrateCS/Source/Entities/EntityEnderman.cs new file mode 100644 index 0000000..6dd1a8a --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityEnderman.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.Nbt; + + // XXX: BUG ALERT + // MC 1.8.1 Enderman data names "carried" and "carriedData" are inconsistent. These values are subject to change + // in the future, when the differences are reconciled. + + public class EntityEnderman : EntityMob + { + public static readonly SchemaNodeCompound EndermanSchema = MobSchema.MergeInto(new SchemaNodeCompound("") + { + new SchemaNodeString("id", "Sheep"), + new SchemaNodeScaler("carried", TagType.TAG_SHORT, SchemaOptions.CREATE_ON_MISSING), + new SchemaNodeScaler("carriedData", TagType.TAG_SHORT, SchemaOptions.CREATE_ON_MISSING), + }); + + private short _carried; + private short _carryingData; + + public int Carried + { + get { return _carried; } + set { _carried = (short)value; } + } + + public int CarryingData + { + get { return _carryingData; } + set { _carryingData = (short)value; } + } + + public EntityEnderman () + : base("Enderman") + { + } + + public EntityEnderman (TypedEntity e) + : base(e) + { + EntityEnderman e2 = e as EntityEnderman; + if (e2 != null) { + _carried = e2._carried; + _carryingData = e2._carryingData; + } + } + + + #region INBTObject Members + + public override TypedEntity LoadTree (TagNode tree) + { + TagNodeCompound ctree = tree as TagNodeCompound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _carried = ctree["carried"].ToTagShort(); + _carryingData = ctree["carriedData"].ToTagShort(); + + return this; + } + + public override TagNode BuildTree () + { + TagNodeCompound tree = base.BuildTree() as TagNodeCompound; + tree["carried"] = new TagNodeShort(_carried); + tree["carriedData"] = new TagNodeShort(_carryingData); + + return tree; + } + + public override bool ValidateTree (TagNode tree) + { + return new NbtVerifier(tree, EndermanSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override TypedEntity Copy () + { + return new EntityEnderman(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMob.cs b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs index 318eb32..1b51159 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityMob.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs @@ -6,6 +6,34 @@ namespace Substrate.Entities { using Substrate.Nbt; + /// + /// Encompasses data in the "ActiveEffects" compound attribute of mob entity types + /// + public class ActiveEffects + { + private byte _id; + private byte _amplifier; + private int _duration; + + public int Id + { + get { return _id; } + set { _id = (byte)value; } + } + + public int Amplifier + { + get { return _amplifier; } + set { _amplifier = (byte)value; } + } + + public int Duration + { + get { return _duration; } + set { _duration = value; } + } + } + public class EntityMob : TypedEntity { public static readonly SchemaNodeCompound MobSchema = TypedEntity.Schema.MergeInto(new SchemaNodeCompound("") @@ -15,6 +43,12 @@ namespace Substrate.Entities new SchemaNodeScaler("DeathTime", TagType.TAG_SHORT), new SchemaNodeScaler("Health", TagType.TAG_SHORT), new SchemaNodeScaler("HurtTime", TagType.TAG_SHORT), + new SchemaNodeCompound("ActiveEffects", SchemaOptions.OPTIONAL) + { + new SchemaNodeScaler("Id", TagType.TAG_BYTE), + new SchemaNodeScaler("Amplifier", TagType.TAG_BYTE), + new SchemaNodeScaler("Duration", TagType.TAG_INT), + }, }); private short _attackTime; @@ -22,6 +56,8 @@ namespace Substrate.Entities private short _health; private short _hurtTime; + private ActiveEffects _activeEffects; + public int AttackTime { get { return _attackTime; } @@ -46,6 +82,12 @@ namespace Substrate.Entities set { _hurtTime = (short)value; } } + public ActiveEffects ActiveEffects + { + get { return _activeEffects; } + set { _activeEffects = value; } + } + public EntityMob () : base("Mob") { @@ -65,6 +107,7 @@ namespace Substrate.Entities _deathTime = e2._deathTime; _health = e2._health; _hurtTime = e2._hurtTime; + _activeEffects = e2._activeEffects; } } @@ -83,6 +126,15 @@ namespace Substrate.Entities _health = ctree["Health"].ToTagShort(); _hurtTime = ctree["HurtTime"].ToTagShort(); + if (ctree.ContainsKey("ActiveEffects")) { + TagNodeCompound ae = ctree["ActiveEffects"].ToTagCompound(); + + _activeEffects = new ActiveEffects(); + _activeEffects.Id = ae["Id"].ToTagByte(); + _activeEffects.Amplifier = ae["Amplifier"].ToTagByte(); + _activeEffects.Duration = ae["Duration"].ToTagInt(); + } + return this; } @@ -94,6 +146,15 @@ namespace Substrate.Entities tree["Health"] = new TagNodeShort(_health); tree["HurtTime"] = new TagNodeShort(_hurtTime); + if (_activeEffects != null) { + TagNodeCompound ae = new TagNodeCompound(); + ae["Id"] = new TagNodeByte((byte)_activeEffects.Id); + ae["Amplifier"] = new TagNodeByte((byte)_activeEffects.Amplifier); + ae["Duration"] = new TagNodeInt(_activeEffects.Duration); + + tree["ActiveEffects"] = ae; + } + return tree; } diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySilverfish.cs b/Substrate/SubstrateCS/Source/Entities/EntitySilverfish.cs new file mode 100644 index 0000000..aa55b8e --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntitySilverfish.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.Nbt; + + public class EntitySilverfish : EntityMob + { + public static readonly SchemaNodeCompound SilverfishSchema = MobSchema.MergeInto(new SchemaNodeCompound("") + { + new SchemaNodeString("id", "Silverfish"), + }); + + public EntitySilverfish () + : base("Silverfish") + { + } + + public EntitySilverfish (TypedEntity e) + : base(e) + { + } + + + #region INBTObject Members + + public override TypedEntity LoadTree (TagNode tree) + { + TagNodeCompound ctree = tree as TagNodeCompound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + return this; + } + + public override TagNode BuildTree () + { + TagNodeCompound tree = base.BuildTree() as TagNodeCompound; + + return tree; + } + + public override bool ValidateTree (TagNode tree) + { + return new NbtVerifier(tree, SilverfishSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override TypedEntity Copy () + { + return new EntitySilverfish(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs b/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs index 0e1022a..bf844c8 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs @@ -43,10 +43,10 @@ namespace Substrate.Entities set { _zTile = (short)value; } } - public bool IsInTile + public int InTile { - get { return _inTile == 1; } - set { _inTile = (byte)(value ? 1 : 0); } + get { return _inTile; } + set { _inTile = (byte)value; } } public int Shake diff --git a/Substrate/SubstrateCS/Source/Entities/EntityXPOrb.cs b/Substrate/SubstrateCS/Source/Entities/EntityXPOrb.cs new file mode 100644 index 0000000..9fd253d --- /dev/null +++ b/Substrate/SubstrateCS/Source/Entities/EntityXPOrb.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.Entities +{ + using Substrate.Nbt; + + public class EntityXPOrb : TypedEntity + { + public static readonly SchemaNodeCompound XPOrbSchema = TypedEntity.Schema.MergeInto(new SchemaNodeCompound("") + { + new SchemaNodeScaler("Health", TagType.TAG_SHORT), + new SchemaNodeScaler("Age", TagType.TAG_SHORT), + new SchemaNodeScaler("Value", TagType.TAG_SHORT), + }); + + private short _health; + private short _age; + private short _value; + + public int Health + { + get { return _health; } + set { _health = (short)(value & 0xFF); } + } + + public int Age + { + get { return _age; } + set { _age = (short)value; } + } + + public int Value + { + get { return _value; } + set { _value = (short)value; } + } + + public EntityXPOrb (string id) + : base(id) + { + } + + public EntityXPOrb (TypedEntity e) + : base(e) + { + EntityXPOrb e2 = e as EntityXPOrb; + if (e2 != null) { + _health = e2._health; + _age = e2._age; + _value = e2._value; + } + } + + + #region INBTObject Members + + public override TypedEntity LoadTree (TagNode tree) + { + TagNodeCompound ctree = tree as TagNodeCompound; + if (ctree == null || base.LoadTree(tree) == null) { + return null; + } + + _health = ctree["Health"].ToTagShort(); + _age = ctree["Age"].ToTagShort(); + _value = ctree["Value"].ToTagShort(); + + return this; + } + + public override TagNode BuildTree () + { + TagNodeCompound tree = base.BuildTree() as TagNodeCompound; + tree["Health"] = new TagNodeShort(_health); + tree["Age"] = new TagNodeShort(_age); + tree["Value"] = new TagNodeShort(_value); + + return tree; + } + + public override bool ValidateTree (TagNode tree) + { + return new NbtVerifier(tree, XPOrbSchema).Verify(); + } + + #endregion + + + #region ICopyable Members + + public override TypedEntity Copy () + { + return new EntityXPOrb(this); + } + + #endregion + } +} diff --git a/Substrate/SubstrateCS/Source/EntityFactory.cs b/Substrate/SubstrateCS/Source/EntityFactory.cs index b73a20c..b6984bd 100644 --- a/Substrate/SubstrateCS/Source/EntityFactory.cs +++ b/Substrate/SubstrateCS/Source/EntityFactory.cs @@ -81,10 +81,12 @@ namespace Substrate { _registry["Arrow"] = typeof(EntityArrow); _registry["Boat"] = typeof(EntityBoat); + _registry["CaveSpider"] = typeof(EntityCaveSpider); _registry["Chicken"] = typeof(EntityChicken); _registry["Cow"] = typeof(EntityCow); _registry["Creeper"] = typeof(EntityCreeper); _registry["Egg"] = typeof(EntityEgg); + _registry["Enderman"] = typeof(EntityEnderman); _registry["FallingSand"] = typeof(EntityFallingSand); _registry["Ghast"] = typeof(EntityGhast); _registry["Giant"] = typeof(EntityGiant); @@ -97,12 +99,14 @@ namespace Substrate _registry["PigZombie"] = typeof(EntityPigZombie); _registry["PrimedTnt"] = typeof(EntityPrimedTnt); _registry["Sheep"] = typeof(EntitySheep); + _registry["Silverfish"] = typeof(EntitySilverfish); _registry["Skeleton"] = typeof(EntitySkeleton); _registry["Slime"] = typeof(EntitySlime); _registry["Snowball"] = typeof(EntitySnowball); _registry["Spider"] = typeof(EntitySpider); _registry["Squid"] = typeof(EntitySquid); _registry["Wolf"] = typeof(EntityWolf); + _registry["XPOrb"] = typeof(EntityXPOrb); _registry["Zombie"] = typeof(EntityZombie); } } diff --git a/Substrate/SubstrateCS/Substrate.csproj b/Substrate/SubstrateCS/Substrate.csproj index 9bc519f..51164ce 100644 --- a/Substrate/SubstrateCS/Substrate.csproj +++ b/Substrate/SubstrateCS/Substrate.csproj @@ -70,6 +70,10 @@ + + + +