Entity updates, including 1.8 entities and additional fields in some existing entities.

This commit is contained in:
Justin Aquadro 2011-09-21 04:38:34 +00:00
parent a84ed77ce1
commit 77f9519ba2
10 changed files with 421 additions and 5 deletions

View file

@ -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)]

View file

@ -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<Entity> 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();

View file

@ -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<Entity> Members
public override bool ValidateTree (TagNode tree)
{
return new NbtVerifier(tree, CaveSpiderSchema).Verify();
}
#endregion
#region ICopyable<Entity> Members
public override TypedEntity Copy ()
{
return new EntityCaveSpider(this);
}
#endregion
}
}

View file

@ -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<Entity> 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<Entity> Members
public override TypedEntity Copy ()
{
return new EntityEnderman(this);
}
#endregion
}
}

View file

@ -6,6 +6,34 @@ namespace Substrate.Entities
{
using Substrate.Nbt;
/// <summary>
/// Encompasses data in the "ActiveEffects" compound attribute of mob entity types
/// </summary>
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;
}

View file

@ -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<Entity> 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<Entity> Members
public override TypedEntity Copy ()
{
return new EntitySilverfish(this);
}
#endregion
}
}

View file

@ -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

View file

@ -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<Entity> 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<Entity> Members
public override TypedEntity Copy ()
{
return new EntityXPOrb(this);
}
#endregion
}
}

View file

@ -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);
}
}

View file

@ -70,6 +70,10 @@
<Compile Include="Source\Core\OpenWorldEvent.cs" />
<Compile Include="Source\Core\RegionInterface.cs" />
<Compile Include="Source\Core\UnboundedBlockInterface.cs" />
<Compile Include="Source\Entities\EntityCaveSpider.cs" />
<Compile Include="Source\Entities\EntityEnderman.cs" />
<Compile Include="Source\Entities\EntitySilverfish.cs" />
<Compile Include="Source\Entities\EntityXPOrb.cs" />
<Compile Include="Source\ImportExport\Schematic.cs" />
<Compile Include="Source\LevelIOException.cs" />
<Compile Include="Source\AlphaBlock.cs" />