NBT type renaming. Added more casting options to NBT Value types.

This commit is contained in:
Justin Aquadro 2011-04-09 02:50:42 +00:00
parent 5234915d9a
commit 3d0caa7a28
48 changed files with 977 additions and 806 deletions

View file

@ -119,19 +119,19 @@ namespace NBToolkit
Chunk c = chunk.GetChunkRef();
if (!opt._dumpBlocks) {
c.Tree.Root["Level"].ToNBTCompound().Remove("Blocks");
c.Tree.Root["Level"].ToNBTCompound().Remove("Data");
c.Tree.Root["Level"].ToNBTCompound().Remove("BlockLight");
c.Tree.Root["Level"].ToNBTCompound().Remove("SkyLight");
c.Tree.Root["Level"].ToNBTCompound().Remove("HeightMap");
c.Tree.Root["Level"].ToTagCompound().Remove("Blocks");
c.Tree.Root["Level"].ToTagCompound().Remove("Data");
c.Tree.Root["Level"].ToTagCompound().Remove("BlockLight");
c.Tree.Root["Level"].ToTagCompound().Remove("SkyLight");
c.Tree.Root["Level"].ToTagCompound().Remove("HeightMap");
}
if (!opt._dumpEntities) {
c.Tree.Root["Level"].ToNBTCompound().Remove("Entities");
c.Tree.Root["Level"].ToTagCompound().Remove("Entities");
}
if (!opt._dumpTileEntities) {
c.Tree.Root["Level"].ToNBTCompound().Remove("TileEntities");
c.Tree.Root["Level"].ToTagCompound().Remove("TileEntities");
}
string s = JSONSerializer.Serialize(c.Tree.Root["Level"], 1);

View file

@ -18,12 +18,12 @@ namespace Substrate
new NBTArrayNode("SkyLight", 16384),
new NBTArrayNode("BlockLight", 16384),
new NBTArrayNode("HeightMap", 256),
new NBTListNode("Entities", NBT_Type.TAG_COMPOUND),
new NBTListNode("TileEntities", NBT_Type.TAG_COMPOUND, TileEntity.BaseSchema),
new NBTScalerNode("LastUpdate", NBT_Type.TAG_LONG),
new NBTScalerNode("xPos", NBT_Type.TAG_INT),
new NBTScalerNode("zPos", NBT_Type.TAG_INT),
new NBTScalerNode("TerrainPopulated", NBT_Type.TAG_BYTE),
new NBTListNode("Entities", TagType.TAG_COMPOUND),
new NBTListNode("TileEntities", TagType.TAG_COMPOUND, TileEntity.BaseSchema),
new NBTScalerNode("LastUpdate", TagType.TAG_LONG),
new NBTScalerNode("xPos", TagType.TAG_INT),
new NBTScalerNode("zPos", TagType.TAG_INT),
new NBTScalerNode("TerrainPopulated", TagType.TAG_BYTE),
},
};
@ -32,16 +32,16 @@ namespace Substrate
private int _cx;
private int _cz;
protected NBT_ByteArray _blocks;
protected TagByteArray _blocks;
protected NibbleArray _data;
protected NibbleArray _blockLight;
protected NibbleArray _skyLight;
protected NBT_ByteArray _heightMap;
protected TagByteArray _heightMap;
protected NBT_List _entities;
protected NBT_List _tileEntities;
protected TagList _entities;
protected TagList _tileEntities;
protected Dictionary<BlockKey, NBT_Compound> _tileEntityTable;
protected Dictionary<BlockKey, TagCompound> _tileEntityTable;
public int X
{
@ -60,8 +60,8 @@ namespace Substrate
public bool IsTerrainPopulated
{
get { return _tree.Root["Level"].ToNBTCompound()["TerrainPopulated"].ToNBTByte() == 1; }
set { _tree.Root["Level"].ToNBTCompound()["TerrainPopulated"].ToNBTByte().Data = (byte)(value ? 1 : 0); }
get { return _tree.Root["Level"].ToTagCompound()["TerrainPopulated"].ToTagByte() == 1; }
set { _tree.Root["Level"].ToTagCompound()["TerrainPopulated"].ToTagByte().Data = (byte)(value ? 1 : 0); }
}
public Chunk (int x, int z)
@ -86,19 +86,19 @@ namespace Substrate
int elements2 = XDim * ZDim;
int elements3 = elements2 *YDim;
_blocks = new NBT_ByteArray(new byte[elements3]);
NBT_ByteArray data = new NBT_ByteArray(new byte[elements3 >> 1]);
NBT_ByteArray blocklight = new NBT_ByteArray(new byte[elements3 >> 1]);
NBT_ByteArray skylight = new NBT_ByteArray(new byte[elements3 >> 1]);
_heightMap = new NBT_ByteArray(new byte[elements2]);
_entities = new NBT_List(NBT_Type.TAG_COMPOUND);
_tileEntities = new NBT_List(NBT_Type.TAG_COMPOUND);
_blocks = new TagByteArray(new byte[elements3]);
TagByteArray data = new TagByteArray(new byte[elements3 >> 1]);
TagByteArray blocklight = new TagByteArray(new byte[elements3 >> 1]);
TagByteArray skylight = new TagByteArray(new byte[elements3 >> 1]);
_heightMap = new TagByteArray(new byte[elements2]);
_entities = new TagList(TagType.TAG_COMPOUND);
_tileEntities = new TagList(TagType.TAG_COMPOUND);
_data = new NibbleArray(data.Data);
_blockLight = new NibbleArray(blocklight.Data);
_skyLight = new NibbleArray(skylight.Data);
NBT_Compound level = new NBT_Compound();
TagCompound level = new TagCompound();
level.Add("Blocks", _blocks);
level.Add("Data", data);
level.Add("SkyLight", blocklight);
@ -106,10 +106,10 @@ namespace Substrate
level.Add("HeightMap", _heightMap);
level.Add("Entities", _entities);
level.Add("TileEntities", _tileEntities);
level.Add("LastUpdate", new NBT_Long());
level.Add("xPos", new NBT_Int());
level.Add("zPos", new NBT_Int());
level.Add("TerrainPopulated", new NBT_Byte());
level.Add("LastUpdate", new TagLong());
level.Add("xPos", new TagInt());
level.Add("zPos", new TagInt());
level.Add("TerrainPopulated", new TagByte());
_tree = new NBT_Tree();
_tree.Root.Add("Level", level);
@ -243,12 +243,12 @@ namespace Substrate
private void BuildTileEntityCache ()
{
_tileEntityTable = new Dictionary<BlockKey, NBT_Compound>();
_tileEntityTable = new Dictionary<BlockKey, TagCompound>();
foreach (NBT_Compound te in _tileEntities) {
int tex = te["x"].ToNBTInt();
int tey = te["y"].ToNBTInt();
int tez = te["z"].ToNBTInt();
foreach (TagCompound te in _tileEntities) {
int tex = te["x"].ToTagInt();
int tey = te["y"].ToTagInt();
int tez = te["z"].ToTagInt();
BlockKey key = new BlockKey(tex, tey, tez);
_tileEntityTable[key] = te;
@ -497,7 +497,7 @@ namespace Substrate
int z = BlockGlobalZ(lz);
BlockKey key = new BlockKey(x, y, z);
NBT_Compound te;
TagCompound te;
if (!_tileEntityTable.TryGetValue(key, out te)) {
return null;
@ -522,7 +522,7 @@ namespace Substrate
int z = BlockGlobalZ(lz);
BlockKey key = new BlockKey(x, y, z);
NBT_Compound oldte;
TagCompound oldte;
if (_tileEntityTable.TryGetValue(key, out oldte)) {
_tileEntities.Remove(oldte);
@ -532,7 +532,7 @@ namespace Substrate
te.Y = y;
te.Z = z;
NBT_Compound tree = te.BuildTree() as NBT_Compound;
TagCompound tree = te.BuildTree() as TagCompound;
_tileEntities.Add(tree);
_tileEntityTable[key] = tree;
@ -547,7 +547,7 @@ namespace Substrate
int z = BlockGlobalZ(lz);
BlockKey key = new BlockKey(x, y, z);
NBT_Compound te;
TagCompound te;
if (!_tileEntityTable.TryGetValue(key, out te)) {
return false;
@ -574,46 +574,46 @@ namespace Substrate
#region INBTObject<Chunk> Members
public Chunk LoadTree (NBT_Value tree)
public Chunk LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null) {
return null;
}
_tree = new NBT_Tree(ctree);
NBT_Compound level = _tree.Root["Level"] as NBT_Compound;
TagCompound level = _tree.Root["Level"] as TagCompound;
_blocks = level["Blocks"] as NBT_ByteArray;
_data = new NibbleArray(level["Data"].ToNBTByteArray().Data);
_blockLight = new NibbleArray(level["BlockLight"].ToNBTByteArray().Data);
_skyLight = new NibbleArray(level["SkyLight"].ToNBTByteArray().Data);
_heightMap = level["HeightMap"] as NBT_ByteArray;
_blocks = level["Blocks"] as TagByteArray;
_data = new NibbleArray(level["Data"].ToTagByteArray().Data);
_blockLight = new NibbleArray(level["BlockLight"].ToTagByteArray().Data);
_skyLight = new NibbleArray(level["SkyLight"].ToTagByteArray().Data);
_heightMap = level["HeightMap"] as TagByteArray;
_entities = level["Entities"] as NBT_List;
_tileEntities = level["TileEntities"] as NBT_List;
_entities = level["Entities"] as TagList;
_tileEntities = level["TileEntities"] as TagList;
// List-type patch up
if (_entities.Count == 0) {
level["Entities"] = new NBT_List(NBT_Type.TAG_COMPOUND);
_entities = level["Entities"] as NBT_List;
level["Entities"] = new TagList(TagType.TAG_COMPOUND);
_entities = level["Entities"] as TagList;
}
if (_tileEntities.Count == 0) {
level["TileEntities"] = new NBT_List(NBT_Type.TAG_COMPOUND);
_tileEntities = level["TileEntities"] as NBT_List;
level["TileEntities"] = new TagList(TagType.TAG_COMPOUND);
_tileEntities = level["TileEntities"] as TagList;
}
_cx = level["xPos"].ToNBTInt();
_cz = level["zPos"].ToNBTInt();
_cx = level["xPos"].ToTagInt();
_cz = level["zPos"].ToTagInt();
BuildTileEntityCache();
return this;
}
public Chunk LoadTreeSafe (NBT_Value tree)
public Chunk LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -622,12 +622,12 @@ namespace Substrate
return LoadTree(tree);
}
public NBT_Value BuildTree ()
public TagValue BuildTree ()
{
return _tree.Root;
}
public bool ValidateTree (NBT_Value tree)
public bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, LevelSchema).Verify();
}
@ -641,13 +641,13 @@ namespace Substrate
{
List<Entity> set = new List<Entity>();
foreach (NBT_Compound ent in _entities) {
NBT_Value eid;
foreach (TagCompound ent in _entities) {
TagValue eid;
if (!ent.TryGetValue("id", out eid)) {
continue;
}
if (eid.ToNBTString().Data != id) {
if (eid.ToTagString().Data != id) {
continue;
}
@ -664,7 +664,7 @@ namespace Substrate
{
List<Entity> set = new List<Entity>();
foreach (NBT_Compound ent in _entities) {
foreach (TagCompound ent in _entities) {
Entity obj = EntityFactory.Create(ent);
if (obj == null) {
continue;
@ -697,24 +697,24 @@ namespace Substrate
public int RemoveEntities (string id)
{
return _entities.RemoveAll(val => {
NBT_Compound cval = val as NBT_Compound;
TagCompound cval = val as TagCompound;
if (cval == null) {
return false;
}
NBT_Value sval;
TagValue sval;
if (!cval.TryGetValue("id", out sval)) {
return false;
}
return (sval.ToNBTString().Data == id);
return (sval.ToTagString().Data == id);
});
}
public int RemoveEntities (Predicate<Entity> match)
{
return _entities.RemoveAll(val => {
NBT_Compound cval = val as NBT_Compound;
TagCompound cval = val as TagCompound;
if (cval == null) {
return false;
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ArrowSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, BoatSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ChickenSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, CowSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, CreeperSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, EggSchema).Verify();
}

View file

@ -11,7 +11,7 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode FallingSandSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "FallingSand"),
new NBTScalerNode("Tile", NBT_Type.TAG_BYTE),
new NBTScalerNode("Tile", TagType.TAG_BYTE),
});
private byte _tile;
@ -39,27 +39,27 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_tile = ctree["Tile"].ToNBTByte();
_tile = ctree["Tile"].ToTagByte();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Tile"] = new NBT_Byte(_tile);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Tile"] = new TagByte(_tile);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, FallingSandSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, GhastSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, GiantSchema).Verify();
}

View file

@ -11,8 +11,8 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode ItemSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Item"),
new NBTScalerNode("Health", NBT_Type.TAG_SHORT),
new NBTScalerNode("Age", NBT_Type.TAG_SHORT),
new NBTScalerNode("Health", TagType.TAG_SHORT),
new NBTScalerNode("Age", TagType.TAG_SHORT),
new NBTCompoundNode("Item", Item.ItemSchema),
});
@ -58,32 +58,32 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_health = ctree["Health"].ToNBTShort();
_age = ctree["Age"].ToNBTShort();
_health = ctree["Health"].ToTagShort();
_age = ctree["Age"].ToTagShort();
_item = new Item().LoadTree(ctree["Item"]);
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Health"] = new NBT_Short(_health);
tree["Age"] = new NBT_Short(_age);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Health"] = new TagShort(_health);
tree["Age"] = new TagShort(_age);
tree["Item"] = _item.BuildTree();
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ItemSchema).Verify();
}

View file

@ -18,7 +18,7 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode MinecartSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Minecart"),
new NBTScalerNode("Type", NBT_Type.TAG_BYTE),
new NBTScalerNode("Type", TagType.TAG_BYTE),
});
private CartType _type;
@ -45,14 +45,14 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_type = (CartType)ctree["Type"].ToNBTByte().Data;
_type = (CartType)ctree["Type"].ToTagByte().Data;
switch (_type) {
case CartType.EMPTY:
@ -66,15 +66,15 @@ namespace Substrate.Entities
}
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Type"] = new NBT_Byte((byte)_type);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Type"] = new TagByte((byte)_type);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, MinecartSchema).Verify();
}

View file

@ -10,7 +10,7 @@ namespace Substrate.Entities
{
public static readonly NBTCompoundNode MinecartChestSchema = MinecartSchema.MergeInto(new NBTCompoundNode("")
{
new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.InventorySchema),
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
});
private static int _CAPACITY = 27;
@ -44,28 +44,28 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
NBT_List items = ctree["Items"].ToNBTList();
TagList items = ctree["Items"].ToTagList();
_items = _items.LoadTree(items);
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
TagCompound tree = base.BuildTree() as TagCompound;
tree["Items"] = _items.BuildTree();
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, MinecartChestSchema).Verify();
}

View file

@ -10,9 +10,9 @@ namespace Substrate.Entities
{
public static readonly NBTCompoundNode MinecartFurnaceSchema = MinecartSchema.MergeInto(new NBTCompoundNode("")
{
new NBTScalerNode("PushX", NBT_Type.TAG_DOUBLE),
new NBTScalerNode("PushZ", NBT_Type.TAG_DOUBLE),
new NBTScalerNode("Fuel", NBT_Type.TAG_SHORT),
new NBTScalerNode("PushX", TagType.TAG_DOUBLE),
new NBTScalerNode("PushZ", TagType.TAG_DOUBLE),
new NBTScalerNode("Fuel", TagType.TAG_SHORT),
});
private double _pushX;
@ -56,31 +56,31 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_pushX = ctree["PushX"].ToNBTDouble();
_pushZ = ctree["PushZ"].ToNBTDouble();
_fuel = ctree["Fuel"].ToNBTShort();
_pushX = ctree["PushX"].ToTagDouble();
_pushZ = ctree["PushZ"].ToTagDouble();
_fuel = ctree["Fuel"].ToTagShort();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["PushX"] = new NBT_Double(_pushX);
tree["PushZ"] = new NBT_Double(_pushZ);
tree["Fuel"] = new NBT_Short(_fuel);
TagCompound tree = base.BuildTree() as TagCompound;
tree["PushX"] = new TagDouble(_pushX);
tree["PushZ"] = new TagDouble(_pushZ);
tree["Fuel"] = new TagShort(_fuel);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, MinecartFurnaceSchema).Verify();
}

View file

@ -11,10 +11,10 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode MobSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Mob"),
new NBTScalerNode("AttackTime", NBT_Type.TAG_SHORT),
new NBTScalerNode("DeathTime", NBT_Type.TAG_SHORT),
new NBTScalerNode("Health", NBT_Type.TAG_SHORT),
new NBTScalerNode("HurtTime", NBT_Type.TAG_SHORT),
new NBTScalerNode("AttackTime", TagType.TAG_SHORT),
new NBTScalerNode("DeathTime", TagType.TAG_SHORT),
new NBTScalerNode("Health", TagType.TAG_SHORT),
new NBTScalerNode("HurtTime", TagType.TAG_SHORT),
});
private short _attackTime;
@ -71,33 +71,33 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_attackTime = ctree["AttackTime"].ToNBTShort();
_deathTime = ctree["DeathTime"].ToNBTShort();
_health = ctree["Health"].ToNBTShort();
_hurtTime = ctree["HurtTime"].ToNBTShort();
_attackTime = ctree["AttackTime"].ToTagShort();
_deathTime = ctree["DeathTime"].ToTagShort();
_health = ctree["Health"].ToTagShort();
_hurtTime = ctree["HurtTime"].ToTagShort();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["AttackTime"] = new NBT_Short(_attackTime);
tree["DeathTime"] = new NBT_Short(_deathTime);
tree["Health"] = new NBT_Short(_health);
tree["HurtTime"] = new NBT_Short(_hurtTime);
TagCompound tree = base.BuildTree() as TagCompound;
tree["AttackTime"] = new TagShort(_attackTime);
tree["DeathTime"] = new TagShort(_deathTime);
tree["Health"] = new TagShort(_health);
tree["HurtTime"] = new TagShort(_hurtTime);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, MobSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, MonsterSchema).Verify();
}

View file

@ -19,11 +19,11 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode PaintingSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Painting"),
new NBTScalerNode("Dir", NBT_Type.TAG_BYTE),
new NBTScalerNode("TileX", NBT_Type.TAG_SHORT),
new NBTScalerNode("TileY", NBT_Type.TAG_SHORT),
new NBTScalerNode("TileZ", NBT_Type.TAG_SHORT),
new NBTScalerNode("Motive", NBT_Type.TAG_STRING),
new NBTScalerNode("Dir", TagType.TAG_BYTE),
new NBTScalerNode("TileX", TagType.TAG_SHORT),
new NBTScalerNode("TileY", TagType.TAG_SHORT),
new NBTScalerNode("TileZ", TagType.TAG_SHORT),
new NBTScalerNode("Motive", TagType.TAG_STRING),
});
private DirectionType _dir;
@ -83,35 +83,35 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_dir = (DirectionType) ctree["Dir"].ToNBTByte().Data;
_motive = ctree["Motive"].ToNBTString();
_xTile = ctree["TileX"].ToNBTShort();
_yTile = ctree["TileY"].ToNBTShort();
_zTile = ctree["TileZ"].ToNBTShort();
_dir = (DirectionType) ctree["Dir"].ToTagByte().Data;
_motive = ctree["Motive"].ToTagString();
_xTile = ctree["TileX"].ToTagShort();
_yTile = ctree["TileY"].ToTagShort();
_zTile = ctree["TileZ"].ToTagShort();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Dir"] = new NBT_Byte((byte)_dir);
tree["Motive"] = new NBT_String(_motive);
tree["TileX"] = new NBT_Short(_xTile);
tree["TileY"] = new NBT_Short(_yTile);
tree["TileZ"] = new NBT_Short(_zTile);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Dir"] = new TagByte((byte)_dir);
tree["Motive"] = new TagString(_motive);
tree["TileX"] = new TagShort(_xTile);
tree["TileY"] = new TagShort(_yTile);
tree["TileZ"] = new TagShort(_zTile);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, PaintingSchema).Verify();
}

View file

@ -11,7 +11,7 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode PigSchema = MobSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Pig"),
new NBTScalerNode("Saddle", NBT_Type.TAG_BYTE),
new NBTScalerNode("Saddle", TagType.TAG_BYTE),
});
private bool _saddle;
@ -39,27 +39,27 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_saddle = ctree["Saddle"].ToNBTByte() == 1;
_saddle = ctree["Saddle"].ToTagByte() == 1;
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Saddle"] = new NBT_Byte((byte)(_saddle ? 1 : 0));
TagCompound tree = base.BuildTree() as TagCompound;
tree["Saddle"] = new TagByte((byte)(_saddle ? 1 : 0));
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, PigSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, PigZombieSchema).Verify();
}

View file

@ -11,7 +11,7 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode PrimedTntSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "PrimedTnt"),
new NBTScalerNode("Fuse", NBT_Type.TAG_BYTE),
new NBTScalerNode("Fuse", TagType.TAG_BYTE),
});
private byte _fuse;
@ -39,27 +39,27 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_fuse = ctree["Fuse"].ToNBTByte();
_fuse = ctree["Fuse"].ToTagByte();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Fuse"] = new NBT_Byte(_fuse);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Fuse"] = new TagByte(_fuse);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, PrimedTntSchema).Verify();
}

View file

@ -11,8 +11,8 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode SheepSchema = MobSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Sheep"),
new NBTScalerNode("Sheared", NBT_Type.TAG_BYTE),
new NBTScalerNode("Color", NBT_Type.TAG_BYTE, NBTOptions.CREATE_ON_MISSING),
new NBTScalerNode("Sheared", TagType.TAG_BYTE),
new NBTScalerNode("Color", TagType.TAG_BYTE, NBTOptions.CREATE_ON_MISSING),
});
private bool _sheared;
@ -48,29 +48,29 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_sheared = ctree["Sheared"].ToNBTByte() == 1;
_color = ctree["Color"].ToNBTByte();
_sheared = ctree["Sheared"].ToTagByte() == 1;
_color = ctree["Color"].ToTagByte();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Sheared"] = new NBT_Byte((byte)(_sheared ? 1 : 0));
tree["Color"] = new NBT_Byte(_color);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Sheared"] = new TagByte((byte)(_sheared ? 1 : 0));
tree["Color"] = new TagByte(_color);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, SheepSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, SkeletonSchema).Verify();
}

View file

@ -11,7 +11,7 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode SlimeSchema = MobSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Slime"),
new NBTScalerNode("Size", NBT_Type.TAG_INT),
new NBTScalerNode("Size", TagType.TAG_INT),
});
private int _size;
@ -39,27 +39,27 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_size = ctree["Size"].ToNBTInt();
_size = ctree["Size"].ToTagInt();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Size"] = new NBT_Int(_size);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Size"] = new TagInt(_size);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, SlimeSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, SnowballSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, SpiderSchema).Verify();
}

View file

@ -10,12 +10,12 @@ namespace Substrate.Entities
{
public static readonly NBTCompoundNode ThrowableSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTScalerNode("xTile", NBT_Type.TAG_SHORT),
new NBTScalerNode("yTile", NBT_Type.TAG_SHORT),
new NBTScalerNode("zTile", NBT_Type.TAG_SHORT),
new NBTScalerNode("inTile", NBT_Type.TAG_BYTE),
new NBTScalerNode("shake", NBT_Type.TAG_BYTE),
new NBTScalerNode("inGround", NBT_Type.TAG_BYTE),
new NBTScalerNode("xTile", TagType.TAG_SHORT),
new NBTScalerNode("yTile", TagType.TAG_SHORT),
new NBTScalerNode("zTile", TagType.TAG_SHORT),
new NBTScalerNode("inTile", TagType.TAG_BYTE),
new NBTScalerNode("shake", TagType.TAG_BYTE),
new NBTScalerNode("inGround", TagType.TAG_BYTE),
});
private short _xTile;
@ -83,37 +83,37 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_xTile = ctree["xTile"].ToNBTShort();
_yTile = ctree["yTile"].ToNBTShort();
_zTile = ctree["zTile"].ToNBTShort();
_inTile = ctree["inTile"].ToNBTByte();
_shake = ctree["shake"].ToNBTByte();
_inGround = ctree["inGround"].ToNBTByte();
_xTile = ctree["xTile"].ToTagShort();
_yTile = ctree["yTile"].ToTagShort();
_zTile = ctree["zTile"].ToTagShort();
_inTile = ctree["inTile"].ToTagByte();
_shake = ctree["shake"].ToTagByte();
_inGround = ctree["inGround"].ToTagByte();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["xTile"] = new NBT_Short(_xTile);
tree["yTile"] = new NBT_Short(_yTile);
tree["zTile"] = new NBT_Short(_zTile);
tree["inTile"] = new NBT_Byte(_inTile);
tree["shake"] = new NBT_Byte(_shake);
tree["inGround"] = new NBT_Byte(_inGround);
TagCompound tree = base.BuildTree() as TagCompound;
tree["xTile"] = new TagShort(_xTile);
tree["yTile"] = new TagShort(_yTile);
tree["zTile"] = new TagShort(_zTile);
tree["inTile"] = new TagByte(_inTile);
tree["shake"] = new TagByte(_shake);
tree["inGround"] = new TagByte(_inGround);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ThrowableSchema).Verify();
}

View file

@ -11,9 +11,9 @@ namespace Substrate.Entities
public static readonly NBTCompoundNode WolfSchema = MobSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Wolf"),
new NBTScalerNode("Owner", NBT_Type.TAG_STRING),
new NBTScalerNode("Sitting", NBT_Type.TAG_BYTE),
new NBTScalerNode("Angry", NBT_Type.TAG_BYTE),
new NBTScalerNode("Owner", TagType.TAG_STRING),
new NBTScalerNode("Sitting", TagType.TAG_BYTE),
new NBTScalerNode("Angry", TagType.TAG_BYTE),
});
private string _owner;
@ -57,31 +57,31 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override Entity LoadTree (NBT_Value tree)
public override Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_owner = ctree["Owner"].ToNBTString();
_sitting = ctree["Sitting"].ToNBTByte() == 1;
_angry = ctree["Angry"].ToNBTByte() == 1;
_owner = ctree["Owner"].ToTagString();
_sitting = ctree["Sitting"].ToTagByte() == 1;
_angry = ctree["Angry"].ToTagByte() == 1;
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Owner"] = new NBT_String(_owner);
tree["Sitting"] = new NBT_Byte((byte)(_sitting ? 1 : 0));
tree["Angry"] = new NBT_Byte((byte)(_angry ? 1 : 0));
TagCompound tree = base.BuildTree() as TagCompound;
tree["Owner"] = new TagString(_owner);
tree["Sitting"] = new TagByte((byte)(_sitting ? 1 : 0));
tree["Angry"] = new TagByte((byte)(_angry ? 1 : 0));
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, WolfSchema).Verify();
}

View file

@ -26,7 +26,7 @@ namespace Substrate.Entities
#region INBTObject<Entity> Members
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ZombieSchema).Verify();
}

View file

@ -35,13 +35,13 @@ namespace Substrate
public static readonly NBTCompoundNode UTBaseSchema = new NBTCompoundNode("")
{
new NBTListNode("Pos", NBT_Type.TAG_DOUBLE, 3),
new NBTListNode("Motion", NBT_Type.TAG_DOUBLE, 3),
new NBTListNode("Rotation", NBT_Type.TAG_FLOAT, 2),
new NBTScalerNode("FallDistance", NBT_Type.TAG_FLOAT),
new NBTScalerNode("Fire", NBT_Type.TAG_SHORT),
new NBTScalerNode("Air", NBT_Type.TAG_SHORT),
new NBTScalerNode("OnGround", NBT_Type.TAG_BYTE),
new NBTListNode("Pos", TagType.TAG_DOUBLE, 3),
new NBTListNode("Motion", TagType.TAG_DOUBLE, 3),
new NBTListNode("Rotation", TagType.TAG_FLOAT, 2),
new NBTScalerNode("FallDistance", TagType.TAG_FLOAT),
new NBTScalerNode("Fire", TagType.TAG_SHORT),
new NBTScalerNode("Air", TagType.TAG_SHORT),
new NBTScalerNode("OnGround", TagType.TAG_BYTE),
};
private Vector3 _pos;
@ -124,38 +124,38 @@ namespace Substrate
#region INBTObject<Entity> Members
public UntypedEntity LoadTree (NBT_Value tree)
public UntypedEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null) {
return null;
}
NBT_List pos = ctree["Pos"].ToNBTList();
TagList pos = ctree["Pos"].ToTagList();
_pos = new Vector3();
_pos.X = pos[0].ToNBTDouble();
_pos.Y = pos[1].ToNBTDouble();
_pos.Z = pos[2].ToNBTDouble();
_pos.X = pos[0].ToTagDouble();
_pos.Y = pos[1].ToTagDouble();
_pos.Z = pos[2].ToTagDouble();
NBT_List motion = ctree["Motion"].ToNBTList();
TagList motion = ctree["Motion"].ToTagList();
_motion = new Vector3();
_motion.X = motion[0].ToNBTDouble();
_motion.Y = motion[1].ToNBTDouble();
_motion.Z = motion[2].ToNBTDouble();
_motion.X = motion[0].ToTagDouble();
_motion.Y = motion[1].ToTagDouble();
_motion.Z = motion[2].ToTagDouble();
NBT_List rotation = ctree["Rotation"].ToNBTList();
TagList rotation = ctree["Rotation"].ToTagList();
_rotation = new Orientation();
_rotation.Yaw = rotation[0].ToNBTFloat();
_rotation.Pitch = rotation[1].ToNBTFloat();
_rotation.Yaw = rotation[0].ToTagFloat();
_rotation.Pitch = rotation[1].ToTagFloat();
_fire = ctree["Fire"].ToNBTShort();
_air = ctree["Air"].ToNBTShort();
_onGround = ctree["OnGround"].ToNBTByte();
_fire = ctree["Fire"].ToTagShort();
_air = ctree["Air"].ToTagShort();
_onGround = ctree["OnGround"].ToTagByte();
return this;
}
public UntypedEntity LoadTreeSafe (NBT_Value tree)
public UntypedEntity LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -164,36 +164,36 @@ namespace Substrate
return LoadTree(tree);
}
public NBT_Value BuildTree ()
public TagValue BuildTree ()
{
NBT_Compound tree = new NBT_Compound();
TagCompound tree = new TagCompound();
NBT_List pos = new NBT_List(NBT_Type.TAG_DOUBLE);
pos.Add(new NBT_Double(_pos.X));
pos.Add(new NBT_Double(_pos.Y));
pos.Add(new NBT_Double(_pos.Z));
TagList pos = new TagList(TagType.TAG_DOUBLE);
pos.Add(new TagDouble(_pos.X));
pos.Add(new TagDouble(_pos.Y));
pos.Add(new TagDouble(_pos.Z));
tree["Position"] = pos;
NBT_List motion = new NBT_List(NBT_Type.TAG_DOUBLE);
motion.Add(new NBT_Double(_motion.X));
motion.Add(new NBT_Double(_motion.Y));
motion.Add(new NBT_Double(_motion.Z));
TagList motion = new TagList(TagType.TAG_DOUBLE);
motion.Add(new TagDouble(_motion.X));
motion.Add(new TagDouble(_motion.Y));
motion.Add(new TagDouble(_motion.Z));
tree["Motion"] = motion;
NBT_List rotation = new NBT_List(NBT_Type.TAG_FLOAT);
rotation.Add(new NBT_Float((float)_rotation.Yaw));
rotation.Add(new NBT_Float((float)_rotation.Pitch));
TagList rotation = new TagList(TagType.TAG_FLOAT);
rotation.Add(new TagFloat((float)_rotation.Yaw));
rotation.Add(new TagFloat((float)_rotation.Pitch));
tree["Rotation"] = rotation;
tree["FallDistance"] = new NBT_Float(_fallDistance);
tree["Fire"] = new NBT_Short(_fire);
tree["Air"] = new NBT_Short(_air);
tree["OnGround"] = new NBT_Byte(_onGround);
tree["FallDistance"] = new TagFloat(_fallDistance);
tree["Fire"] = new TagShort(_fire);
tree["Air"] = new TagShort(_air);
tree["OnGround"] = new TagByte(_onGround);
return tree;
}
public bool ValidateTree (NBT_Value tree)
public bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, UTBaseSchema).Verify();
}
@ -215,7 +215,7 @@ namespace Substrate
{
public static readonly NBTCompoundNode BaseSchema = UTBaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTScalerNode("id", NBT_Type.TAG_STRING),
new NBTScalerNode("id", TagType.TAG_STRING),
});
private string _id;
@ -240,19 +240,19 @@ namespace Substrate
#region INBTObject<Entity> Members
public virtual new Entity LoadTree (NBT_Value tree)
public virtual new Entity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_id = ctree["id"].ToNBTString();
_id = ctree["id"].ToTagString();
return this;
}
public virtual new Entity LoadTreeSafe (NBT_Value tree)
public virtual new Entity LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -261,15 +261,15 @@ namespace Substrate
return LoadTree(tree);
}
public virtual new NBT_Value BuildTree ()
public virtual new TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["id"] = new NBT_String(_id);
TagCompound tree = base.BuildTree() as TagCompound;
tree["id"] = new TagString(_id);
return tree;
}
public virtual new bool ValidateTree (NBT_Value tree)
public virtual new bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, BaseSchema).Verify();
}

View file

@ -21,15 +21,15 @@ namespace Substrate
return Activator.CreateInstance(t, new object[] { type } ) as Entity;
}
public static Entity Create (NBT_Compound tree)
public static Entity Create (TagCompound tree)
{
NBT_Value type;
TagValue type;
if (!tree.TryGetValue("id", out type)) {
return null;
}
Type t;
if (!_registry.TryGetValue(type.ToNBTString(), out t)) {
if (!_registry.TryGetValue(type.ToTagString(), out t)) {
return null;
}

View file

@ -16,9 +16,9 @@ namespace Substrate
{
public static readonly NBTCompoundNode ItemSchema = new NBTCompoundNode("")
{
new NBTScalerNode("id", NBT_Type.TAG_SHORT),
new NBTScalerNode("Damage", NBT_Type.TAG_SHORT),
new NBTScalerNode("Count", NBT_Type.TAG_BYTE),
new NBTScalerNode("id", TagType.TAG_SHORT),
new NBTScalerNode("Damage", TagType.TAG_SHORT),
new NBTScalerNode("Count", TagType.TAG_BYTE),
};
private short _id;
@ -63,21 +63,21 @@ namespace Substrate
#region INBTObject<Item> Members
public Item LoadTree (NBT_Value tree)
public Item LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null) {
return null;
}
_id = ctree["id"].ToNBTShort();
_count = ctree["Count"].ToNBTByte();
_damage = ctree["Damage"].ToNBTShort();
_id = ctree["id"].ToTagShort();
_count = ctree["Count"].ToTagByte();
_damage = ctree["Damage"].ToTagShort();
return this;
}
public Item LoadTreeSafe (NBT_Value tree)
public Item LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -86,17 +86,17 @@ namespace Substrate
return LoadTree(tree);
}
public NBT_Value BuildTree ()
public TagValue BuildTree ()
{
NBT_Compound tree = new NBT_Compound();
tree["id"] = new NBT_Short(_id);
tree["Count"] = new NBT_Byte(_count);
tree["Damage"] = new NBT_Short(_damage);
TagCompound tree = new TagCompound();
tree["id"] = new TagShort(_id);
tree["Count"] = new TagByte(_count);
tree["Damage"] = new TagShort(_damage);
return tree;
}
public bool ValidateTree (NBT_Value tree)
public bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ItemSchema).Verify();
}
@ -108,10 +108,10 @@ namespace Substrate
{
public static readonly NBTCompoundNode InventorySchema = Item.ItemSchema.MergeInto(new NBTCompoundNode("")
{
new NBTScalerNode("Slot", NBT_Type.TAG_BYTE),
new NBTScalerNode("Slot", TagType.TAG_BYTE),
});
public static readonly NBTListNode ListSchema = new NBTListNode("", NBT_Type.TAG_COMPOUND, InventorySchema);
public static readonly NBTListNode ListSchema = new NBTListNode("", TagType.TAG_COMPOUND, InventorySchema);
protected Dictionary<int, Item> _items;
protected int _capacity;
@ -180,22 +180,22 @@ namespace Substrate
#region INBTObject<ItemCollection> Members
public ItemCollection LoadTree (NBT_Value tree)
public ItemCollection LoadTree (TagValue tree)
{
NBT_List ltree = tree as NBT_List;
TagList ltree = tree as TagList;
if (ltree == null) {
return null;
}
foreach (NBT_Compound item in ltree) {
int slot = item["Slot"].ToNBTByte();
foreach (TagCompound item in ltree) {
int slot = item["Slot"].ToTagByte();
_items[slot] = new Item().LoadTree(item);
}
return this;
}
public ItemCollection LoadTreeSafe (NBT_Value tree)
public ItemCollection LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -204,20 +204,20 @@ namespace Substrate
return LoadTree(tree);
}
public NBT_Value BuildTree ()
public TagValue BuildTree ()
{
NBT_List list = new NBT_List(NBT_Type.TAG_COMPOUND);
TagList list = new TagList(TagType.TAG_COMPOUND);
foreach (KeyValuePair<int, Item> item in _items) {
NBT_Compound itemtree = item.Value.BuildTree() as NBT_Compound;
itemtree["Slot"] = new NBT_Byte((byte)item.Key);
TagCompound itemtree = item.Value.BuildTree() as TagCompound;
itemtree["Slot"] = new TagByte((byte)item.Key);
list.Add(itemtree);
}
return list;
}
public bool ValidateTree (NBT_Value tree)
public bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ListSchema).Verify();
}

View file

@ -93,16 +93,16 @@ namespace Substrate
{
new NBTCompoundNode("Data")
{
new NBTScalerNode("Time", NBT_Type.TAG_LONG),
new NBTScalerNode("LastPlayed", NBT_Type.TAG_LONG),
new NBTScalerNode("Time", TagType.TAG_LONG),
new NBTScalerNode("LastPlayed", TagType.TAG_LONG),
new NBTCompoundNode("Player", Player.PlayerSchema, NBTOptions.OPTIONAL),
new NBTScalerNode("SpawnX", NBT_Type.TAG_INT),
new NBTScalerNode("SpawnY", NBT_Type.TAG_INT),
new NBTScalerNode("SpawnZ", NBT_Type.TAG_INT),
new NBTScalerNode("SizeOnDisk", NBT_Type.TAG_LONG),
new NBTScalerNode("RandomSeed", NBT_Type.TAG_LONG),
new NBTScalerNode("version", NBT_Type.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("LevelName", NBT_Type.TAG_STRING, NBTOptions.OPTIONAL),
new NBTScalerNode("SpawnX", TagType.TAG_INT),
new NBTScalerNode("SpawnY", TagType.TAG_INT),
new NBTScalerNode("SpawnZ", TagType.TAG_INT),
new NBTScalerNode("SizeOnDisk", TagType.TAG_LONG),
new NBTScalerNode("RandomSeed", TagType.TAG_LONG),
new NBTScalerNode("version", TagType.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("LevelName", TagType.TAG_STRING, NBTOptions.OPTIONAL),
},
};
}
@ -138,7 +138,7 @@ namespace Substrate
return false;
}
new NBT_Tree(BuildTree() as NBT_Compound).WriteTo(zipstr);
new NBT_Tree(BuildTree() as TagCompound).WriteTo(zipstr);
zipstr.Close();
return true;
@ -147,41 +147,41 @@ namespace Substrate
#region INBTObject<Player> Members
public virtual Level LoadTree (NBT_Value tree)
public virtual Level LoadTree (TagValue tree)
{
NBT_Compound dtree = tree as NBT_Compound;
TagCompound dtree = tree as TagCompound;
if (dtree == null) {
return null;
}
NBT_Compound ctree = dtree["Data"].ToNBTCompound();
TagCompound ctree = dtree["Data"].ToTagCompound();
_time = ctree["Time"].ToNBTLong();
_lastPlayed = ctree["LastPlayed"].ToNBTLong();
_time = ctree["Time"].ToTagLong();
_lastPlayed = ctree["LastPlayed"].ToTagLong();
if (ctree.ContainsKey("Player")) {
_player = new Player().LoadTree(ctree["Player"]);
}
_spawnX = ctree["SpawnX"].ToNBTInt();
_spawnY = ctree["SpawnY"].ToNBTInt();
_spawnZ = ctree["SpawnZ"].ToNBTInt();
_spawnX = ctree["SpawnX"].ToTagInt();
_spawnY = ctree["SpawnY"].ToTagInt();
_spawnZ = ctree["SpawnZ"].ToTagInt();
_sizeOnDisk = ctree["SizeOnDisk"].ToNBTLong();
_randomSeed = ctree["RandomSeed"].ToNBTLong();
_sizeOnDisk = ctree["SizeOnDisk"].ToTagLong();
_randomSeed = ctree["RandomSeed"].ToTagLong();
if (ctree.ContainsKey("version")) {
_version = ctree["version"].ToNBTInt();
_version = ctree["version"].ToTagInt();
}
if (ctree.ContainsKey("LevelName")) {
_name = ctree["LevelName"].ToNBTString();
_name = ctree["LevelName"].ToTagString();
}
return this;
}
public virtual Level LoadTreeSafe (NBT_Value tree)
public virtual Level LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -190,37 +190,37 @@ namespace Substrate
return LoadTree(tree);
}
public virtual NBT_Value BuildTree ()
public virtual TagValue BuildTree ()
{
NBT_Compound data = new NBT_Compound();
data["Time"] = new NBT_Long(_time);
data["LastPlayed"] = new NBT_Long(_lastPlayed);
TagCompound data = new TagCompound();
data["Time"] = new TagLong(_time);
data["LastPlayed"] = new TagLong(_lastPlayed);
if (_player != null) {
data["Player"] = _player.BuildTree();
}
data["SpawnX"] = new NBT_Int(_spawnX);
data["SpawnY"] = new NBT_Int(_spawnY);
data["SpawnZ"] = new NBT_Int(_spawnZ);
data["SizeOnDisk"] = new NBT_Long(_sizeOnDisk);
data["RandomSeed"] = new NBT_Long(_randomSeed);
data["SpawnX"] = new TagInt(_spawnX);
data["SpawnY"] = new TagInt(_spawnY);
data["SpawnZ"] = new TagInt(_spawnZ);
data["SizeOnDisk"] = new TagLong(_sizeOnDisk);
data["RandomSeed"] = new TagLong(_randomSeed);
if (_version != null) {
data["version"] = new NBT_Int(_version ?? 0);
data["version"] = new TagInt(_version ?? 0);
}
if (_name != null) {
data["LevelName"] = new NBT_String(_name);
data["LevelName"] = new TagString(_name);
}
NBT_Compound tree = new NBT_Compound();
TagCompound tree = new TagCompound();
tree.Add("Data", data);
return tree;
}
public virtual bool ValidateTree (NBT_Value tree)
public virtual bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, LevelSchema).Verify();
}

View file

@ -6,20 +6,20 @@ namespace Substrate.NBT
{
public class JSONSerializer
{
public static string Serialize (NBT_Value tag)
public static string Serialize (TagValue tag)
{
return Serialize(tag, 0);
}
public static string Serialize (NBT_Value tag, int level)
public static string Serialize (TagValue tag, int level)
{
StringBuilder str = new StringBuilder();
if (tag.GetNBTType() == NBT_Type.TAG_COMPOUND) {
SerializeCompound(tag as NBT_Compound, str, level);
if (tag.GetTagType() == TagType.TAG_COMPOUND) {
SerializeCompound(tag as TagCompound, str, level);
}
else if (tag.GetNBTType() == NBT_Type.TAG_LIST) {
SerializeList(tag as NBT_List, str, level);
else if (tag.GetTagType() == TagType.TAG_LIST) {
SerializeList(tag as TagList, str, level);
}
else {
SerializeScaler(tag, str);
@ -28,7 +28,7 @@ namespace Substrate.NBT
return str.ToString();
}
private static void SerializeCompound (NBT_Compound tag, StringBuilder str, int level)
private static void SerializeCompound (TagCompound tag, StringBuilder str, int level)
{
if (tag.Count == 0) {
str.Append("{ }");
@ -38,7 +38,7 @@ namespace Substrate.NBT
str.AppendLine();
AddLine(str, "{", level);
IEnumerator<KeyValuePair<string, NBT_Value>> en = tag.GetEnumerator();
IEnumerator<KeyValuePair<string, TagValue>> en = tag.GetEnumerator();
bool first = true;
while (en.MoveNext()) {
if (!first) {
@ -46,14 +46,14 @@ namespace Substrate.NBT
str.AppendLine();
}
KeyValuePair<string, NBT_Value> item = en.Current;
KeyValuePair<string, TagValue> item = en.Current;
Add(str, "\"" + item.Key + "\": ", level + 1);
if (item.Value.GetNBTType() == NBT_Type.TAG_COMPOUND) {
SerializeCompound(item.Value as NBT_Compound, str, level + 1);
if (item.Value.GetTagType() == TagType.TAG_COMPOUND) {
SerializeCompound(item.Value as TagCompound, str, level + 1);
}
else if (item.Value.GetNBTType() == NBT_Type.TAG_LIST) {
SerializeList(item.Value as NBT_List, str, level + 1);
else if (item.Value.GetTagType() == TagType.TAG_LIST) {
SerializeList(item.Value as TagList, str, level + 1);
}
else {
SerializeScaler(item.Value, str);
@ -66,7 +66,7 @@ namespace Substrate.NBT
Add(str, "}", level);
}
private static void SerializeList (NBT_List tag, StringBuilder str, int level)
private static void SerializeList (TagList tag, StringBuilder str, int level)
{
if (tag.Count == 0) {
str.Append("[ ]");
@ -76,20 +76,20 @@ namespace Substrate.NBT
str.AppendLine();
AddLine(str, "[", level);
IEnumerator<NBT_Value> en = tag.GetEnumerator();
IEnumerator<TagValue> en = tag.GetEnumerator();
bool first = true;
while (en.MoveNext()) {
if (!first) {
str.Append(",");
}
NBT_Value item = en.Current;
TagValue item = en.Current;
if (item.GetNBTType() == NBT_Type.TAG_COMPOUND) {
SerializeCompound(item as NBT_Compound, str, level + 1);
if (item.GetTagType() == TagType.TAG_COMPOUND) {
SerializeCompound(item as TagCompound, str, level + 1);
}
else if (item.GetNBTType() == NBT_Type.TAG_LIST) {
SerializeList(item as NBT_List, str, level + 1);
else if (item.GetTagType() == TagType.TAG_LIST) {
SerializeList(item as TagList, str, level + 1);
}
else {
if (!first) {
@ -107,40 +107,40 @@ namespace Substrate.NBT
Add(str, "]", level);
}
private static void SerializeScaler (NBT_Value tag, StringBuilder str)
private static void SerializeScaler (TagValue tag, StringBuilder str)
{
NBT_Type type = tag.GetNBTType();
switch (tag.GetNBTType()) {
case NBT_Type.TAG_STRING:
str.Append("\"" + tag.ToNBTString().Data + "\"");
TagType type = tag.GetTagType();
switch (tag.GetTagType()) {
case TagType.TAG_STRING:
str.Append("\"" + tag.ToTagString().Data + "\"");
break;
case NBT_Type.TAG_BYTE:
str.Append(tag.ToNBTByte().Data);
case TagType.TAG_BYTE:
str.Append(tag.ToTagByte().Data);
break;
case NBT_Type.TAG_SHORT:
str.Append(tag.ToNBTShort().Data);
case TagType.TAG_SHORT:
str.Append(tag.ToTagShort().Data);
break;
case NBT_Type.TAG_INT:
str.Append(tag.ToNBTInt().Data);
case TagType.TAG_INT:
str.Append(tag.ToTagInt().Data);
break;
case NBT_Type.TAG_LONG:
str.Append(tag.ToNBTLong().Data);
case TagType.TAG_LONG:
str.Append(tag.ToTagLong().Data);
break;
case NBT_Type.TAG_FLOAT:
str.Append(tag.ToNBTFloat().Data);
case TagType.TAG_FLOAT:
str.Append(tag.ToTagFloat().Data);
break;
case NBT_Type.TAG_DOUBLE:
str.Append(tag.ToNBTDouble().Data);
case TagType.TAG_DOUBLE:
str.Append(tag.ToTagDouble().Data);
break;
case NBT_Type.TAG_BYTE_ARRAY:
str.Append(Convert.ToBase64String(tag.ToNBTByteArray().Data));
case TagType.TAG_BYTE_ARRAY:
str.Append(Convert.ToBase64String(tag.ToTagByteArray().Data));
break;
}
}

View file

@ -10,32 +10,32 @@ namespace Substrate.NBT
public interface INBTObject<T>
{
T LoadTree (NBT_Value tree);
T LoadTreeSafe (NBT_Value tree);
T LoadTree (TagValue tree);
T LoadTreeSafe (TagValue tree);
NBT_Value BuildTree ();
TagValue BuildTree ();
bool ValidateTree (NBT_Value tree);
bool ValidateTree (TagValue tree);
}
public class NBT_Tree : ICopyable<NBT_Tree>
{
private Stream _stream = null;
private NBT_Compound _root = null;
private TagCompound _root = null;
private static NBT_Null _nulltag = new NBT_Null();
private static TagNull _nulltag = new TagNull();
public NBT_Compound Root
public TagCompound Root
{
get { return _root; }
}
public NBT_Tree ()
{
_root = new NBT_Compound();
_root = new TagCompound();
}
public NBT_Tree (NBT_Compound tree)
public NBT_Tree (TagCompound tree)
{
_root = tree;
}
@ -67,59 +67,59 @@ namespace Substrate.NBT
}
}
private NBT_Value ReadValue (NBT_Type type)
private TagValue ReadValue (TagType type)
{
switch (type) {
case NBT_Type.TAG_END:
case TagType.TAG_END:
return null;
case NBT_Type.TAG_BYTE:
case TagType.TAG_BYTE:
return ReadByte();
case NBT_Type.TAG_SHORT:
case TagType.TAG_SHORT:
return ReadShort();
case NBT_Type.TAG_INT:
case TagType.TAG_INT:
return ReadInt();
case NBT_Type.TAG_LONG:
case TagType.TAG_LONG:
return ReadLong();
case NBT_Type.TAG_FLOAT:
case TagType.TAG_FLOAT:
return ReadFloat();
case NBT_Type.TAG_DOUBLE:
case TagType.TAG_DOUBLE:
return ReadDouble();
case NBT_Type.TAG_BYTE_ARRAY:
case TagType.TAG_BYTE_ARRAY:
return ReadByteArray();
case NBT_Type.TAG_STRING:
case TagType.TAG_STRING:
return ReadString();
case NBT_Type.TAG_LIST:
case TagType.TAG_LIST:
return ReadList();
case NBT_Type.TAG_COMPOUND:
case TagType.TAG_COMPOUND:
return ReadCompound();
}
throw new Exception();
}
private NBT_Value ReadByte ()
private TagValue ReadByte ()
{
int gzByte = _stream.ReadByte();
if (gzByte == -1) {
throw new NBTException(NBTException.MSG_GZIP_ENDOFSTREAM);
}
NBT_Byte val = new NBT_Byte((byte)gzByte);
TagByte val = new TagByte((byte)gzByte);
return val;
}
private NBT_Value ReadShort ()
private TagValue ReadShort ()
{
byte[] gzBytes = new byte[2];
_stream.Read(gzBytes, 0, 2);
@ -128,12 +128,12 @@ namespace Substrate.NBT
Array.Reverse(gzBytes);
}
NBT_Short val = new NBT_Short(BitConverter.ToInt16(gzBytes, 0));
TagShort val = new TagShort(BitConverter.ToInt16(gzBytes, 0));
return val;
}
private NBT_Value ReadInt ()
private TagValue ReadInt ()
{
byte[] gzBytes = new byte[4];
_stream.Read(gzBytes, 0, 4);
@ -142,12 +142,12 @@ namespace Substrate.NBT
Array.Reverse(gzBytes);
}
NBT_Int val = new NBT_Int(BitConverter.ToInt32(gzBytes, 0));
TagInt val = new TagInt(BitConverter.ToInt32(gzBytes, 0));
return val;
}
private NBT_Value ReadLong ()
private TagValue ReadLong ()
{
byte[] gzBytes = new byte[8];
_stream.Read(gzBytes, 0, 8);
@ -156,12 +156,12 @@ namespace Substrate.NBT
Array.Reverse(gzBytes);
}
NBT_Long val = new NBT_Long(BitConverter.ToInt64(gzBytes, 0));
TagLong val = new TagLong(BitConverter.ToInt64(gzBytes, 0));
return val;
}
private NBT_Value ReadFloat ()
private TagValue ReadFloat ()
{
byte[] gzBytes = new byte[4];
_stream.Read(gzBytes, 0, 4);
@ -170,12 +170,12 @@ namespace Substrate.NBT
Array.Reverse(gzBytes);
}
NBT_Float val = new NBT_Float(BitConverter.ToSingle(gzBytes, 0));
TagFloat val = new TagFloat(BitConverter.ToSingle(gzBytes, 0));
return val;
}
private NBT_Value ReadDouble ()
private TagValue ReadDouble ()
{
byte[] gzBytes = new byte[8];
_stream.Read(gzBytes, 0, 8);
@ -184,12 +184,12 @@ namespace Substrate.NBT
Array.Reverse(gzBytes);
}
NBT_Double val = new NBT_Double(BitConverter.ToDouble(gzBytes, 0));
TagDouble val = new TagDouble(BitConverter.ToDouble(gzBytes, 0));
return val;
}
private NBT_Value ReadByteArray ()
private TagValue ReadByteArray ()
{
byte[] lenBytes = new byte[4];
_stream.Read(lenBytes, 0, 4);
@ -206,12 +206,12 @@ namespace Substrate.NBT
byte[] data = new byte[length];
_stream.Read(data, 0, length);
NBT_ByteArray val = new NBT_ByteArray(data);
TagByteArray val = new TagByteArray(data);
return val;
}
private NBT_Value ReadString ()
private TagValue ReadString ()
{
byte[] lenBytes = new byte[2];
_stream.Read(lenBytes, 0, 2);
@ -230,20 +230,20 @@ namespace Substrate.NBT
System.Text.Encoding str = Encoding.GetEncoding(28591);
NBT_String val = new NBT_String(str.GetString(strBytes));
TagString val = new TagString(str.GetString(strBytes));
return val;
}
private NBT_Value ReadList ()
private TagValue ReadList ()
{
int gzByte = _stream.ReadByte();
if (gzByte == -1) {
throw new NBTException(NBTException.MSG_GZIP_ENDOFSTREAM);
}
NBT_List val = new NBT_List((NBT_Type)gzByte);
if (val.ValueType > (NBT_Type)Enum.GetValues(typeof(NBT_Type)).GetUpperBound(0)) {
TagList val = new TagList((TagType)gzByte);
if (val.ValueType > (TagType)Enum.GetValues(typeof(TagType)).GetUpperBound(0)) {
throw new NBTException(NBTException.MSG_READ_TYPE);
}
@ -266,33 +266,33 @@ namespace Substrate.NBT
return val;
}
private NBT_Value ReadCompound ()
private TagValue ReadCompound ()
{
NBT_Compound val = new NBT_Compound();
TagCompound val = new TagCompound();
while (ReadTag(val)) ;
return val;
}
private NBT_Compound ReadRoot ()
private TagCompound ReadRoot ()
{
NBT_Type type = (NBT_Type)_stream.ReadByte();
if (type == NBT_Type.TAG_COMPOUND) {
string name = ReadString().ToNBTString().Data;
return ReadValue(type) as NBT_Compound;
TagType type = (TagType)_stream.ReadByte();
if (type == TagType.TAG_COMPOUND) {
string name = ReadString().ToTagString().Data;
return ReadValue(type) as TagCompound;
}
return null;
}
private bool ReadTag (NBT_Compound parent)
private bool ReadTag (TagCompound parent)
{
//NBT_Tag tag = new NBT_Tag();
NBT_Type type = (NBT_Type)_stream.ReadByte();
if (type != NBT_Type.TAG_END) {
string name = ReadString().ToNBTString().Data;
TagType type = (TagType)_stream.ReadByte();
if (type != TagType.TAG_END) {
string name = ReadString().ToTagString().Data;
parent[name] = ReadValue(type);
return true;
}
@ -304,60 +304,60 @@ namespace Substrate.NBT
//return tag;
}
private void WriteValue (NBT_Value val)
private void WriteValue (TagValue val)
{
switch (val.GetNBTType()) {
case NBT_Type.TAG_END:
switch (val.GetTagType()) {
case TagType.TAG_END:
break;
case NBT_Type.TAG_BYTE:
WriteByte(val.ToNBTByte());
case TagType.TAG_BYTE:
WriteByte(val.ToTagByte());
break;
case NBT_Type.TAG_SHORT:
WriteShort(val.ToNBTShort());
case TagType.TAG_SHORT:
WriteShort(val.ToTagShort());
break;
case NBT_Type.TAG_INT:
WriteInt(val.ToNBTInt());
case TagType.TAG_INT:
WriteInt(val.ToTagInt());
break;
case NBT_Type.TAG_LONG:
WriteLong(val.ToNBTLong());
case TagType.TAG_LONG:
WriteLong(val.ToTagLong());
break;
case NBT_Type.TAG_FLOAT:
WriteFloat(val.ToNBTFloat());
case TagType.TAG_FLOAT:
WriteFloat(val.ToTagFloat());
break;
case NBT_Type.TAG_DOUBLE:
WriteDouble(val.ToNBTDouble());
case TagType.TAG_DOUBLE:
WriteDouble(val.ToTagDouble());
break;
case NBT_Type.TAG_BYTE_ARRAY:
WriteByteArray(val.ToNBTByteArray());
case TagType.TAG_BYTE_ARRAY:
WriteByteArray(val.ToTagByteArray());
break;
case NBT_Type.TAG_STRING:
WriteString(val.ToNBTString());
case TagType.TAG_STRING:
WriteString(val.ToTagString());
break;
case NBT_Type.TAG_LIST:
WriteList(val.ToNBTList());
case TagType.TAG_LIST:
WriteList(val.ToTagList());
break;
case NBT_Type.TAG_COMPOUND:
WriteCompound(val.ToNBTCompound());
case TagType.TAG_COMPOUND:
WriteCompound(val.ToTagCompound());
break;
}
}
private void WriteByte (NBT_Byte val)
private void WriteByte (TagByte val)
{
_stream.WriteByte(val.Data);
}
private void WriteShort (NBT_Short val)
private void WriteShort (TagShort val)
{
byte[] gzBytes = BitConverter.GetBytes(val.Data);
@ -368,7 +368,7 @@ namespace Substrate.NBT
_stream.Write(gzBytes, 0, 2);
}
private void WriteInt (NBT_Int val)
private void WriteInt (TagInt val)
{
byte[] gzBytes = BitConverter.GetBytes(val.Data);
@ -379,7 +379,7 @@ namespace Substrate.NBT
_stream.Write(gzBytes, 0, 4);
}
private void WriteLong (NBT_Long val)
private void WriteLong (TagLong val)
{
byte[] gzBytes = BitConverter.GetBytes(val.Data);
@ -390,7 +390,7 @@ namespace Substrate.NBT
_stream.Write(gzBytes, 0, 8);
}
private void WriteFloat (NBT_Float val)
private void WriteFloat (TagFloat val)
{
byte[] gzBytes = BitConverter.GetBytes(val.Data);
@ -401,7 +401,7 @@ namespace Substrate.NBT
_stream.Write(gzBytes, 0, 4);
}
private void WriteDouble (NBT_Double val)
private void WriteDouble (TagDouble val)
{
byte[] gzBytes = BitConverter.GetBytes(val.Data);
@ -412,7 +412,7 @@ namespace Substrate.NBT
_stream.Write(gzBytes, 0, 8);
}
private void WriteByteArray (NBT_ByteArray val)
private void WriteByteArray (TagByteArray val)
{
byte[] lenBytes = BitConverter.GetBytes(val.Length);
@ -424,7 +424,7 @@ namespace Substrate.NBT
_stream.Write(val.Data, 0, val.Length);
}
private void WriteString (NBT_String val)
private void WriteString (TagString val)
{
byte[] lenBytes = BitConverter.GetBytes((short)val.Length);
@ -440,7 +440,7 @@ namespace Substrate.NBT
_stream.Write(gzBytes, 0, gzBytes.Length);
}
private void WriteList (NBT_List val)
private void WriteList (TagList val)
{
byte[] lenBytes = BitConverter.GetBytes(val.Count);
@ -451,25 +451,25 @@ namespace Substrate.NBT
_stream.WriteByte((byte)val.ValueType);
_stream.Write(lenBytes, 0, 4);
foreach (NBT_Value v in val) {
foreach (TagValue v in val) {
WriteValue(v);
}
}
private void WriteCompound (NBT_Compound val)
private void WriteCompound (TagCompound val)
{
foreach (KeyValuePair<string, NBT_Value> item in val) {
foreach (KeyValuePair<string, TagValue> item in val) {
WriteTag(item.Key, item.Value);
}
WriteTag(null, _nulltag);
}
private void WriteTag (string name, NBT_Value val)
private void WriteTag (string name, TagValue val)
{
_stream.WriteByte((byte)val.GetNBTType());
_stream.WriteByte((byte)val.GetTagType());
if (val.GetNBTType() != NBT_Type.TAG_END) {
if (val.GetTagType() != TagType.TAG_END) {
WriteString(name);
WriteValue(val);
}
@ -480,7 +480,7 @@ namespace Substrate.NBT
public NBT_Tree Copy ()
{
NBT_Tree tree = new NBT_Tree();
tree._root = _root.Copy() as NBT_Compound;
tree._root = _root.Copy() as TagCompound;
return tree;
}

View file

@ -37,7 +37,7 @@ namespace Substrate.NBT
_options = options;
}
public virtual NBT_Value BuildDefaultTree ()
public virtual TagValue BuildDefaultTree ()
{
return null;
}
@ -45,48 +45,48 @@ namespace Substrate.NBT
public class NBTScalerNode : NBTSchemaNode
{
private NBT_Type _type;
private TagType _type;
public NBT_Type Type
public TagType Type
{
get { return _type; }
}
public NBTScalerNode (string name, NBT_Type type)
public NBTScalerNode (string name, TagType type)
: base(name)
{
_type = type;
}
public NBTScalerNode (string name, NBT_Type type, NBTOptions options)
public NBTScalerNode (string name, TagType type, NBTOptions options)
: base(name, options)
{
_type = type;
}
public override NBT_Value BuildDefaultTree ()
public override TagValue BuildDefaultTree ()
{
switch (_type) {
case NBT_Type.TAG_STRING:
return new NBT_String();
case TagType.TAG_STRING:
return new TagString();
case NBT_Type.TAG_BYTE:
return new NBT_Byte();
case TagType.TAG_BYTE:
return new TagByte();
case NBT_Type.TAG_SHORT:
return new NBT_Short();
case TagType.TAG_SHORT:
return new TagShort();
case NBT_Type.TAG_INT:
return new NBT_Int();
case TagType.TAG_INT:
return new TagInt();
case NBT_Type.TAG_LONG:
return new NBT_Long();
case TagType.TAG_LONG:
return new TagLong();
case NBT_Type.TAG_FLOAT:
return new NBT_Float();
case TagType.TAG_FLOAT:
return new TagFloat();
case NBT_Type.TAG_DOUBLE:
return new NBT_Double();
case TagType.TAG_DOUBLE:
return new TagDouble();
}
return null;
@ -125,13 +125,13 @@ namespace Substrate.NBT
_length = length;
}
public override NBT_Value BuildDefaultTree ()
public override TagValue BuildDefaultTree ()
{
if (_value.Length > 0) {
return new NBT_String(_value);
return new TagString(_value);
}
return new NBT_String();
return new TagString();
}
}
@ -168,15 +168,15 @@ namespace Substrate.NBT
_length = length;
}
public override NBT_Value BuildDefaultTree ()
public override TagValue BuildDefaultTree ()
{
return new NBT_ByteArray(new byte[_length]);
return new TagByteArray(new byte[_length]);
}
}
public class NBTListNode : NBTSchemaNode
{
private NBT_Type _type;
private TagType _type;
private int _length;
private NBTSchemaNode _subschema;
@ -185,7 +185,7 @@ namespace Substrate.NBT
get { return _length; }
}
public NBT_Type Type
public TagType Type
{
get { return _type; }
}
@ -195,47 +195,47 @@ namespace Substrate.NBT
get { return _subschema; }
}
public NBTListNode (string name, NBT_Type type)
public NBTListNode (string name, TagType type)
: base(name)
{
_type = type;
}
public NBTListNode (string name, NBT_Type type, NBTOptions options)
public NBTListNode (string name, TagType type, NBTOptions options)
: base(name, options)
{
_type = type;
}
public NBTListNode (string name, NBT_Type type, int length)
public NBTListNode (string name, TagType type, int length)
: base(name)
{
_type = type;
_length = length;
}
public NBTListNode (string name, NBT_Type type, int length, NBTOptions options)
public NBTListNode (string name, TagType type, int length, NBTOptions options)
: base(name, options)
{
_type = type;
_length = length;
}
public NBTListNode (string name, NBT_Type type, NBTSchemaNode subschema)
public NBTListNode (string name, TagType type, NBTSchemaNode subschema)
: base(name)
{
_type = type;
_subschema = subschema;
}
public NBTListNode (string name, NBT_Type type, NBTSchemaNode subschema, NBTOptions options)
public NBTListNode (string name, TagType type, NBTSchemaNode subschema, NBTOptions options)
: base(name, options)
{
_type = type;
_subschema = subschema;
}
public NBTListNode (string name, NBT_Type type, int length, NBTSchemaNode subschema)
public NBTListNode (string name, TagType type, int length, NBTSchemaNode subschema)
: base(name)
{
_type = type;
@ -243,7 +243,7 @@ namespace Substrate.NBT
_subschema = subschema;
}
public NBTListNode (string name, NBT_Type type, int length, NBTSchemaNode subschema, NBTOptions options)
public NBTListNode (string name, TagType type, int length, NBTSchemaNode subschema, NBTOptions options)
: base(name, options)
{
_type = type;
@ -251,13 +251,13 @@ namespace Substrate.NBT
_subschema = subschema;
}
public override NBT_Value BuildDefaultTree ()
public override TagValue BuildDefaultTree ()
{
if (_length == 0) {
return new NBT_List(_type);
return new TagList(_type);
}
NBT_List list = new NBT_List(_type);
TagList list = new TagList(_type);
for (int i = 0; i < _length; i++) {
list.Add(_subschema.BuildDefaultTree());
}
@ -395,9 +395,9 @@ namespace Substrate.NBT
return tree;
}
public override NBT_Value BuildDefaultTree ()
public override TagValue BuildDefaultTree ()
{
NBT_Compound list = new NBT_Compound();
TagCompound list = new TagCompound();
foreach (NBTSchemaNode node in _subnodes) {
list[node.Name] = node.BuildDefaultTree();
}

View file

@ -6,10 +6,7 @@ namespace Substrate.NBT {
using Substrate.Utility;
/// <summary>
/// Describes the type of value held by an NBT_Tag
/// </summary>
public enum NBT_Type
public enum TagType
{
TAG_END = 0,
TAG_BYTE = 1, // 8 bits signed
@ -24,45 +21,62 @@ namespace Substrate.NBT {
TAG_COMPOUND = 10
}
public abstract class NBT_Value : ICopyable<NBT_Value>
public abstract class TagValue : ICopyable<TagValue>
{
virtual public NBT_Null ToNBTNull () { throw new InvalidCastException(); }
virtual public NBT_Byte ToNBTByte () { throw new InvalidCastException(); }
virtual public NBT_Short ToNBTShort () { throw new InvalidCastException(); }
virtual public NBT_Int ToNBTInt () { throw new InvalidCastException(); }
virtual public NBT_Long ToNBTLong () { throw new InvalidCastException(); }
virtual public NBT_Float ToNBTFloat () { throw new InvalidCastException(); }
virtual public NBT_Double ToNBTDouble () { throw new InvalidCastException(); }
virtual public NBT_ByteArray ToNBTByteArray () { throw new InvalidCastException(); }
virtual public NBT_String ToNBTString () { throw new InvalidCastException(); }
virtual public NBT_List ToNBTList () { throw new InvalidCastException(); }
virtual public NBT_Compound ToNBTCompound () { throw new InvalidCastException(); }
public virtual TagNull ToTagNull () { throw new InvalidCastException(); }
public virtual TagByte ToTagByte () { throw new InvalidCastException(); }
public virtual TagShort ToTagShort () { throw new InvalidCastException(); }
public virtual TagInt ToTagInt () { throw new InvalidCastException(); }
public virtual TagLong ToTagLong () { throw new InvalidCastException(); }
public virtual TagFloat ToTagFloat () { throw new InvalidCastException(); }
public virtual TagDouble ToTagDouble () { throw new InvalidCastException(); }
public virtual TagByteArray ToTagByteArray () { throw new InvalidCastException(); }
public virtual TagString ToTagString () { throw new InvalidCastException(); }
public virtual TagList ToTagList () { throw new InvalidCastException(); }
public virtual TagCompound ToTagCompound () { throw new InvalidCastException(); }
virtual public NBT_Type GetNBTType () { return NBT_Type.TAG_END; }
public virtual TagType GetTagType () { return TagType.TAG_END; }
public virtual NBT_Value Copy ()
public virtual bool IsCastableTo (TagType type)
{
return type == GetTagType();
}
public virtual TagValue Copy ()
{
return null;
}
}
public class NBT_Null : NBT_Value
public class TagNull : TagValue
{
override public NBT_Null ToNBTNull () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_END; }
public override TagNull ToTagNull () { return this; }
public override TagType GetTagType () { return TagType.TAG_END; }
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_Null();
return new TagNull();
}
}
public class NBT_Byte : NBT_Value
public class TagByte : TagValue
{
private byte _data = 0;
override public NBT_Byte ToNBTByte () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_BYTE; }
public override TagByte ToTagByte () { return this; }
public override TagShort ToTagShort () { return new TagShort(_data); }
public override TagInt ToTagInt () { return new TagInt(_data); }
public override TagLong ToTagLong () { return new TagLong(_data); }
public override TagType GetTagType () { return TagType.TAG_BYTE; }
public override bool IsCastableTo (TagType type)
{
return (type == TagType.TAG_BYTE ||
type == TagType.TAG_SHORT ||
type == TagType.TAG_INT ||
type == TagType.TAG_LONG);
}
public byte Data
{
@ -70,35 +84,65 @@ namespace Substrate.NBT {
set { _data = value; }
}
public NBT_Byte () { }
public TagByte () { }
public NBT_Byte (byte d)
public TagByte (byte d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_Byte(_data);
return new TagByte(_data);
}
public static implicit operator NBT_Byte (byte b)
public override string ToString ()
{
return new NBT_Byte(b);
return _data.ToString();
}
public static implicit operator byte (NBT_Byte b)
public static implicit operator TagByte (byte b)
{
return new TagByte(b);
}
public static implicit operator byte (TagByte b)
{
return b._data;
}
public static implicit operator short (TagByte b)
{
return b._data;
}
public static implicit operator int (TagByte b)
{
return b._data;
}
public static implicit operator long (TagByte b)
{
return b._data;
}
}
public class NBT_Short : NBT_Value
public class TagShort : TagValue
{
private short _data = 0;
override public NBT_Short ToNBTShort () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_SHORT; }
public override TagShort ToTagShort () { return this; }
public override TagInt ToTagInt () { return new TagInt(_data); }
public override TagLong ToTagLong () { return new TagLong(_data); }
public override TagType GetTagType () { return TagType.TAG_SHORT; }
public override bool IsCastableTo (TagType type)
{
return (type == TagType.TAG_SHORT ||
type == TagType.TAG_INT ||
type == TagType.TAG_LONG);
}
public short Data
{
@ -106,35 +150,63 @@ namespace Substrate.NBT {
set { _data = value; }
}
public NBT_Short () { }
public TagShort () { }
public NBT_Short (short d)
public TagShort (short d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_Short(_data);
return new TagShort(_data);
}
public static implicit operator NBT_Short (short s)
public override string ToString ()
{
return new NBT_Short(s);
return _data.ToString();
}
public static implicit operator short (NBT_Short s)
public static implicit operator TagShort (byte b)
{
return new TagShort(b);
}
public static implicit operator TagShort (short s)
{
return new TagShort(s);
}
public static implicit operator short (TagShort s)
{
return s._data;
}
public static implicit operator int (TagShort s)
{
return s._data;
}
public static implicit operator long (TagShort s)
{
return s._data;
}
}
public class NBT_Int : NBT_Value
public class TagInt : TagValue
{
private int _data = 0;
override public NBT_Int ToNBTInt () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_INT; }
public override TagInt ToTagInt () { return this; }
public override TagLong ToTagLong () { return new TagLong(_data); }
public override TagType GetTagType () { return TagType.TAG_INT; }
public override bool IsCastableTo (TagType type)
{
return (type == TagType.TAG_INT ||
type == TagType.TAG_LONG);
}
public int Data
{
@ -142,35 +214,56 @@ namespace Substrate.NBT {
set { _data = value; }
}
public NBT_Int () { }
public TagInt () { }
public NBT_Int (int d)
public TagInt (int d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_Int(_data);
return new TagInt(_data);
}
public static implicit operator NBT_Int (int i)
public override string ToString ()
{
return new NBT_Int(i);
return _data.ToString();
}
public static implicit operator int (NBT_Int i)
public static implicit operator TagInt (byte b)
{
return new TagInt(b);
}
public static implicit operator TagInt (short s)
{
return new TagInt(s);
}
public static implicit operator TagInt (int i)
{
return new TagInt(i);
}
public static implicit operator int (TagInt i)
{
return i._data;
}
public static implicit operator long (TagInt i)
{
return i._data;
}
}
public class NBT_Long : NBT_Value
public class TagLong : TagValue
{
private long _data = 0;
override public NBT_Long ToNBTLong () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_LONG; }
public override TagLong ToTagLong () { return this; }
public override TagType GetTagType () { return TagType.TAG_LONG; }
public long Data
{
@ -178,35 +271,63 @@ namespace Substrate.NBT {
set { _data = value; }
}
public NBT_Long () { }
public TagLong () { }
public NBT_Long (long d)
public TagLong (long d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_Long(_data);
return new TagLong(_data);
}
public static implicit operator NBT_Long (long l)
public override string ToString ()
{
return new NBT_Long(l);
return _data.ToString();
}
public static implicit operator long (NBT_Long l)
public static implicit operator TagLong (byte b)
{
return new TagLong(b);
}
public static implicit operator TagLong (short s)
{
return new TagLong(s);
}
public static implicit operator TagLong (int i)
{
return new TagLong(i);
}
public static implicit operator TagLong (long l)
{
return new TagLong(l);
}
public static implicit operator long (TagLong l)
{
return l._data;
}
}
public class NBT_Float : NBT_Value
public class TagFloat : TagValue
{
private float _data = 0;
override public NBT_Float ToNBTFloat () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_FLOAT; }
public override TagFloat ToTagFloat () { return this; }
public override TagDouble ToTagDouble () { return new TagDouble(_data); }
public override TagType GetTagType () { return TagType.TAG_FLOAT; }
public override bool IsCastableTo (TagType type)
{
return (type == TagType.TAG_FLOAT ||
type == TagType.TAG_DOUBLE);
}
public float Data
{
@ -214,35 +335,46 @@ namespace Substrate.NBT {
set { _data = value; }
}
public NBT_Float () { }
public TagFloat () { }
public NBT_Float (float d)
public TagFloat (float d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_Float(_data);
return new TagFloat(_data);
}
public static implicit operator NBT_Float (float f)
public override string ToString ()
{
return new NBT_Float(f);
return _data.ToString();
}
public static implicit operator float (NBT_Float f)
public static implicit operator TagFloat (float f)
{
return new TagFloat(f);
}
public static implicit operator float (TagFloat f)
{
return f._data;
}
public static implicit operator double (TagFloat f)
{
return f._data;
}
}
public class NBT_Double : NBT_Value
public class TagDouble : TagValue
{
private double _data = 0;
override public NBT_Double ToNBTDouble () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_DOUBLE; }
public override TagDouble ToTagDouble () { return this; }
public override TagType GetTagType () { return TagType.TAG_DOUBLE; }
public double Data
{
@ -250,35 +382,46 @@ namespace Substrate.NBT {
set { _data = value; }
}
public NBT_Double () { }
public TagDouble () { }
public NBT_Double (double d)
public TagDouble (double d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_Double(_data);
return new TagDouble(_data);
}
public static implicit operator NBT_Double (double d)
public override string ToString ()
{
return new NBT_Double(d);
return _data.ToString();
}
public static implicit operator double (NBT_Double d)
public static implicit operator TagDouble (float f)
{
return new TagDouble(f);
}
public static implicit operator TagDouble (double d)
{
return new TagDouble(d);
}
public static implicit operator double (TagDouble d)
{
return d._data;
}
}
public class NBT_ByteArray : NBT_Value
public class TagByteArray : TagValue
{
private byte[] _data = null;
override public NBT_ByteArray ToNBTByteArray () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_BYTE_ARRAY; }
public override TagByteArray ToTagByteArray () { return this; }
public override TagType GetTagType () { return TagType.TAG_BYTE_ARRAY; }
public byte[] Data
{
@ -291,19 +434,24 @@ namespace Substrate.NBT {
get { return _data.Length; }
}
public NBT_ByteArray () { }
public TagByteArray () { }
public NBT_ByteArray (byte[] d)
public TagByteArray (byte[] d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
byte[] arr = new byte[_data.Length];
_data.CopyTo(arr, 0);
return new NBT_ByteArray(arr);
return new TagByteArray(arr);
}
public override string ToString ()
{
return _data.ToString();
}
public byte this [int index] {
@ -311,18 +459,24 @@ namespace Substrate.NBT {
set { _data[index] = value; }
}
public static implicit operator NBT_ByteArray (byte[] b)
public static implicit operator TagByteArray (byte[] b)
{
return new NBT_ByteArray(b);
return new TagByteArray(b);
}
public static implicit operator byte[] (TagByteArray b)
{
return b._data;
}
}
public class NBT_String : NBT_Value
public class TagString : TagValue
{
private string _data = "";
override public NBT_String ToNBTString () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_STRING; }
public override TagString ToTagString () { return this; }
public override TagType GetTagType () { return TagType.TAG_STRING; }
public string Data
{
@ -335,87 +489,98 @@ namespace Substrate.NBT {
get { return _data.Length; }
}
public NBT_String () { }
public TagString () { }
public NBT_String (string d)
public TagString (string d)
{
_data = d;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
return new NBT_String(_data);
return new TagString(_data);
}
public static implicit operator NBT_String (string s)
public override string ToString ()
{
return new NBT_String(s);
return _data.ToString();
}
public static implicit operator string (NBT_String s)
public static implicit operator TagString (string s)
{
return new TagString(s);
}
public static implicit operator string (TagString s)
{
return s._data;
}
}
public class NBT_List : NBT_Value, IList<NBT_Value>
public class TagList : TagValue, IList<TagValue>
{
private NBT_Type _type = NBT_Type.TAG_END;
private TagType _type = TagType.TAG_END;
private List<NBT_Value> _items = null;
private List<TagValue> _items = null;
override public NBT_List ToNBTList () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_LIST; }
public override TagList ToTagList () { return this; }
public override TagType GetTagType () { return TagType.TAG_LIST; }
public int Count
{
get { return _items.Count; }
}
public NBT_Type ValueType
public TagType ValueType
{
get { return _type; }
}
public NBT_List (NBT_Type type)
public TagList (TagType type)
{
_type = type;
_items = new List<NBT_Value>();
_items = new List<TagValue>();
}
public NBT_List (NBT_Type type, List<NBT_Value> items)
public TagList (TagType type, List<TagValue> items)
{
_type = type;
_items = items;
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
NBT_List list = new NBT_List(_type);
foreach (NBT_Value item in _items) {
TagList list = new TagList(_type);
foreach (TagValue item in _items) {
list.Add(item.Copy());
}
return list;
}
public List<NBT_Value> FindAll(Predicate<NBT_Value> match)
public List<TagValue> FindAll(Predicate<TagValue> match)
{
return _items.FindAll(match);
}
public int RemoveAll (Predicate<NBT_Value> match)
public int RemoveAll (Predicate<TagValue> match)
{
return _items.RemoveAll(match);
}
public override string ToString ()
{
return _items.ToString();
}
#region IList<NBT_Value> Members
public int IndexOf (NBT_Value item)
public int IndexOf (TagValue item)
{
return _items.IndexOf(item);
}
public void Insert (int index, NBT_Value item)
public void Insert (int index, TagValue item)
{
_items.Insert(index, item);
}
@ -425,7 +590,7 @@ namespace Substrate.NBT {
_items.RemoveAt(index);
}
public NBT_Value this[int index]
public TagValue this[int index]
{
get
{
@ -441,7 +606,7 @@ namespace Substrate.NBT {
#region ICollection<NBT_Value> Members
public void Add (NBT_Value item)
public void Add (TagValue item)
{
_items.Add(item);
}
@ -451,12 +616,12 @@ namespace Substrate.NBT {
_items.Clear();
}
public bool Contains (NBT_Value item)
public bool Contains (TagValue item)
{
return _items.Contains(item);
}
public void CopyTo (NBT_Value[] array, int arrayIndex)
public void CopyTo (TagValue[] array, int arrayIndex)
{
_items.CopyTo(array, arrayIndex);
}
@ -466,7 +631,7 @@ namespace Substrate.NBT {
get { return false; }
}
public bool Remove (NBT_Value item)
public bool Remove (TagValue item)
{
return _items.Remove(item);
}
@ -475,7 +640,7 @@ namespace Substrate.NBT {
#region IEnumerable<NBT_Value> Members
public IEnumerator<NBT_Value> GetEnumerator ()
public IEnumerator<TagValue> GetEnumerator ()
{
return _items.GetEnumerator();
}
@ -492,35 +657,41 @@ namespace Substrate.NBT {
#endregion
}
public class NBT_Compound : NBT_Value, IDictionary<string, NBT_Value>
public class TagCompound : TagValue, IDictionary<string, TagValue>
{
private Dictionary<string, NBT_Value> _tags;
private Dictionary<string, TagValue> _tags;
override public NBT_Compound ToNBTCompound () { return this; }
override public NBT_Type GetNBTType () { return NBT_Type.TAG_COMPOUND; }
public override TagCompound ToTagCompound () { return this; }
public override TagType GetTagType () { return TagType.TAG_COMPOUND; }
public int Count
{
get { return _tags.Count; }
}
public NBT_Compound ()
public TagCompound ()
{
_tags = new Dictionary<string, NBT_Value>();
_tags = new Dictionary<string, TagValue>();
}
public override NBT_Value Copy ()
public override TagValue Copy ()
{
NBT_Compound list = new NBT_Compound();
foreach (KeyValuePair<string, NBT_Value> item in _tags) {
TagCompound list = new TagCompound();
foreach (KeyValuePair<string, TagValue> item in _tags) {
list[item.Key] = item.Value.Copy();
}
return list;
}
public override string ToString ()
{
return _tags.ToString();
}
#region IDictionary<string,NBT_Value> Members
public void Add (string key, NBT_Value value)
public void Add (string key, TagValue value)
{
_tags.Add(key, value);
}
@ -540,17 +711,17 @@ namespace Substrate.NBT {
return _tags.Remove(key);
}
public bool TryGetValue (string key, out NBT_Value value)
public bool TryGetValue (string key, out TagValue value)
{
return _tags.TryGetValue(key, out value);
}
public ICollection<NBT_Value> Values
public ICollection<TagValue> Values
{
get { return _tags.Values; }
}
public NBT_Value this[string key]
public TagValue this[string key]
{
get
{
@ -566,7 +737,7 @@ namespace Substrate.NBT {
#region ICollection<KeyValuePair<string,NBT_Value>> Members
public void Add (KeyValuePair<string, NBT_Value> item)
public void Add (KeyValuePair<string, TagValue> item)
{
_tags.Add(item.Key, item.Value);
}
@ -576,16 +747,16 @@ namespace Substrate.NBT {
_tags.Clear();
}
public bool Contains (KeyValuePair<string, NBT_Value> item)
public bool Contains (KeyValuePair<string, TagValue> item)
{
NBT_Value value;
TagValue value;
if (!_tags.TryGetValue(item.Key, out value)) {
return false;
}
return value == item.Value;
}
public void CopyTo (KeyValuePair<string, NBT_Value>[] array, int arrayIndex)
public void CopyTo (KeyValuePair<string, TagValue>[] array, int arrayIndex)
{
if (array == null) {
throw new ArgumentNullException();
@ -597,7 +768,7 @@ namespace Substrate.NBT {
throw new ArgumentException();
}
foreach (KeyValuePair<string, NBT_Value> item in _tags) {
foreach (KeyValuePair<string, TagValue> item in _tags) {
array[arrayIndex] = item;
arrayIndex++;
}
@ -608,7 +779,7 @@ namespace Substrate.NBT {
get { return false; }
}
public bool Remove (KeyValuePair<string, NBT_Value> item)
public bool Remove (KeyValuePair<string, TagValue> item)
{
if (Contains(item)) {
_tags.Remove(item.Key);
@ -621,7 +792,7 @@ namespace Substrate.NBT {
#region IEnumerable<KeyValuePair<string,NBT_Value>> Members
public IEnumerator<KeyValuePair<string, NBT_Value>> GetEnumerator ()
public IEnumerator<KeyValuePair<string, TagValue>> GetEnumerator ()
{
return _tags.GetEnumerator();
}

View file

@ -20,7 +20,7 @@ namespace Substrate.NBT
public class TagEventArgs : EventArgs
{
protected string _tagName;
protected NBT_Value _tag;
protected TagValue _tag;
protected NBTSchemaNode _schema;
public string TagName
@ -34,14 +34,14 @@ namespace Substrate.NBT
_tagName = tagName;
}
public TagEventArgs (string tagName, NBT_Value tag)
public TagEventArgs (string tagName, TagValue tag)
: base()
{
_tag = tag;
_tagName = tagName;
}
public TagEventArgs (NBTSchemaNode schema, NBT_Value tag)
public TagEventArgs (NBTSchemaNode schema, TagValue tag)
: base()
{
_tag = tag;
@ -51,18 +51,18 @@ namespace Substrate.NBT
public class NBTVerifier : INBTVerifier
{
private NBT_Value _root;
private TagValue _root;
private NBTSchemaNode _schema;
public event MissingTagHandler MissingTag;
public event InvalidTagTypeHandler InvalidTagType;
public event InvalidTagValueHandler InvalidTagValue;
private Dictionary<string, NBT_Value> _scratch = new Dictionary<string,NBT_Value>();
private Dictionary<string, TagValue> _scratch = new Dictionary<string,TagValue>();
public NBTVerifier () { }
public NBTVerifier (NBT_Value root, NBTSchemaNode schema)
public NBTVerifier (TagValue root, NBTSchemaNode schema)
{
_root = root;
_schema = schema;
@ -75,13 +75,13 @@ namespace Substrate.NBT
static NBTCompoundNode inventorySchema = new NBTCompoundNode("")
{
new NBTScalerNode("id", NBT_Type.TAG_SHORT),
new NBTScalerNode("Damage", NBT_Type.TAG_SHORT),
new NBTScalerNode("Count", NBT_Type.TAG_BYTE),
new NBTScalerNode("Slot", NBT_Type.TAG_BYTE),
new NBTScalerNode("id", TagType.TAG_SHORT),
new NBTScalerNode("Damage", TagType.TAG_SHORT),
new NBTScalerNode("Count", TagType.TAG_BYTE),
new NBTScalerNode("Slot", TagType.TAG_BYTE),
};
private bool Verify (NBT_Value tag, NBTSchemaNode schema)
private bool Verify (TagValue tag, NBTSchemaNode schema)
{
if (tag == null) {
OnMissingTag(new TagEventArgs(schema.Name));
@ -116,9 +116,9 @@ namespace Substrate.NBT
return false;
}
private bool VerifyScaler (NBT_Value tag, NBTScalerNode schema)
private bool VerifyScaler (TagValue tag, NBTScalerNode schema)
{
if (tag.GetNBTType() != schema.Type) {
if (!tag.IsCastableTo(schema.Type)) {
OnInvalidTagType(new TagEventArgs(schema.Name, tag));
return false;
}
@ -126,9 +126,9 @@ namespace Substrate.NBT
return true;
}
private bool VerifyString (NBT_Value tag, NBTStringNode schema)
private bool VerifyString (TagValue tag, NBTStringNode schema)
{
NBT_String stag = tag as NBT_String;
TagString stag = tag as TagString;
if (stag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag));
return false;
@ -146,9 +146,9 @@ namespace Substrate.NBT
}
private bool VerifyArray (NBT_Value tag, NBTArrayNode schema)
private bool VerifyArray (TagValue tag, NBTArrayNode schema)
{
NBT_ByteArray atag = tag as NBT_ByteArray;
TagByteArray atag = tag as TagByteArray;
if (atag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag));
return false;
@ -161,9 +161,9 @@ namespace Substrate.NBT
return true;
}
private bool VerifyList (NBT_Value tag, NBTListNode schema)
private bool VerifyList (TagValue tag, NBTListNode schema)
{
NBT_List ltag = tag as NBT_List;
TagList ltag = tag as TagList;
if (ltag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag));
return false;
@ -187,7 +187,7 @@ namespace Substrate.NBT
// If a subschema is set, test all items in list against it
if (schema.SubSchema != null) {
foreach (NBT_Value v in ltag) {
foreach (TagValue v in ltag) {
pass = Verify(v, schema.SubSchema) && pass;
}
}
@ -195,9 +195,9 @@ namespace Substrate.NBT
return pass;
}
private bool VerifyCompound (NBT_Value tag, NBTCompoundNode schema)
private bool VerifyCompound (TagValue tag, NBTCompoundNode schema)
{
NBT_Compound ctag = tag as NBT_Compound;
TagCompound ctag = tag as TagCompound;
if (ctag == null) {
OnInvalidTagType(new TagEventArgs(schema, tag));
return false;
@ -206,7 +206,7 @@ namespace Substrate.NBT
bool pass = true;
foreach (NBTSchemaNode node in schema) {
NBT_Value value;
TagValue value;
ctag.TryGetValue(node.Name, out value);
if (value == null) {
@ -222,7 +222,7 @@ namespace Substrate.NBT
pass = Verify(value, node) && pass;
}
foreach (KeyValuePair<string, NBT_Value> item in _scratch) {
foreach (KeyValuePair<string, TagValue> item in _scratch) {
ctag[item.Key] = item.Value;
}

View file

@ -11,14 +11,14 @@ namespace Substrate
{
public static readonly NBTCompoundNode PlayerSchema = UTBaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTScalerNode("Dimension", NBT_Type.TAG_INT),
new NBTListNode("Inventory", NBT_Type.TAG_COMPOUND, ItemCollection.InventorySchema),
new NBTScalerNode("World", NBT_Type.TAG_STRING, NBTOptions.OPTIONAL),
new NBTScalerNode("Sleeping", NBT_Type.TAG_BYTE, NBTOptions.CREATE_ON_MISSING),
new NBTScalerNode("SleepTimer", NBT_Type.TAG_SHORT, NBTOptions.CREATE_ON_MISSING),
new NBTScalerNode("SpawnX", NBT_Type.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("SpawnY", NBT_Type.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("SpawnZ", NBT_Type.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("Dimension", TagType.TAG_INT),
new NBTListNode("Inventory", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
new NBTScalerNode("World", TagType.TAG_STRING, NBTOptions.OPTIONAL),
new NBTScalerNode("Sleeping", TagType.TAG_BYTE, NBTOptions.CREATE_ON_MISSING),
new NBTScalerNode("SleepTimer", TagType.TAG_SHORT, NBTOptions.CREATE_ON_MISSING),
new NBTScalerNode("SpawnX", TagType.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("SpawnY", TagType.TAG_INT, NBTOptions.OPTIONAL),
new NBTScalerNode("SpawnZ", TagType.TAG_INT, NBTOptions.OPTIONAL),
});
private const int _CAPACITY = 105;
@ -98,37 +98,37 @@ namespace Substrate
#region INBTObject<Player> Members
public virtual new Player LoadTree (NBT_Value tree)
public virtual new Player LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_dimension = ctree["Dimension"].ToNBTInt();
_sleeping = ctree["Sleeping"].ToNBTByte();
_sleepTimer = ctree["SleepTimer"].ToNBTShort();
_dimension = ctree["Dimension"].ToTagInt();
_sleeping = ctree["Sleeping"].ToTagByte();
_sleepTimer = ctree["SleepTimer"].ToTagShort();
if (ctree.ContainsKey("SpawnX")) {
_spawnX = ctree["SpawnX"].ToNBTInt();
_spawnX = ctree["SpawnX"].ToTagInt();
}
if (ctree.ContainsKey("SpawnY")) {
_spawnY = ctree["SpawnY"].ToNBTInt();
_spawnY = ctree["SpawnY"].ToTagInt();
}
if (ctree.ContainsKey("SpawnZ")) {
_spawnZ = ctree["SpawnZ"].ToNBTInt();
_spawnZ = ctree["SpawnZ"].ToTagInt();
}
if (ctree.ContainsKey("World")) {
_world = ctree["World"].ToNBTString();
_world = ctree["World"].ToTagString();
}
_inventory.LoadTree(ctree["Inventory"].ToNBTList());
_inventory.LoadTree(ctree["Inventory"].ToTagList());
return this;
}
public virtual new Player LoadTreeSafe (NBT_Value tree)
public virtual new Player LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -137,21 +137,21 @@ namespace Substrate
return LoadTree(tree);
}
public virtual new NBT_Value BuildTree ()
public virtual new TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Dimension"] = new NBT_Int(_dimension);
tree["Sleeping"] = new NBT_Byte(_sleeping);
tree["SleepTimer"] = new NBT_Short(_sleepTimer);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Dimension"] = new TagInt(_dimension);
tree["Sleeping"] = new TagByte(_sleeping);
tree["SleepTimer"] = new TagShort(_sleepTimer);
if (_spawnX != null && _spawnY != null && _spawnZ != null) {
tree["SpawnX"] = new NBT_Int(_spawnX ?? 0);
tree["SpawnY"] = new NBT_Int(_spawnY ?? 0);
tree["SpawnZ"] = new NBT_Int(_spawnZ ?? 0);
tree["SpawnX"] = new TagInt(_spawnX ?? 0);
tree["SpawnY"] = new TagInt(_spawnY ?? 0);
tree["SpawnZ"] = new TagInt(_spawnZ ?? 0);
}
if (_world != null) {
tree["World"] = new NBT_String(_world);
tree["World"] = new TagString(_world);
}
tree["Inventory"] = _inventory.BuildTree();
@ -159,7 +159,7 @@ namespace Substrate
return tree;
}
public virtual new bool ValidateTree (NBT_Value tree)
public virtual new bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, PlayerSchema).Verify();
}

View file

@ -57,7 +57,7 @@ namespace Substrate
public bool SetPlayer (string name, Player player)
{
return SavePlayerTree(name, new NBT_Tree(player.BuildTree() as NBT_Compound));
return SavePlayerTree(name, new NBT_Tree(player.BuildTree() as TagCompound));
}
public bool PlayerExists (string name)

View file

@ -11,7 +11,7 @@ namespace Substrate.TileEntities
public static readonly NBTCompoundNode ChestSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Chest"),
new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema),
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.ListSchema),
});
private const int _CAPACITY = 27;
@ -58,28 +58,28 @@ namespace Substrate.TileEntities
#region INBTObject<TileEntity> Members
public override TileEntity LoadTree (NBT_Value tree)
public override TileEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
NBT_List items = ctree["Items"].ToNBTList();
TagList items = ctree["Items"].ToTagList();
_items = new ItemCollection(_CAPACITY).LoadTree(items);
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
TagCompound tree = base.BuildTree() as TagCompound;
tree["Items"] = _items.BuildTree();
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, ChestSchema).Verify();
}

View file

@ -11,9 +11,9 @@ namespace Substrate.TileEntities
public static readonly NBTCompoundNode FurnaceSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Furnace"),
new NBTScalerNode("BurnTime", NBT_Type.TAG_SHORT),
new NBTScalerNode("CookTime", NBT_Type.TAG_SHORT),
new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema),
new NBTScalerNode("BurnTime", TagType.TAG_SHORT),
new NBTScalerNode("CookTime", TagType.TAG_SHORT),
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.ListSchema),
});
private const int _CAPACITY = 3;
@ -78,33 +78,33 @@ namespace Substrate.TileEntities
#region INBTObject<TileEntity> Members
public override TileEntity LoadTree (NBT_Value tree)
public override TileEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_burnTime = ctree["BurnTime"].ToNBTShort();
_cookTime = ctree["CookTime"].ToNBTShort();
_burnTime = ctree["BurnTime"].ToTagShort();
_cookTime = ctree["CookTime"].ToTagShort();
NBT_List items = ctree["Items"].ToNBTList();
TagList items = ctree["Items"].ToTagList();
_items = new ItemCollection(_CAPACITY).LoadTree(items);
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["BurnTime"] = new NBT_Short(_burnTime);
tree["CookTime"] = new NBT_Short(_cookTime);
TagCompound tree = base.BuildTree() as TagCompound;
tree["BurnTime"] = new TagShort(_burnTime);
tree["CookTime"] = new TagShort(_cookTime);
tree["Items"] = _items.BuildTree();
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, FurnaceSchema).Verify();
}

View file

@ -11,8 +11,8 @@ namespace Substrate.TileEntities
public static readonly NBTCompoundNode MobSpawnerSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "MobSpawner"),
new NBTScalerNode("EntityId", NBT_Type.TAG_STRING),
new NBTScalerNode("Delay", NBT_Type.TAG_SHORT),
new NBTScalerNode("EntityId", TagType.TAG_STRING),
new NBTScalerNode("Delay", TagType.TAG_SHORT),
});
private short _delay;
@ -58,29 +58,29 @@ namespace Substrate.TileEntities
#region INBTObject<TileEntity> Members
public override TileEntity LoadTree (NBT_Value tree)
public override TileEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_delay = ctree["Delay"].ToNBTShort();
_entityID = ctree["EntityID"].ToNBTString();
_delay = ctree["Delay"].ToTagShort();
_entityID = ctree["EntityID"].ToTagString();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["EntityID"] = new NBT_String(_entityID);
tree["Delay"] = new NBT_Short(_delay);
TagCompound tree = base.BuildTree() as TagCompound;
tree["EntityID"] = new TagString(_entityID);
tree["Delay"] = new TagShort(_delay);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, MobSpawnerSchema).Verify();
}

View file

@ -11,7 +11,7 @@ namespace Substrate.TileEntities
public static readonly NBTCompoundNode MusicSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Music"),
new NBTScalerNode("note", NBT_Type.TAG_BYTE),
new NBTScalerNode("note", TagType.TAG_BYTE),
});
private byte _note;
@ -49,27 +49,27 @@ namespace Substrate.TileEntities
#region INBTObject<TileEntity> Members
public override TileEntity LoadTree (NBT_Value tree)
public override TileEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_note = ctree["Note"].ToNBTByte();
_note = ctree["Note"].ToTagByte();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Note"] = new NBT_Byte(_note);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Note"] = new TagByte(_note);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, MusicSchema).Verify();
}

View file

@ -11,10 +11,10 @@ namespace Substrate.TileEntities
public static readonly NBTCompoundNode SignSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Sign"),
new NBTScalerNode("Text1", NBT_Type.TAG_STRING),
new NBTScalerNode("Text2", NBT_Type.TAG_STRING),
new NBTScalerNode("Text3", NBT_Type.TAG_STRING),
new NBTScalerNode("Text4", NBT_Type.TAG_STRING),
new NBTScalerNode("Text1", TagType.TAG_STRING),
new NBTScalerNode("Text2", TagType.TAG_STRING),
new NBTScalerNode("Text3", TagType.TAG_STRING),
new NBTScalerNode("Text4", TagType.TAG_STRING),
});
private string _text1 = "";
@ -76,33 +76,33 @@ namespace Substrate.TileEntities
#region INBTObject<TileEntity> Members
public override TileEntity LoadTree (NBT_Value tree)
public override TileEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
_text1 = ctree["Text1"].ToNBTString();
_text2 = ctree["Text2"].ToNBTString();
_text3 = ctree["Text3"].ToNBTString();
_text4 = ctree["Text4"].ToNBTString();
_text1 = ctree["Text1"].ToTagString();
_text2 = ctree["Text2"].ToTagString();
_text3 = ctree["Text3"].ToTagString();
_text4 = ctree["Text4"].ToTagString();
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
tree["Text1"] = new NBT_String(_text1);
tree["Text2"] = new NBT_String(_text2);
tree["Text3"] = new NBT_String(_text3);
tree["Text4"] = new NBT_String(_text4);
TagCompound tree = base.BuildTree() as TagCompound;
tree["Text1"] = new TagString(_text1);
tree["Text2"] = new TagString(_text2);
tree["Text3"] = new TagString(_text3);
tree["Text4"] = new TagString(_text4);
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, SignSchema).Verify();
}

View file

@ -11,7 +11,7 @@ namespace Substrate.TileEntities
public static readonly NBTCompoundNode TrapSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
{
new NBTStringNode("id", "Trap"),
new NBTListNode("Items", NBT_Type.TAG_COMPOUND, ItemCollection.ListSchema),
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.ListSchema),
});
private const int _CAPACITY = 8;
@ -59,28 +59,28 @@ namespace Substrate.TileEntities
#region INBTObject<TileEntity> Members
public override TileEntity LoadTree (NBT_Value tree)
public override TileEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null || base.LoadTree(tree) == null) {
return null;
}
NBT_List items = ctree["Items"].ToNBTList();
TagList items = ctree["Items"].ToTagList();
_items = new ItemCollection(_CAPACITY).LoadTree(items);
return this;
}
public override NBT_Value BuildTree ()
public override TagValue BuildTree ()
{
NBT_Compound tree = base.BuildTree() as NBT_Compound;
TagCompound tree = base.BuildTree() as TagCompound;
tree["Items"] = _items.BuildTree();
return tree;
}
public override bool ValidateTree (NBT_Value tree)
public override bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, TrapSchema).Verify();
}

View file

@ -11,10 +11,10 @@ namespace Substrate
{
public static readonly NBTCompoundNode BaseSchema = new NBTCompoundNode("")
{
new NBTScalerNode("id", NBT_Type.TAG_STRING),
new NBTScalerNode("x", NBT_Type.TAG_INT),
new NBTScalerNode("y", NBT_Type.TAG_INT),
new NBTScalerNode("z", NBT_Type.TAG_INT),
new NBTScalerNode("id", TagType.TAG_STRING),
new NBTScalerNode("x", TagType.TAG_INT),
new NBTScalerNode("y", TagType.TAG_INT),
new NBTScalerNode("z", TagType.TAG_INT),
};
private string _id;
@ -76,22 +76,22 @@ namespace Substrate
#region INBTObject<TileEntity> Members
public virtual TileEntity LoadTree (NBT_Value tree)
public virtual TileEntity LoadTree (TagValue tree)
{
NBT_Compound ctree = tree as NBT_Compound;
TagCompound ctree = tree as TagCompound;
if (ctree == null) {
return null;
}
_id = ctree["id"].ToNBTString();
_x = ctree["x"].ToNBTInt();
_y = ctree["y"].ToNBTInt();
_z = ctree["z"].ToNBTInt();
_id = ctree["id"].ToTagString();
_x = ctree["x"].ToTagInt();
_y = ctree["y"].ToTagInt();
_z = ctree["z"].ToTagInt();
return this;
}
public virtual TileEntity LoadTreeSafe (NBT_Value tree)
public virtual TileEntity LoadTreeSafe (TagValue tree)
{
if (!ValidateTree(tree)) {
return null;
@ -100,18 +100,18 @@ namespace Substrate
return LoadTree(tree);
}
public virtual NBT_Value BuildTree ()
public virtual TagValue BuildTree ()
{
NBT_Compound tree = new NBT_Compound();
tree["id"] = new NBT_String(_id);
tree["x"] = new NBT_Int(_x);
tree["y"] = new NBT_Int(_y);
tree["z"] = new NBT_Int(_z);
TagCompound tree = new TagCompound();
tree["id"] = new TagString(_id);
tree["x"] = new TagInt(_x);
tree["y"] = new TagInt(_y);
tree["z"] = new TagInt(_z);
return tree;
}
public virtual bool ValidateTree (NBT_Value tree)
public virtual bool ValidateTree (TagValue tree)
{
return new NBTVerifier(tree, BaseSchema).Verify();
}

View file

@ -21,9 +21,9 @@ namespace Substrate
return Activator.CreateInstance(t, new object[] { type }) as TileEntity;
}
public static TileEntity Create (NBT_Compound tree)
public static TileEntity Create (TagCompound tree)
{
string type = tree["id"].ToNBTString();
string type = tree["id"].ToTagString();
Type t;
if (!_registry.TryGetValue(type, out t)) {