forked from mirrors/NBTExplorer
Baseline NBT refactoring and documentation. Most changes outside of NBT are for renamed identifiers.
This commit is contained in:
parent
0fefa0d640
commit
cdee3fb41d
67 changed files with 2513 additions and 1473 deletions
|
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("0.6.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.6.0.0")]
|
||||
[assembly: AssemblyVersion("0.6.1.0")]
|
||||
[assembly: AssemblyFileVersion("0.6.1.0")]
|
||||
|
|
|
@ -38,9 +38,9 @@ namespace Substrate
|
|||
}
|
||||
|
||||
public struct BlockPropertyData {
|
||||
public TagList tileEntities;
|
||||
public TagNodeList tileEntities;
|
||||
|
||||
public BlockPropertyData (TagList t)
|
||||
public BlockPropertyData (TagNodeList t)
|
||||
{
|
||||
tileEntities = t;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace Substrate
|
|||
private XZYNibbleArray _skyLight;
|
||||
private ZXByteArray _heightMap;
|
||||
|
||||
private TagList _tileEntities;
|
||||
private TagNodeList _tileEntities;
|
||||
|
||||
private BlockLight _lightManager;
|
||||
private BlockFluid _fluidManager;
|
||||
|
|
|
@ -11,13 +11,13 @@ namespace Substrate
|
|||
public class BlockTileEntities
|
||||
{
|
||||
private XZYByteArray _blocks;
|
||||
private TagList _tileEntities;
|
||||
private TagNodeList _tileEntities;
|
||||
|
||||
private Dictionary<BlockKey, TagCompound> _tileEntityTable;
|
||||
private Dictionary<BlockKey, TagNodeCompound> _tileEntityTable;
|
||||
|
||||
public event BlockCoordinateHandler TranslateCoordinates;
|
||||
|
||||
public BlockTileEntities (XZYByteArray blocks, TagList tileEntities)
|
||||
public BlockTileEntities (XZYByteArray blocks, TagNodeList tileEntities)
|
||||
{
|
||||
_blocks = blocks;
|
||||
_tileEntities = tileEntities;
|
||||
|
@ -39,7 +39,7 @@ namespace Substrate
|
|||
? TranslateCoordinates(x, y, z)
|
||||
: new BlockKey(x, y, z);
|
||||
|
||||
TagCompound te;
|
||||
TagNodeCompound te;
|
||||
|
||||
if (!_tileEntityTable.TryGetValue(key, out te)) {
|
||||
return null;
|
||||
|
@ -63,7 +63,7 @@ namespace Substrate
|
|||
? TranslateCoordinates(x, y, z)
|
||||
: new BlockKey(x, y, z);
|
||||
|
||||
TagCompound oldte;
|
||||
TagNodeCompound oldte;
|
||||
|
||||
if (_tileEntityTable.TryGetValue(key, out oldte)) {
|
||||
_tileEntities.Remove(oldte);
|
||||
|
@ -73,7 +73,7 @@ namespace Substrate
|
|||
te.Y = key.y;
|
||||
te.Z = key.z;
|
||||
|
||||
TagCompound tree = te.BuildTree() as TagCompound;
|
||||
TagNodeCompound tree = te.BuildTree() as TagNodeCompound;
|
||||
|
||||
_tileEntities.Add(tree);
|
||||
_tileEntityTable[key] = tree;
|
||||
|
@ -95,7 +95,7 @@ namespace Substrate
|
|||
? TranslateCoordinates(x, y, z)
|
||||
: new BlockKey(x, y, z);
|
||||
|
||||
TagCompound oldte;
|
||||
TagNodeCompound oldte;
|
||||
|
||||
if (_tileEntityTable.TryGetValue(key, out oldte)) {
|
||||
_tileEntities.Remove(oldte);
|
||||
|
@ -105,7 +105,7 @@ namespace Substrate
|
|||
te.Y = key.y;
|
||||
te.Z = key.z;
|
||||
|
||||
TagCompound tree = te.BuildTree() as TagCompound;
|
||||
TagNodeCompound tree = te.BuildTree() as TagNodeCompound;
|
||||
|
||||
_tileEntities.Add(tree);
|
||||
_tileEntityTable[key] = tree;
|
||||
|
@ -117,7 +117,7 @@ namespace Substrate
|
|||
? TranslateCoordinates(x, y, z)
|
||||
: new BlockKey(x, y, z);
|
||||
|
||||
TagCompound te;
|
||||
TagNodeCompound te;
|
||||
|
||||
if (!_tileEntityTable.TryGetValue(key, out te)) {
|
||||
return;
|
||||
|
@ -129,9 +129,9 @@ namespace Substrate
|
|||
|
||||
private void BuildTileEntityCache ()
|
||||
{
|
||||
_tileEntityTable = new Dictionary<BlockKey, TagCompound>();
|
||||
_tileEntityTable = new Dictionary<BlockKey, TagNodeCompound>();
|
||||
|
||||
foreach (TagCompound te in _tileEntities) {
|
||||
foreach (TagNodeCompound te in _tileEntities) {
|
||||
int tex = te["x"].ToTagInt();
|
||||
int tey = te["y"].ToTagInt();
|
||||
int tez = te["z"].ToTagInt();
|
||||
|
|
|
@ -22,21 +22,21 @@ namespace Substrate
|
|||
/// <summary>
|
||||
/// An NBT Schema definition for valid chunk data.
|
||||
/// </summary>
|
||||
public static NBTCompoundNode LevelSchema = new NBTCompoundNode()
|
||||
public static SchemaNodeCompound LevelSchema = new SchemaNodeCompound()
|
||||
{
|
||||
new NBTCompoundNode("Level")
|
||||
new SchemaNodeCompound("Level")
|
||||
{
|
||||
new NBTArrayNode("Blocks", 32768),
|
||||
new NBTArrayNode("Data", 16384),
|
||||
new NBTArrayNode("SkyLight", 16384),
|
||||
new NBTArrayNode("BlockLight", 16384),
|
||||
new NBTArrayNode("HeightMap", 256),
|
||||
new NBTListNode("Entities", TagType.TAG_COMPOUND, 0, NBTOptions.CREATE_ON_MISSING),
|
||||
new NBTListNode("TileEntities", TagType.TAG_COMPOUND, TileEntity.BaseSchema, NBTOptions.CREATE_ON_MISSING),
|
||||
new NBTScalerNode("LastUpdate", TagType.TAG_LONG, NBTOptions.CREATE_ON_MISSING),
|
||||
new NBTScalerNode("xPos", TagType.TAG_INT),
|
||||
new NBTScalerNode("zPos", TagType.TAG_INT),
|
||||
new NBTScalerNode("TerrainPopulated", TagType.TAG_BYTE, NBTOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeArray("Blocks", 32768),
|
||||
new SchemaNodeArray("Data", 16384),
|
||||
new SchemaNodeArray("SkyLight", 16384),
|
||||
new SchemaNodeArray("BlockLight", 16384),
|
||||
new SchemaNodeArray("HeightMap", 256),
|
||||
new SchemaNodeList("Entities", TagType.TAG_COMPOUND, 0, SchemaOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeList("TileEntities", TagType.TAG_COMPOUND, TileEntity.BaseSchema, SchemaOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeScaler("LastUpdate", TagType.TAG_LONG, SchemaOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeScaler("xPos", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("zPos", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("TerrainPopulated", TagType.TAG_BYTE, SchemaOptions.CREATE_ON_MISSING),
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -51,8 +51,8 @@ namespace Substrate
|
|||
private XZYNibbleArray _skyLight;
|
||||
private ZXByteArray _heightMap;
|
||||
|
||||
private TagList _entities;
|
||||
private TagList _tileEntities;
|
||||
private TagNodeList _entities;
|
||||
private TagNodeList _tileEntities;
|
||||
|
||||
private AlphaBlockCollection _blockManager;
|
||||
private EntityCollection _entityManager;
|
||||
|
@ -189,35 +189,35 @@ namespace Substrate
|
|||
/// </summary>
|
||||
/// <param name="tree">Root node of an NBT tree.</param>
|
||||
/// <returns>A reference to the current Chunk, or null if the tree is unparsable.</returns>
|
||||
public Chunk LoadTree (TagValue tree)
|
||||
public Chunk LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
_tree = new NBT_Tree(ctree);
|
||||
|
||||
TagCompound level = _tree.Root["Level"] as TagCompound;
|
||||
TagNodeCompound level = _tree.Root["Level"] as TagNodeCompound;
|
||||
|
||||
_blocks = new XZYByteArray(XDIM, YDIM, ZDIM, level["Blocks"] as TagByteArray);
|
||||
_data = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["Data"] as TagByteArray);
|
||||
_blockLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["BlockLight"] as TagByteArray);
|
||||
_skyLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["SkyLight"] as TagByteArray);
|
||||
_heightMap = new ZXByteArray(XDIM, ZDIM, level["HeightMap"] as TagByteArray);
|
||||
_blocks = new XZYByteArray(XDIM, YDIM, ZDIM, level["Blocks"] as TagNodeByteArray);
|
||||
_data = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["Data"] as TagNodeByteArray);
|
||||
_blockLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["BlockLight"] as TagNodeByteArray);
|
||||
_skyLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, level["SkyLight"] as TagNodeByteArray);
|
||||
_heightMap = new ZXByteArray(XDIM, ZDIM, level["HeightMap"] as TagNodeByteArray);
|
||||
|
||||
_entities = level["Entities"] as TagList;
|
||||
_tileEntities = level["TileEntities"] as TagList;
|
||||
_entities = level["Entities"] as TagNodeList;
|
||||
_tileEntities = level["TileEntities"] as TagNodeList;
|
||||
|
||||
// List-type patch up
|
||||
if (_entities.Count == 0) {
|
||||
level["Entities"] = new TagList(TagType.TAG_COMPOUND);
|
||||
_entities = level["Entities"] as TagList;
|
||||
level["Entities"] = new TagNodeList(TagType.TAG_COMPOUND);
|
||||
_entities = level["Entities"] as TagNodeList;
|
||||
}
|
||||
|
||||
if (_tileEntities.Count == 0) {
|
||||
level["TileEntities"] = new TagList(TagType.TAG_COMPOUND);
|
||||
_tileEntities = level["TileEntities"] as TagList;
|
||||
level["TileEntities"] = new TagNodeList(TagType.TAG_COMPOUND);
|
||||
_tileEntities = level["TileEntities"] as TagNodeList;
|
||||
}
|
||||
|
||||
_cx = level["xPos"].ToTagInt();
|
||||
|
@ -240,7 +240,7 @@ namespace Substrate
|
|||
/// </summary>
|
||||
/// <param name="tree">Root node of an NBT tree.</param>
|
||||
/// <returns>A reference to the current Chunk, or null if the tree does not conform to the chunk's NBT Schema definition.</returns>
|
||||
public Chunk LoadTreeSafe (TagValue tree)
|
||||
public Chunk LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -253,7 +253,7 @@ namespace Substrate
|
|||
/// Gets a valid NBT tree representing the Chunk.
|
||||
/// </summary>
|
||||
/// <returns>The root node of the Chunk's NBT tree.</returns>
|
||||
public TagValue BuildTree ()
|
||||
public TagNode BuildTree ()
|
||||
{
|
||||
return _tree.Root;
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ namespace Substrate
|
|||
/// </summary>
|
||||
/// <param name="tree">The root node of the NBT tree to verify.</param>
|
||||
/// <returns>Status indicating if the tree represents a valid chunk.</returns>
|
||||
public bool ValidateTree (TagValue tree)
|
||||
public bool ValidateTree (TagNode tree)
|
||||
{
|
||||
NBTVerifier v = new NBTVerifier(tree, LevelSchema);
|
||||
return v.Verify();
|
||||
|
@ -291,11 +291,11 @@ namespace Substrate
|
|||
int elements2 = XDIM * ZDIM;
|
||||
int elements3 = elements2 * YDIM;
|
||||
|
||||
TagByteArray 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]);
|
||||
TagByteArray heightMap = new TagByteArray(new byte[elements2]);
|
||||
TagNodeByteArray blocks = new TagNodeByteArray(new byte[elements3]);
|
||||
TagNodeByteArray data = new TagNodeByteArray(new byte[elements3 >> 1]);
|
||||
TagNodeByteArray blocklight = new TagNodeByteArray(new byte[elements3 >> 1]);
|
||||
TagNodeByteArray skylight = new TagNodeByteArray(new byte[elements3 >> 1]);
|
||||
TagNodeByteArray heightMap = new TagNodeByteArray(new byte[elements2]);
|
||||
|
||||
_blocks = new XZYByteArray(XDIM, YDIM, ZDIM, blocks);
|
||||
_data = new XZYNibbleArray(XDIM, YDIM, ZDIM, data);
|
||||
|
@ -303,10 +303,10 @@ namespace Substrate
|
|||
_skyLight = new XZYNibbleArray(XDIM, YDIM, ZDIM, skylight);
|
||||
_heightMap = new ZXByteArray(XDIM, ZDIM, heightMap);
|
||||
|
||||
_entities = new TagList(TagType.TAG_COMPOUND);
|
||||
_tileEntities = new TagList(TagType.TAG_COMPOUND);
|
||||
_entities = new TagNodeList(TagType.TAG_COMPOUND);
|
||||
_tileEntities = new TagNodeList(TagType.TAG_COMPOUND);
|
||||
|
||||
TagCompound level = new TagCompound();
|
||||
TagNodeCompound level = new TagNodeCompound();
|
||||
level.Add("Blocks", blocks);
|
||||
level.Add("Data", data);
|
||||
level.Add("SkyLight", blocklight);
|
||||
|
@ -314,10 +314,10 @@ namespace Substrate
|
|||
level.Add("HeightMap", heightMap);
|
||||
level.Add("Entities", _entities);
|
||||
level.Add("TileEntities", _tileEntities);
|
||||
level.Add("LastUpdate", new TagLong(Timestamp()));
|
||||
level.Add("xPos", new TagInt(_cx));
|
||||
level.Add("zPos", new TagInt(_cz));
|
||||
level.Add("TerrainPopulated", new TagByte());
|
||||
level.Add("LastUpdate", new TagNodeLong(Timestamp()));
|
||||
level.Add("xPos", new TagNodeInt(_cx));
|
||||
level.Add("zPos", new TagNodeInt(_cz));
|
||||
level.Add("TerrainPopulated", new TagNodeByte());
|
||||
|
||||
_tree = new NBT_Tree();
|
||||
_tree.Root.Add("Level", level);
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityArrow : EntityThrowable
|
||||
{
|
||||
public static readonly NBTCompoundNode ArrowSchema = ThrowableSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound ArrowSchema = ThrowableSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Arrow"),
|
||||
new SchemaNodeString("id", "Arrow"),
|
||||
});
|
||||
|
||||
public EntityArrow ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ArrowSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityBoat : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode BoatSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound BoatSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Boat"),
|
||||
new SchemaNodeString("id", "Boat"),
|
||||
});
|
||||
|
||||
public EntityBoat ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, BoatSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityChicken : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode ChickenSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound ChickenSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Chicken"),
|
||||
new SchemaNodeString("id", "Chicken"),
|
||||
});
|
||||
|
||||
public EntityChicken ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ChickenSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityCow : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode CowSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound CowSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Cow"),
|
||||
new SchemaNodeString("id", "Cow"),
|
||||
});
|
||||
|
||||
public EntityCow ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, CowSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityCreeper : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode CreeperSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound CreeperSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Creeper"),
|
||||
new SchemaNodeString("id", "Creeper"),
|
||||
});
|
||||
|
||||
public EntityCreeper ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, CreeperSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityEgg : EntityThrowable
|
||||
{
|
||||
public static readonly NBTCompoundNode EggSchema = ThrowableSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound EggSchema = ThrowableSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Egg"),
|
||||
new SchemaNodeString("id", "Egg"),
|
||||
});
|
||||
|
||||
public EntityEgg ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, EggSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityFallingSand : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode FallingSandSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound FallingSandSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "FallingSand"),
|
||||
new NBTScalerNode("Tile", TagType.TAG_BYTE),
|
||||
new SchemaNodeString("id", "FallingSand"),
|
||||
new SchemaNodeScaler("Tile", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
private byte _tile;
|
||||
|
@ -39,9 +39,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -51,15 +51,15 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["Tile"] = new TagByte(_tile);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Tile"] = new TagNodeByte(_tile);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, FallingSandSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityGhast : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode GhastSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound GhastSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Ghast"),
|
||||
new SchemaNodeString("id", "Ghast"),
|
||||
});
|
||||
|
||||
public EntityGhast ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, GhastSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityGiant : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode GiantSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound GiantSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Giant"),
|
||||
new SchemaNodeString("id", "Giant"),
|
||||
});
|
||||
|
||||
public EntityGiant ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, GiantSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityItem : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode ItemSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound ItemSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Item"),
|
||||
new NBTScalerNode("Health", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("Age", TagType.TAG_SHORT),
|
||||
new NBTCompoundNode("Item", Item.ItemSchema),
|
||||
new SchemaNodeString("id", "Item"),
|
||||
new SchemaNodeScaler("Health", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Age", TagType.TAG_SHORT),
|
||||
new SchemaNodeCompound("Item", Item.ItemSchema),
|
||||
});
|
||||
|
||||
private short _health;
|
||||
|
@ -58,9 +58,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -73,17 +73,17 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["Health"] = new TagShort(_health);
|
||||
tree["Age"] = new TagShort(_age);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Health"] = new TagNodeShort(_health);
|
||||
tree["Age"] = new TagNodeShort(_age);
|
||||
tree["Item"] = _item.BuildTree();
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ItemSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ namespace Substrate.Entities
|
|||
FURNACE = 2,
|
||||
}
|
||||
|
||||
public static readonly NBTCompoundNode MinecartSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound MinecartSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Minecart"),
|
||||
new NBTScalerNode("Type", TagType.TAG_BYTE),
|
||||
new SchemaNodeString("id", "Minecart"),
|
||||
new SchemaNodeScaler("Type", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
private CartType _type;
|
||||
|
@ -45,9 +45,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -66,15 +66,15 @@ namespace Substrate.Entities
|
|||
}
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["Type"] = new TagByte((byte)_type);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Type"] = new TagNodeByte((byte)_type);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, MinecartSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityMinecartChest : EntityMinecart, IItemContainer
|
||||
{
|
||||
public static readonly NBTCompoundNode MinecartChestSchema = MinecartSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound MinecartChestSchema = MinecartSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
new SchemaNodeList("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 (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TagList items = ctree["Items"].ToTagList();
|
||||
TagNodeList items = ctree["Items"].ToTagList();
|
||||
_items = _items.LoadTree(items);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Items"] = _items.BuildTree();
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, MinecartChestSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityMinecartFurnace : EntityMinecart
|
||||
{
|
||||
public static readonly NBTCompoundNode MinecartFurnaceSchema = MinecartSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound MinecartFurnaceSchema = MinecartSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTScalerNode("PushX", TagType.TAG_DOUBLE),
|
||||
new NBTScalerNode("PushZ", TagType.TAG_DOUBLE),
|
||||
new NBTScalerNode("Fuel", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("PushX", TagType.TAG_DOUBLE),
|
||||
new SchemaNodeScaler("PushZ", TagType.TAG_DOUBLE),
|
||||
new SchemaNodeScaler("Fuel", TagType.TAG_SHORT),
|
||||
});
|
||||
|
||||
private double _pushX;
|
||||
|
@ -56,9 +56,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -70,17 +70,17 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["PushX"] = new TagDouble(_pushX);
|
||||
tree["PushZ"] = new TagDouble(_pushZ);
|
||||
tree["Fuel"] = new TagShort(_fuel);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["PushX"] = new TagNodeDouble(_pushX);
|
||||
tree["PushZ"] = new TagNodeDouble(_pushZ);
|
||||
tree["Fuel"] = new TagNodeShort(_fuel);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, MinecartFurnaceSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityMob : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode MobSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound MobSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Mob"),
|
||||
new NBTScalerNode("AttackTime", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("DeathTime", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("Health", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("HurtTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeString("id", "Mob"),
|
||||
new SchemaNodeScaler("AttackTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("DeathTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Health", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("HurtTime", TagType.TAG_SHORT),
|
||||
});
|
||||
|
||||
private short _attackTime;
|
||||
|
@ -71,9 +71,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -86,18 +86,18 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
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);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["AttackTime"] = new TagNodeShort(_attackTime);
|
||||
tree["DeathTime"] = new TagNodeShort(_deathTime);
|
||||
tree["Health"] = new TagNodeShort(_health);
|
||||
tree["HurtTime"] = new TagNodeShort(_hurtTime);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, MobSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityMonster : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode MonsterSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound MonsterSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Monster"),
|
||||
new SchemaNodeString("id", "Monster"),
|
||||
});
|
||||
|
||||
public EntityMonster ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, MonsterSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -16,14 +16,14 @@ namespace Substrate.Entities
|
|||
SOUTH = 3,
|
||||
}
|
||||
|
||||
public static readonly NBTCompoundNode PaintingSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound PaintingSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Painting"),
|
||||
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),
|
||||
new SchemaNodeString("id", "Painting"),
|
||||
new SchemaNodeScaler("Dir", TagType.TAG_BYTE),
|
||||
new SchemaNodeScaler("TileX", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("TileY", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("TileZ", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Motive", TagType.TAG_STRING),
|
||||
});
|
||||
|
||||
private DirectionType _dir;
|
||||
|
@ -83,9 +83,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -99,19 +99,19 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
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);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Dir"] = new TagNodeByte((byte)_dir);
|
||||
tree["Motive"] = new TagNodeString(_motive);
|
||||
tree["TileX"] = new TagNodeShort(_xTile);
|
||||
tree["TileY"] = new TagNodeShort(_yTile);
|
||||
tree["TileZ"] = new TagNodeShort(_zTile);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, PaintingSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityPig : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode PigSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound PigSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Pig"),
|
||||
new NBTScalerNode("Saddle", TagType.TAG_BYTE),
|
||||
new SchemaNodeString("id", "Pig"),
|
||||
new SchemaNodeScaler("Saddle", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
private bool _saddle;
|
||||
|
@ -39,9 +39,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -51,15 +51,15 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["Saddle"] = new TagByte((byte)(_saddle ? 1 : 0));
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Saddle"] = new TagNodeByte((byte)(_saddle ? 1 : 0));
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, PigSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityPigZombie : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode PigZombieSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound PigZombieSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "PigZombie"),
|
||||
new SchemaNodeString("id", "PigZombie"),
|
||||
});
|
||||
|
||||
public EntityPigZombie ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, PigZombieSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityPrimedTnt : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode PrimedTntSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound PrimedTntSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "PrimedTnt"),
|
||||
new NBTScalerNode("Fuse", TagType.TAG_BYTE),
|
||||
new SchemaNodeString("id", "PrimedTnt"),
|
||||
new SchemaNodeScaler("Fuse", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
private byte _fuse;
|
||||
|
@ -39,9 +39,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -51,15 +51,15 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["Fuse"] = new TagByte(_fuse);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Fuse"] = new TagNodeByte(_fuse);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, PrimedTntSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntitySheep : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode SheepSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound SheepSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Sheep"),
|
||||
new NBTScalerNode("Sheared", TagType.TAG_BYTE),
|
||||
new NBTScalerNode("Color", TagType.TAG_BYTE, NBTOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeString("id", "Sheep"),
|
||||
new SchemaNodeScaler("Sheared", TagType.TAG_BYTE),
|
||||
new SchemaNodeScaler("Color", TagType.TAG_BYTE, SchemaOptions.CREATE_ON_MISSING),
|
||||
});
|
||||
|
||||
private bool _sheared;
|
||||
|
@ -48,9 +48,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -61,16 +61,16 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["Sheared"] = new TagByte((byte)(_sheared ? 1 : 0));
|
||||
tree["Color"] = new TagByte(_color);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Sheared"] = new TagNodeByte((byte)(_sheared ? 1 : 0));
|
||||
tree["Color"] = new TagNodeByte(_color);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SheepSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntitySkeleton : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode SkeletonSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound SkeletonSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Skeleton"),
|
||||
new SchemaNodeString("id", "Skeleton"),
|
||||
});
|
||||
|
||||
public EntitySkeleton ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SkeletonSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntitySlime : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode SlimeSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound SlimeSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Slime"),
|
||||
new NBTScalerNode("Size", TagType.TAG_INT),
|
||||
new SchemaNodeString("id", "Slime"),
|
||||
new SchemaNodeScaler("Size", TagType.TAG_INT),
|
||||
});
|
||||
|
||||
private int _size;
|
||||
|
@ -39,9 +39,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -51,15 +51,15 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["Size"] = new TagInt(_size);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Size"] = new TagNodeInt(_size);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SlimeSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntitySnowball : EntityThrowable
|
||||
{
|
||||
public static readonly NBTCompoundNode SnowballSchema = ThrowableSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound SnowballSchema = ThrowableSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Snowball"),
|
||||
new SchemaNodeString("id", "Snowball"),
|
||||
});
|
||||
|
||||
public EntitySnowball ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SnowballSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntitySpider : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode SpiderSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound SpiderSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Spider"),
|
||||
new SchemaNodeString("id", "Spider"),
|
||||
});
|
||||
|
||||
public EntitySpider ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SpiderSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntitySquid : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode SquidSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound SquidSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Squid"),
|
||||
new SchemaNodeString("id", "Squid"),
|
||||
});
|
||||
|
||||
public EntitySquid ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SquidSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityThrowable : Entity
|
||||
{
|
||||
public static readonly NBTCompoundNode ThrowableSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound ThrowableSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
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),
|
||||
new SchemaNodeScaler("xTile", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("yTile", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("zTile", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("inTile", TagType.TAG_BYTE),
|
||||
new SchemaNodeScaler("shake", TagType.TAG_BYTE),
|
||||
new SchemaNodeScaler("inGround", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
private short _xTile;
|
||||
|
@ -83,9 +83,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -100,20 +100,20 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
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);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["xTile"] = new TagNodeShort(_xTile);
|
||||
tree["yTile"] = new TagNodeShort(_yTile);
|
||||
tree["zTile"] = new TagNodeShort(_zTile);
|
||||
tree["inTile"] = new TagNodeByte(_inTile);
|
||||
tree["shake"] = new TagNodeByte(_shake);
|
||||
tree["inGround"] = new TagNodeByte(_inGround);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ThrowableSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityWolf : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode WolfSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound WolfSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Wolf"),
|
||||
new NBTScalerNode("Owner", TagType.TAG_STRING),
|
||||
new NBTScalerNode("Sitting", TagType.TAG_BYTE),
|
||||
new NBTScalerNode("Angry", TagType.TAG_BYTE),
|
||||
new SchemaNodeString("id", "Wolf"),
|
||||
new SchemaNodeScaler("Owner", TagType.TAG_STRING),
|
||||
new SchemaNodeScaler("Sitting", TagType.TAG_BYTE),
|
||||
new SchemaNodeScaler("Angry", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
private string _owner;
|
||||
|
@ -57,9 +57,9 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override Entity LoadTree (TagValue tree)
|
||||
public override Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -71,17 +71,17 @@ namespace Substrate.Entities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
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));
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Owner"] = new TagNodeString(_owner);
|
||||
tree["Sitting"] = new TagNodeByte((byte)(_sitting ? 1 : 0));
|
||||
tree["Angry"] = new TagNodeByte((byte)(_angry ? 1 : 0));
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, WolfSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Substrate.Entities
|
|||
|
||||
public class EntityZombie : EntityMob
|
||||
{
|
||||
public static readonly NBTCompoundNode ZombieSchema = MobSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound ZombieSchema = MobSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Zombie"),
|
||||
new SchemaNodeString("id", "Zombie"),
|
||||
});
|
||||
|
||||
public EntityZombie ()
|
||||
|
@ -26,7 +26,7 @@ namespace Substrate.Entities
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ZombieSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -33,15 +33,15 @@ namespace Substrate
|
|||
public double Yaw { get; set; }
|
||||
}
|
||||
|
||||
public static readonly NBTCompoundNode UTBaseSchema = new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound UTBaseSchema = new SchemaNodeCompound("")
|
||||
{
|
||||
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),
|
||||
new SchemaNodeList("Pos", TagType.TAG_DOUBLE, 3),
|
||||
new SchemaNodeList("Motion", TagType.TAG_DOUBLE, 3),
|
||||
new SchemaNodeList("Rotation", TagType.TAG_FLOAT, 2),
|
||||
new SchemaNodeScaler("FallDistance", TagType.TAG_FLOAT),
|
||||
new SchemaNodeScaler("Fire", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Air", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("OnGround", TagType.TAG_BYTE),
|
||||
};
|
||||
|
||||
private Vector3 _pos;
|
||||
|
@ -127,26 +127,26 @@ namespace Substrate
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public UntypedEntity LoadTree (TagValue tree)
|
||||
public UntypedEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TagList pos = ctree["Pos"].ToTagList();
|
||||
TagNodeList pos = ctree["Pos"].ToTagList();
|
||||
_pos = new Vector3();
|
||||
_pos.X = pos[0].ToTagDouble();
|
||||
_pos.Y = pos[1].ToTagDouble();
|
||||
_pos.Z = pos[2].ToTagDouble();
|
||||
|
||||
TagList motion = ctree["Motion"].ToTagList();
|
||||
TagNodeList motion = ctree["Motion"].ToTagList();
|
||||
_motion = new Vector3();
|
||||
_motion.X = motion[0].ToTagDouble();
|
||||
_motion.Y = motion[1].ToTagDouble();
|
||||
_motion.Z = motion[2].ToTagDouble();
|
||||
|
||||
TagList rotation = ctree["Rotation"].ToTagList();
|
||||
TagNodeList rotation = ctree["Rotation"].ToTagList();
|
||||
_rotation = new Orientation();
|
||||
_rotation.Yaw = rotation[0].ToTagFloat();
|
||||
_rotation.Pitch = rotation[1].ToTagFloat();
|
||||
|
@ -158,7 +158,7 @@ namespace Substrate
|
|||
return this;
|
||||
}
|
||||
|
||||
public UntypedEntity LoadTreeSafe (TagValue tree)
|
||||
public UntypedEntity LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -167,36 +167,36 @@ namespace Substrate
|
|||
return LoadTree(tree);
|
||||
}
|
||||
|
||||
public TagValue BuildTree ()
|
||||
public TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = new TagCompound();
|
||||
TagNodeCompound tree = new TagNodeCompound();
|
||||
|
||||
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));
|
||||
TagNodeList pos = new TagNodeList(TagType.TAG_DOUBLE);
|
||||
pos.Add(new TagNodeDouble(_pos.X));
|
||||
pos.Add(new TagNodeDouble(_pos.Y));
|
||||
pos.Add(new TagNodeDouble(_pos.Z));
|
||||
tree["Pos"] = pos;
|
||||
|
||||
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));
|
||||
TagNodeList motion = new TagNodeList(TagType.TAG_DOUBLE);
|
||||
motion.Add(new TagNodeDouble(_motion.X));
|
||||
motion.Add(new TagNodeDouble(_motion.Y));
|
||||
motion.Add(new TagNodeDouble(_motion.Z));
|
||||
tree["Motion"] = motion;
|
||||
|
||||
TagList rotation = new TagList(TagType.TAG_FLOAT);
|
||||
rotation.Add(new TagFloat((float)_rotation.Yaw));
|
||||
rotation.Add(new TagFloat((float)_rotation.Pitch));
|
||||
TagNodeList rotation = new TagNodeList(TagType.TAG_FLOAT);
|
||||
rotation.Add(new TagNodeFloat((float)_rotation.Yaw));
|
||||
rotation.Add(new TagNodeFloat((float)_rotation.Pitch));
|
||||
tree["Rotation"] = rotation;
|
||||
|
||||
tree["FallDistance"] = new TagFloat(_fallDistance);
|
||||
tree["Fire"] = new TagShort(_fire);
|
||||
tree["Air"] = new TagShort(_air);
|
||||
tree["OnGround"] = new TagByte(_onGround);
|
||||
tree["FallDistance"] = new TagNodeFloat(_fallDistance);
|
||||
tree["Fire"] = new TagNodeShort(_fire);
|
||||
tree["Air"] = new TagNodeShort(_air);
|
||||
tree["OnGround"] = new TagNodeByte(_onGround);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public bool ValidateTree (TagValue tree)
|
||||
public bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, UTBaseSchema).Verify();
|
||||
}
|
||||
|
@ -216,9 +216,9 @@ namespace Substrate
|
|||
|
||||
public class Entity : UntypedEntity, INBTObject<Entity>, ICopyable<Entity>
|
||||
{
|
||||
public static readonly NBTCompoundNode BaseSchema = UTBaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound BaseSchema = UTBaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTScalerNode("id", TagType.TAG_STRING),
|
||||
new SchemaNodeScaler("id", TagType.TAG_STRING),
|
||||
});
|
||||
|
||||
private string _id;
|
||||
|
@ -243,9 +243,9 @@ namespace Substrate
|
|||
|
||||
#region INBTObject<Entity> Members
|
||||
|
||||
public virtual new Entity LoadTree (TagValue tree)
|
||||
public virtual new Entity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ namespace Substrate
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual new Entity LoadTreeSafe (TagValue tree)
|
||||
public virtual new Entity LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -264,15 +264,15 @@ namespace Substrate
|
|||
return LoadTree(tree);
|
||||
}
|
||||
|
||||
public virtual new TagValue BuildTree ()
|
||||
public virtual new TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["id"] = new TagString(_id);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["id"] = new TagNodeString(_id);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public virtual new bool ValidateTree (TagValue tree)
|
||||
public virtual new bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, BaseSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Substrate
|
|||
|
||||
public class EntityCollection : IEnumerable<Entity>
|
||||
{
|
||||
private TagList _entities;
|
||||
private TagNodeList _entities;
|
||||
|
||||
private bool _dirty;
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace Substrate
|
|||
set { _dirty = value; }
|
||||
}
|
||||
|
||||
public EntityCollection (TagList entities)
|
||||
public EntityCollection (TagNodeList entities)
|
||||
{
|
||||
_entities = entities;
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ namespace Substrate
|
|||
{
|
||||
List<Entity> set = new List<Entity>();
|
||||
|
||||
foreach (TagCompound ent in _entities) {
|
||||
TagValue eid;
|
||||
foreach (TagNodeCompound ent in _entities) {
|
||||
TagNode eid;
|
||||
if (!ent.TryGetValue("id", out eid)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace Substrate
|
|||
{
|
||||
List<Entity> set = new List<Entity>();
|
||||
|
||||
foreach (TagCompound ent in _entities) {
|
||||
foreach (TagNodeCompound ent in _entities) {
|
||||
Entity obj = EntityFactory.Create(ent);
|
||||
if (obj == null) {
|
||||
continue;
|
||||
|
@ -86,12 +86,12 @@ namespace Substrate
|
|||
{
|
||||
int rem = _entities.RemoveAll(val =>
|
||||
{
|
||||
TagCompound cval = val as TagCompound;
|
||||
TagNodeCompound cval = val as TagNodeCompound;
|
||||
if (cval == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TagValue sval;
|
||||
TagNode sval;
|
||||
if (!cval.TryGetValue("id", out sval)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ namespace Substrate
|
|||
{
|
||||
int rem = _entities.RemoveAll(val =>
|
||||
{
|
||||
TagCompound cval = val as TagCompound;
|
||||
TagNodeCompound cval = val as TagNodeCompound;
|
||||
if (cval == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -150,11 +150,11 @@ namespace Substrate
|
|||
|
||||
public class EntityEnumerator : IEnumerator<Entity>
|
||||
{
|
||||
private IEnumerator<TagValue> _enum;
|
||||
private IEnumerator<TagNode> _enum;
|
||||
|
||||
private Entity _cur;
|
||||
|
||||
public EntityEnumerator (TagList entities)
|
||||
public EntityEnumerator (TagNodeList entities)
|
||||
{
|
||||
_enum = entities.GetEnumerator();
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ namespace Substrate
|
|||
return Activator.CreateInstance(t) as Entity;
|
||||
}
|
||||
|
||||
public static Entity Create (TagCompound tree)
|
||||
public static Entity Create (TagNodeCompound tree)
|
||||
{
|
||||
TagValue type;
|
||||
TagNode type;
|
||||
if (!tree.TryGetValue("id", out type)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ namespace Substrate
|
|||
|
||||
public class Item : INBTObject<Item>, ICopyable<Item>
|
||||
{
|
||||
public static readonly NBTCompoundNode ItemSchema = new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound ItemSchema = new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTScalerNode("id", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("Damage", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("Count", TagType.TAG_BYTE),
|
||||
new SchemaNodeScaler("id", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Damage", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Count", TagType.TAG_BYTE),
|
||||
};
|
||||
|
||||
private short _id;
|
||||
|
@ -73,9 +73,9 @@ namespace Substrate
|
|||
|
||||
#region INBTObject<Item> Members
|
||||
|
||||
public Item LoadTree (TagValue tree)
|
||||
public Item LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ namespace Substrate
|
|||
return this;
|
||||
}
|
||||
|
||||
public Item LoadTreeSafe (TagValue tree)
|
||||
public Item LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -96,17 +96,17 @@ namespace Substrate
|
|||
return LoadTree(tree);
|
||||
}
|
||||
|
||||
public TagValue BuildTree ()
|
||||
public TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = new TagCompound();
|
||||
tree["id"] = new TagShort(_id);
|
||||
tree["Count"] = new TagByte(_count);
|
||||
tree["Damage"] = new TagShort(_damage);
|
||||
TagNodeCompound tree = new TagNodeCompound();
|
||||
tree["id"] = new TagNodeShort(_id);
|
||||
tree["Count"] = new TagNodeByte(_count);
|
||||
tree["Damage"] = new TagNodeShort(_damage);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public bool ValidateTree (TagValue tree)
|
||||
public bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ItemSchema).Verify();
|
||||
}
|
||||
|
@ -116,12 +116,12 @@ namespace Substrate
|
|||
|
||||
public class ItemCollection : INBTObject<ItemCollection>, ICopyable<ItemCollection>
|
||||
{
|
||||
public static readonly NBTCompoundNode InventorySchema = Item.ItemSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound InventorySchema = Item.ItemSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTScalerNode("Slot", TagType.TAG_BYTE),
|
||||
new SchemaNodeScaler("Slot", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
public static readonly NBTListNode ListSchema = new NBTListNode("", TagType.TAG_COMPOUND, InventorySchema);
|
||||
public static readonly SchemaNodeList ListSchema = new SchemaNodeList("", TagType.TAG_COMPOUND, InventorySchema);
|
||||
|
||||
protected Dictionary<int, Item> _items;
|
||||
protected int _capacity;
|
||||
|
@ -190,14 +190,14 @@ namespace Substrate
|
|||
|
||||
#region INBTObject<ItemCollection> Members
|
||||
|
||||
public ItemCollection LoadTree (TagValue tree)
|
||||
public ItemCollection LoadTree (TagNode tree)
|
||||
{
|
||||
TagList ltree = tree as TagList;
|
||||
TagNodeList ltree = tree as TagNodeList;
|
||||
if (ltree == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (TagCompound item in ltree) {
|
||||
foreach (TagNodeCompound item in ltree) {
|
||||
int slot = item["Slot"].ToTagByte();
|
||||
_items[slot] = new Item().LoadTree(item);
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ namespace Substrate
|
|||
return this;
|
||||
}
|
||||
|
||||
public ItemCollection LoadTreeSafe (TagValue tree)
|
||||
public ItemCollection LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -214,20 +214,20 @@ namespace Substrate
|
|||
return LoadTree(tree);
|
||||
}
|
||||
|
||||
public TagValue BuildTree ()
|
||||
public TagNode BuildTree ()
|
||||
{
|
||||
TagList list = new TagList(TagType.TAG_COMPOUND);
|
||||
TagNodeList list = new TagNodeList(TagType.TAG_COMPOUND);
|
||||
|
||||
foreach (KeyValuePair<int, Item> item in _items) {
|
||||
TagCompound itemtree = item.Value.BuildTree() as TagCompound;
|
||||
itemtree["Slot"] = new TagByte((byte)item.Key);
|
||||
TagNodeCompound itemtree = item.Value.BuildTree() as TagNodeCompound;
|
||||
itemtree["Slot"] = new TagNodeByte((byte)item.Key);
|
||||
list.Add(itemtree);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool ValidateTree (TagValue tree)
|
||||
public bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ListSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -10,24 +10,24 @@ namespace Substrate
|
|||
|
||||
public class Level : INBTObject<Level>, ICopyable<Level>
|
||||
{
|
||||
public static NBTCompoundNode LevelSchema = new NBTCompoundNode()
|
||||
public static SchemaNodeCompound LevelSchema = new SchemaNodeCompound()
|
||||
{
|
||||
new NBTCompoundNode("Data")
|
||||
new SchemaNodeCompound("Data")
|
||||
{
|
||||
new NBTScalerNode("Time", TagType.TAG_LONG),
|
||||
new NBTScalerNode("LastPlayed", TagType.TAG_LONG, NBTOptions.CREATE_ON_MISSING),
|
||||
new NBTCompoundNode("Player", Player.PlayerSchema, 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, NBTOptions.CREATE_ON_MISSING),
|
||||
new NBTScalerNode("RandomSeed", TagType.TAG_LONG),
|
||||
new NBTScalerNode("version", TagType.TAG_INT, NBTOptions.OPTIONAL),
|
||||
new NBTScalerNode("LevelName", TagType.TAG_STRING, NBTOptions.OPTIONAL),
|
||||
new NBTScalerNode("raining", TagType.TAG_BYTE, NBTOptions.OPTIONAL),
|
||||
new NBTScalerNode("thundering", TagType.TAG_BYTE, NBTOptions.OPTIONAL),
|
||||
new NBTScalerNode("rainTime", TagType.TAG_INT, NBTOptions.OPTIONAL),
|
||||
new NBTScalerNode("thunderTime", TagType.TAG_INT, NBTOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("Time", TagType.TAG_LONG),
|
||||
new SchemaNodeScaler("LastPlayed", TagType.TAG_LONG, SchemaOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeCompound("Player", Player.PlayerSchema, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("SpawnX", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("SpawnY", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("SpawnZ", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("SizeOnDisk", TagType.TAG_LONG, SchemaOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeScaler("RandomSeed", TagType.TAG_LONG),
|
||||
new SchemaNodeScaler("version", TagType.TAG_INT, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("LevelName", TagType.TAG_STRING, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("raining", TagType.TAG_BYTE, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("thundering", TagType.TAG_BYTE, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("rainTime", TagType.TAG_INT, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("thunderTime", TagType.TAG_INT, SchemaOptions.OPTIONAL),
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -206,7 +206,7 @@ namespace Substrate
|
|||
return false;
|
||||
}
|
||||
|
||||
new NBT_Tree(BuildTree() as TagCompound).WriteTo(zipstr);
|
||||
new NBT_Tree(BuildTree() as TagNodeCompound).WriteTo(zipstr);
|
||||
zipstr.Close();
|
||||
|
||||
return true;
|
||||
|
@ -215,9 +215,9 @@ namespace Substrate
|
|||
|
||||
#region INBTObject<Player> Members
|
||||
|
||||
public virtual Level LoadTree (TagValue tree)
|
||||
public virtual Level LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound dtree = tree as TagCompound;
|
||||
TagNodeCompound dtree = tree as TagNodeCompound;
|
||||
if (dtree == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ namespace Substrate
|
|||
_thundering = null;
|
||||
_thunderTime = null;
|
||||
|
||||
TagCompound ctree = dtree["Data"].ToTagCompound();
|
||||
TagNodeCompound ctree = dtree["Data"].ToTagCompound();
|
||||
|
||||
_time = ctree["Time"].ToTagLong();
|
||||
_lastPlayed = ctree["LastPlayed"].ToTagLong();
|
||||
|
@ -267,7 +267,7 @@ namespace Substrate
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual Level LoadTreeSafe (TagValue tree)
|
||||
public virtual Level LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -276,50 +276,50 @@ namespace Substrate
|
|||
return LoadTree(tree);
|
||||
}
|
||||
|
||||
public virtual TagValue BuildTree ()
|
||||
public virtual TagNode BuildTree ()
|
||||
{
|
||||
TagCompound data = new TagCompound();
|
||||
data["Time"] = new TagLong(_time);
|
||||
data["LastPlayed"] = new TagLong(_lastPlayed);
|
||||
TagNodeCompound data = new TagNodeCompound();
|
||||
data["Time"] = new TagNodeLong(_time);
|
||||
data["LastPlayed"] = new TagNodeLong(_lastPlayed);
|
||||
|
||||
if (_player != null) {
|
||||
data["Player"] = _player.BuildTree();
|
||||
}
|
||||
|
||||
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);
|
||||
data["SpawnX"] = new TagNodeInt(_spawnX);
|
||||
data["SpawnY"] = new TagNodeInt(_spawnY);
|
||||
data["SpawnZ"] = new TagNodeInt(_spawnZ);
|
||||
data["SizeOnDisk"] = new TagNodeLong(_sizeOnDisk);
|
||||
data["RandomSeed"] = new TagNodeLong(_randomSeed);
|
||||
|
||||
if (_version != null && _version != 0) {
|
||||
data["version"] = new TagInt(_version ?? 0);
|
||||
data["version"] = new TagNodeInt(_version ?? 0);
|
||||
}
|
||||
|
||||
if (_name != null) {
|
||||
data["LevelName"] = new TagString(_name);
|
||||
data["LevelName"] = new TagNodeString(_name);
|
||||
}
|
||||
|
||||
if (_raining != null) {
|
||||
data["raining"] = new TagByte(_raining ?? 0);
|
||||
data["raining"] = new TagNodeByte(_raining ?? 0);
|
||||
}
|
||||
if (_thundering != null) {
|
||||
data["thundering"] = new TagByte(_thundering ?? 0);
|
||||
data["thundering"] = new TagNodeByte(_thundering ?? 0);
|
||||
}
|
||||
if (_rainTime != null) {
|
||||
data["rainTime"] = new TagInt(_rainTime ?? 0);
|
||||
data["rainTime"] = new TagNodeInt(_rainTime ?? 0);
|
||||
}
|
||||
if (_thunderTime != null) {
|
||||
data["thunderTime"] = new TagInt(_thunderTime ?? 0);
|
||||
data["thunderTime"] = new TagNodeInt(_thunderTime ?? 0);
|
||||
}
|
||||
|
||||
TagCompound tree = new TagCompound();
|
||||
TagNodeCompound tree = new TagNodeCompound();
|
||||
tree.Add("Data", data);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public virtual bool ValidateTree (TagValue tree)
|
||||
public virtual bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, LevelSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,20 +8,20 @@ namespace Substrate.NBT
|
|||
|
||||
public class JSONSerializer
|
||||
{
|
||||
public static string Serialize (TagValue tag)
|
||||
public static string Serialize (TagNode tag)
|
||||
{
|
||||
return Serialize(tag, 0);
|
||||
}
|
||||
|
||||
public static string Serialize (TagValue tag, int level)
|
||||
public static string Serialize (TagNode tag, int level)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
if (tag.GetTagType() == TagType.TAG_COMPOUND) {
|
||||
SerializeCompound(tag as TagCompound, str, level);
|
||||
SerializeCompound(tag as TagNodeCompound, str, level);
|
||||
}
|
||||
else if (tag.GetTagType() == TagType.TAG_LIST) {
|
||||
SerializeList(tag as TagList, str, level);
|
||||
SerializeList(tag as TagNodeList, str, level);
|
||||
}
|
||||
else {
|
||||
SerializeScaler(tag, str);
|
||||
|
@ -30,7 +30,7 @@ namespace Substrate.NBT
|
|||
return str.ToString();
|
||||
}
|
||||
|
||||
private static void SerializeCompound (TagCompound tag, StringBuilder str, int level)
|
||||
private static void SerializeCompound (TagNodeCompound tag, StringBuilder str, int level)
|
||||
{
|
||||
if (tag.Count == 0) {
|
||||
str.Append("{ }");
|
||||
|
@ -40,7 +40,7 @@ namespace Substrate.NBT
|
|||
str.AppendLine();
|
||||
AddLine(str, "{", level);
|
||||
|
||||
IEnumerator<KeyValuePair<string, TagValue>> en = tag.GetEnumerator();
|
||||
IEnumerator<KeyValuePair<string, TagNode>> en = tag.GetEnumerator();
|
||||
bool first = true;
|
||||
while (en.MoveNext()) {
|
||||
if (!first) {
|
||||
|
@ -48,14 +48,14 @@ namespace Substrate.NBT
|
|||
str.AppendLine();
|
||||
}
|
||||
|
||||
KeyValuePair<string, TagValue> item = en.Current;
|
||||
KeyValuePair<string, TagNode> item = en.Current;
|
||||
Add(str, "\"" + item.Key + "\": ", level + 1);
|
||||
|
||||
if (item.Value.GetTagType() == TagType.TAG_COMPOUND) {
|
||||
SerializeCompound(item.Value as TagCompound, str, level + 1);
|
||||
SerializeCompound(item.Value as TagNodeCompound, str, level + 1);
|
||||
}
|
||||
else if (item.Value.GetTagType() == TagType.TAG_LIST) {
|
||||
SerializeList(item.Value as TagList, str, level + 1);
|
||||
SerializeList(item.Value as TagNodeList, str, level + 1);
|
||||
}
|
||||
else {
|
||||
SerializeScaler(item.Value, str);
|
||||
|
@ -68,7 +68,7 @@ namespace Substrate.NBT
|
|||
Add(str, "}", level);
|
||||
}
|
||||
|
||||
private static void SerializeList (TagList tag, StringBuilder str, int level)
|
||||
private static void SerializeList (TagNodeList tag, StringBuilder str, int level)
|
||||
{
|
||||
if (tag.Count == 0) {
|
||||
str.Append("[ ]");
|
||||
|
@ -78,20 +78,20 @@ namespace Substrate.NBT
|
|||
str.AppendLine();
|
||||
AddLine(str, "[", level);
|
||||
|
||||
IEnumerator<TagValue> en = tag.GetEnumerator();
|
||||
IEnumerator<TagNode> en = tag.GetEnumerator();
|
||||
bool first = true;
|
||||
while (en.MoveNext()) {
|
||||
if (!first) {
|
||||
str.Append(",");
|
||||
}
|
||||
|
||||
TagValue item = en.Current;
|
||||
TagNode item = en.Current;
|
||||
|
||||
if (item.GetTagType() == TagType.TAG_COMPOUND) {
|
||||
SerializeCompound(item as TagCompound, str, level + 1);
|
||||
SerializeCompound(item as TagNodeCompound, str, level + 1);
|
||||
}
|
||||
else if (item.GetTagType() == TagType.TAG_LIST) {
|
||||
SerializeList(item as TagList, str, level + 1);
|
||||
SerializeList(item as TagNodeList, str, level + 1);
|
||||
}
|
||||
else {
|
||||
if (!first) {
|
||||
|
@ -109,7 +109,7 @@ namespace Substrate.NBT
|
|||
Add(str, "]", level);
|
||||
}
|
||||
|
||||
private static void SerializeScaler (TagValue tag, StringBuilder str)
|
||||
private static void SerializeScaler (TagNode tag, StringBuilder str)
|
||||
{
|
||||
switch (tag.GetTagType()) {
|
||||
case TagType.TAG_STRING:
|
||||
|
|
|
@ -8,43 +8,93 @@ namespace Substrate.NBT
|
|||
{
|
||||
using Substrate.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// Defines methods for loading or extracting an NBT tree.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Object type that supports this interface.</typeparam>
|
||||
public interface INBTObject<T>
|
||||
{
|
||||
T LoadTree (TagValue tree);
|
||||
T LoadTreeSafe (TagValue tree);
|
||||
/// <summary>
|
||||
/// Attempt to load an NBT tree into the object without validation.
|
||||
/// </summary>
|
||||
/// <param name="tree">The root node of an NBT tree.</param>
|
||||
/// <returns>The object returns itself on success, or null if the tree was unparsable.</returns>
|
||||
T LoadTree (TagNode tree);
|
||||
|
||||
TagValue BuildTree ();
|
||||
/// <summary>
|
||||
/// Attempt to load an NBT tree into the object with validation.
|
||||
/// </summary>
|
||||
/// <param name="tree">The root node of an NBT tree.</param>
|
||||
/// <returns>The object returns itself on success, or null if the tree failed validation.</returns>
|
||||
T LoadTreeSafe (TagNode tree);
|
||||
|
||||
bool ValidateTree (TagValue tree);
|
||||
/// <summary>
|
||||
/// Builds an NBT tree from the object's data.
|
||||
/// </summary>
|
||||
/// <returns>The root node of an NBT tree representing the object's data.</returns>
|
||||
TagNode BuildTree ();
|
||||
|
||||
/// <summary>
|
||||
/// Validate an NBT tree, usually against an object-supplied schema.
|
||||
/// </summary>
|
||||
/// <param name="tree">The root node of an NBT tree.</param>
|
||||
/// <returns>Status indicating whether the tree was valid for this object.</returns>
|
||||
bool ValidateTree (TagNode tree);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the root node of an NBT tree and handles IO of tree nodes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// NBT, or Named Byte Tag, is a tree-based data structure for storing most Minecraft data.
|
||||
/// NBT_Tree is more of a helper class for NBT trees that handles reading and writing nodes to data streams.
|
||||
/// Most of the API takes a TagValue or derived node as the root of the tree, rather than an NBT_Tree object itself.
|
||||
/// </remarks>
|
||||
public class NBT_Tree : ICopyable<NBT_Tree>
|
||||
{
|
||||
private Stream _stream = null;
|
||||
private TagCompound _root = null;
|
||||
private TagNodeCompound _root = null;
|
||||
|
||||
private static TagNull _nulltag = new TagNull();
|
||||
private static TagNodeNull _nulltag = new TagNodeNull();
|
||||
|
||||
public TagCompound Root
|
||||
/// <summary>
|
||||
/// Gets the root node of this tree.
|
||||
/// </summary>
|
||||
public TagNodeCompound Root
|
||||
{
|
||||
get { return _root; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a wrapper around a new NBT tree with an empty root node.
|
||||
/// </summary>
|
||||
public NBT_Tree ()
|
||||
{
|
||||
_root = new TagCompound();
|
||||
_root = new TagNodeCompound();
|
||||
}
|
||||
|
||||
public NBT_Tree (TagCompound tree)
|
||||
/// <summary>
|
||||
/// Constructs a wrapper around another NBT tree.
|
||||
/// </summary>
|
||||
/// <param name="tree">The root node of an NBT tree.</param>
|
||||
public NBT_Tree (TagNodeCompound tree)
|
||||
{
|
||||
_root = tree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs and wrapper around a new NBT tree parsed from a source data stream.
|
||||
/// </summary>
|
||||
/// <param name="s">An open, readable data stream containing NBT data.</param>
|
||||
public NBT_Tree (Stream s)
|
||||
{
|
||||
ReadFrom(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rebuild the internal NBT tree from a source data stream.
|
||||
/// </summary>
|
||||
/// <param name="s">An open, readable data stream containing NBT data.</param>
|
||||
public void ReadFrom (Stream s)
|
||||
{
|
||||
if (s != null) {
|
||||
|
@ -54,6 +104,10 @@ namespace Substrate.NBT
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes out the internal NBT tree to a destination data stream.
|
||||
/// </summary>
|
||||
/// <param name="s">An open, writable data stream.</param>
|
||||
public void WriteTo (Stream s)
|
||||
{
|
||||
if (s != null) {
|
||||
|
@ -67,7 +121,7 @@ namespace Substrate.NBT
|
|||
}
|
||||
}
|
||||
|
||||
private TagValue ReadValue (TagType type)
|
||||
private TagNode ReadValue (TagType type)
|
||||
{
|
||||
switch (type) {
|
||||
case TagType.TAG_END:
|
||||
|
@ -107,19 +161,19 @@ namespace Substrate.NBT
|
|||
throw new Exception();
|
||||
}
|
||||
|
||||
private TagValue ReadByte ()
|
||||
private TagNode ReadByte ()
|
||||
{
|
||||
int gzByte = _stream.ReadByte();
|
||||
if (gzByte == -1) {
|
||||
throw new NBTException(NBTException.MSG_GZIP_ENDOFSTREAM);
|
||||
}
|
||||
|
||||
TagByte val = new TagByte((byte)gzByte);
|
||||
TagNodeByte val = new TagNodeByte((byte)gzByte);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadShort ()
|
||||
private TagNode ReadShort ()
|
||||
{
|
||||
byte[] gzBytes = new byte[2];
|
||||
_stream.Read(gzBytes, 0, 2);
|
||||
|
@ -128,12 +182,12 @@ namespace Substrate.NBT
|
|||
Array.Reverse(gzBytes);
|
||||
}
|
||||
|
||||
TagShort val = new TagShort(BitConverter.ToInt16(gzBytes, 0));
|
||||
TagNodeShort val = new TagNodeShort(BitConverter.ToInt16(gzBytes, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadInt ()
|
||||
private TagNode ReadInt ()
|
||||
{
|
||||
byte[] gzBytes = new byte[4];
|
||||
_stream.Read(gzBytes, 0, 4);
|
||||
|
@ -142,12 +196,12 @@ namespace Substrate.NBT
|
|||
Array.Reverse(gzBytes);
|
||||
}
|
||||
|
||||
TagInt val = new TagInt(BitConverter.ToInt32(gzBytes, 0));
|
||||
TagNodeInt val = new TagNodeInt(BitConverter.ToInt32(gzBytes, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadLong ()
|
||||
private TagNode ReadLong ()
|
||||
{
|
||||
byte[] gzBytes = new byte[8];
|
||||
_stream.Read(gzBytes, 0, 8);
|
||||
|
@ -156,12 +210,12 @@ namespace Substrate.NBT
|
|||
Array.Reverse(gzBytes);
|
||||
}
|
||||
|
||||
TagLong val = new TagLong(BitConverter.ToInt64(gzBytes, 0));
|
||||
TagNodeLong val = new TagNodeLong(BitConverter.ToInt64(gzBytes, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadFloat ()
|
||||
private TagNode ReadFloat ()
|
||||
{
|
||||
byte[] gzBytes = new byte[4];
|
||||
_stream.Read(gzBytes, 0, 4);
|
||||
|
@ -170,12 +224,12 @@ namespace Substrate.NBT
|
|||
Array.Reverse(gzBytes);
|
||||
}
|
||||
|
||||
TagFloat val = new TagFloat(BitConverter.ToSingle(gzBytes, 0));
|
||||
TagNodeFloat val = new TagNodeFloat(BitConverter.ToSingle(gzBytes, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadDouble ()
|
||||
private TagNode ReadDouble ()
|
||||
{
|
||||
byte[] gzBytes = new byte[8];
|
||||
_stream.Read(gzBytes, 0, 8);
|
||||
|
@ -184,12 +238,12 @@ namespace Substrate.NBT
|
|||
Array.Reverse(gzBytes);
|
||||
}
|
||||
|
||||
TagDouble val = new TagDouble(BitConverter.ToDouble(gzBytes, 0));
|
||||
TagNodeDouble val = new TagNodeDouble(BitConverter.ToDouble(gzBytes, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadByteArray ()
|
||||
private TagNode ReadByteArray ()
|
||||
{
|
||||
byte[] lenBytes = new byte[4];
|
||||
_stream.Read(lenBytes, 0, 4);
|
||||
|
@ -206,12 +260,12 @@ namespace Substrate.NBT
|
|||
byte[] data = new byte[length];
|
||||
_stream.Read(data, 0, length);
|
||||
|
||||
TagByteArray val = new TagByteArray(data);
|
||||
TagNodeByteArray val = new TagNodeByteArray(data);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadString ()
|
||||
private TagNode ReadString ()
|
||||
{
|
||||
byte[] lenBytes = new byte[2];
|
||||
_stream.Read(lenBytes, 0, 2);
|
||||
|
@ -230,19 +284,19 @@ namespace Substrate.NBT
|
|||
|
||||
System.Text.Encoding str = Encoding.GetEncoding(28591);
|
||||
|
||||
TagString val = new TagString(str.GetString(strBytes));
|
||||
TagNodeString val = new TagNodeString(str.GetString(strBytes));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadList ()
|
||||
private TagNode ReadList ()
|
||||
{
|
||||
int gzByte = _stream.ReadByte();
|
||||
if (gzByte == -1) {
|
||||
throw new NBTException(NBTException.MSG_GZIP_ENDOFSTREAM);
|
||||
}
|
||||
|
||||
TagList val = new TagList((TagType)gzByte);
|
||||
TagNodeList val = new TagNodeList((TagType)gzByte);
|
||||
if (val.ValueType > (TagType)Enum.GetValues(typeof(TagType)).GetUpperBound(0)) {
|
||||
throw new NBTException(NBTException.MSG_READ_TYPE);
|
||||
}
|
||||
|
@ -266,27 +320,27 @@ namespace Substrate.NBT
|
|||
return val;
|
||||
}
|
||||
|
||||
private TagValue ReadCompound ()
|
||||
private TagNode ReadCompound ()
|
||||
{
|
||||
TagCompound val = new TagCompound();
|
||||
TagNodeCompound val = new TagNodeCompound();
|
||||
|
||||
while (ReadTag(val)) ;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private TagCompound ReadRoot ()
|
||||
private TagNodeCompound ReadRoot ()
|
||||
{
|
||||
TagType type = (TagType)_stream.ReadByte();
|
||||
if (type == TagType.TAG_COMPOUND) {
|
||||
ReadString(); // name
|
||||
return ReadValue(type) as TagCompound;
|
||||
return ReadValue(type) as TagNodeCompound;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ReadTag (TagCompound parent)
|
||||
private bool ReadTag (TagNodeCompound parent)
|
||||
{
|
||||
//NBT_Tag tag = new NBT_Tag();
|
||||
|
||||
|
@ -304,7 +358,7 @@ namespace Substrate.NBT
|
|||
//return tag;
|
||||
}
|
||||
|
||||
private void WriteValue (TagValue val)
|
||||
private void WriteValue (TagNode val)
|
||||
{
|
||||
switch (val.GetTagType()) {
|
||||
case TagType.TAG_END:
|
||||
|
@ -352,12 +406,12 @@ namespace Substrate.NBT
|
|||
}
|
||||
}
|
||||
|
||||
private void WriteByte (TagByte val)
|
||||
private void WriteByte (TagNodeByte val)
|
||||
{
|
||||
_stream.WriteByte(val.Data);
|
||||
}
|
||||
|
||||
private void WriteShort (TagShort val)
|
||||
private void WriteShort (TagNodeShort val)
|
||||
{
|
||||
byte[] gzBytes = BitConverter.GetBytes(val.Data);
|
||||
|
||||
|
@ -368,7 +422,7 @@ namespace Substrate.NBT
|
|||
_stream.Write(gzBytes, 0, 2);
|
||||
}
|
||||
|
||||
private void WriteInt (TagInt val)
|
||||
private void WriteInt (TagNodeInt val)
|
||||
{
|
||||
byte[] gzBytes = BitConverter.GetBytes(val.Data);
|
||||
|
||||
|
@ -379,7 +433,7 @@ namespace Substrate.NBT
|
|||
_stream.Write(gzBytes, 0, 4);
|
||||
}
|
||||
|
||||
private void WriteLong (TagLong val)
|
||||
private void WriteLong (TagNodeLong val)
|
||||
{
|
||||
byte[] gzBytes = BitConverter.GetBytes(val.Data);
|
||||
|
||||
|
@ -390,7 +444,7 @@ namespace Substrate.NBT
|
|||
_stream.Write(gzBytes, 0, 8);
|
||||
}
|
||||
|
||||
private void WriteFloat (TagFloat val)
|
||||
private void WriteFloat (TagNodeFloat val)
|
||||
{
|
||||
byte[] gzBytes = BitConverter.GetBytes(val.Data);
|
||||
|
||||
|
@ -401,7 +455,7 @@ namespace Substrate.NBT
|
|||
_stream.Write(gzBytes, 0, 4);
|
||||
}
|
||||
|
||||
private void WriteDouble (TagDouble val)
|
||||
private void WriteDouble (TagNodeDouble val)
|
||||
{
|
||||
byte[] gzBytes = BitConverter.GetBytes(val.Data);
|
||||
|
||||
|
@ -412,7 +466,7 @@ namespace Substrate.NBT
|
|||
_stream.Write(gzBytes, 0, 8);
|
||||
}
|
||||
|
||||
private void WriteByteArray (TagByteArray val)
|
||||
private void WriteByteArray (TagNodeByteArray val)
|
||||
{
|
||||
byte[] lenBytes = BitConverter.GetBytes(val.Length);
|
||||
|
||||
|
@ -424,7 +478,7 @@ namespace Substrate.NBT
|
|||
_stream.Write(val.Data, 0, val.Length);
|
||||
}
|
||||
|
||||
private void WriteString (TagString val)
|
||||
private void WriteString (TagNodeString val)
|
||||
{
|
||||
byte[] lenBytes = BitConverter.GetBytes((short)val.Length);
|
||||
|
||||
|
@ -440,7 +494,7 @@ namespace Substrate.NBT
|
|||
_stream.Write(gzBytes, 0, gzBytes.Length);
|
||||
}
|
||||
|
||||
private void WriteList (TagList val)
|
||||
private void WriteList (TagNodeList val)
|
||||
{
|
||||
byte[] lenBytes = BitConverter.GetBytes(val.Count);
|
||||
|
||||
|
@ -451,21 +505,21 @@ namespace Substrate.NBT
|
|||
_stream.WriteByte((byte)val.ValueType);
|
||||
_stream.Write(lenBytes, 0, 4);
|
||||
|
||||
foreach (TagValue v in val) {
|
||||
foreach (TagNode v in val) {
|
||||
WriteValue(v);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteCompound (TagCompound val)
|
||||
private void WriteCompound (TagNodeCompound val)
|
||||
{
|
||||
foreach (KeyValuePair<string, TagValue> item in val) {
|
||||
foreach (KeyValuePair<string, TagNode> item in val) {
|
||||
WriteTag(item.Key, item.Value);
|
||||
}
|
||||
|
||||
WriteTag(null, _nulltag);
|
||||
}
|
||||
|
||||
private void WriteTag (string name, TagValue val)
|
||||
private void WriteTag (string name, TagNode val)
|
||||
{
|
||||
_stream.WriteByte((byte)val.GetTagType());
|
||||
|
||||
|
@ -477,10 +531,14 @@ namespace Substrate.NBT
|
|||
|
||||
#region ICopyable<NBT_Tree> Members
|
||||
|
||||
/// <summary>
|
||||
/// Creates a deep copy of the NBT_Tree and underlying nodes.
|
||||
/// </summary>
|
||||
/// <returns>A new NBT_tree.</returns>
|
||||
public NBT_Tree Copy ()
|
||||
{
|
||||
NBT_Tree tree = new NBT_Tree();
|
||||
tree._root = _root.Copy() as TagCompound;
|
||||
tree._root = _root.Copy() as TagNodeCompound;
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
@ -488,6 +546,7 @@ namespace Substrate.NBT
|
|||
#endregion
|
||||
}
|
||||
|
||||
// TODO: Revise exceptions?
|
||||
public class NBTException : Exception
|
||||
{
|
||||
public const String MSG_GZIP_ENDOFSTREAM = "Gzip Error: Unexpected end of stream";
|
||||
|
|
|
@ -5,45 +5,45 @@ using System.Text;
|
|||
namespace Substrate.NBT
|
||||
{
|
||||
[Flags]
|
||||
public enum NBTOptions
|
||||
public enum SchemaOptions
|
||||
{
|
||||
OPTIONAL = 0x1,
|
||||
CREATE_ON_MISSING = 0x2,
|
||||
}
|
||||
|
||||
public abstract class NBTSchemaNode
|
||||
public abstract class SchemaNode
|
||||
{
|
||||
private string _name;
|
||||
private NBTOptions _options;
|
||||
private SchemaOptions _options;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
public NBTOptions Options
|
||||
public SchemaOptions Options
|
||||
{
|
||||
get { return _options; }
|
||||
}
|
||||
|
||||
public NBTSchemaNode (string name)
|
||||
public SchemaNode (string name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public NBTSchemaNode (string name, NBTOptions options)
|
||||
public SchemaNode (string name, SchemaOptions options)
|
||||
{
|
||||
_name = name;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public virtual TagValue BuildDefaultTree ()
|
||||
public virtual TagNode BuildDefaultTree ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NBTScalerNode : NBTSchemaNode
|
||||
public sealed class SchemaNodeScaler : SchemaNode
|
||||
{
|
||||
private TagType _type;
|
||||
|
||||
|
@ -52,48 +52,48 @@ namespace Substrate.NBT
|
|||
get { return _type; }
|
||||
}
|
||||
|
||||
public NBTScalerNode (string name, TagType type)
|
||||
public SchemaNodeScaler (string name, TagType type)
|
||||
: base(name)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public NBTScalerNode (string name, TagType type, NBTOptions options)
|
||||
public SchemaNodeScaler (string name, TagType type, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public override TagValue BuildDefaultTree ()
|
||||
public override TagNode BuildDefaultTree ()
|
||||
{
|
||||
switch (_type) {
|
||||
case TagType.TAG_STRING:
|
||||
return new TagString();
|
||||
return new TagNodeString();
|
||||
|
||||
case TagType.TAG_BYTE:
|
||||
return new TagByte();
|
||||
return new TagNodeByte();
|
||||
|
||||
case TagType.TAG_SHORT:
|
||||
return new TagShort();
|
||||
return new TagNodeShort();
|
||||
|
||||
case TagType.TAG_INT:
|
||||
return new TagInt();
|
||||
return new TagNodeInt();
|
||||
|
||||
case TagType.TAG_LONG:
|
||||
return new TagLong();
|
||||
return new TagNodeLong();
|
||||
|
||||
case TagType.TAG_FLOAT:
|
||||
return new TagFloat();
|
||||
return new TagNodeFloat();
|
||||
|
||||
case TagType.TAG_DOUBLE:
|
||||
return new TagDouble();
|
||||
return new TagNodeDouble();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NBTStringNode : NBTSchemaNode
|
||||
public sealed class SchemaNodeString : SchemaNode
|
||||
{
|
||||
private string _value = "";
|
||||
private int _length;
|
||||
|
@ -108,34 +108,34 @@ namespace Substrate.NBT
|
|||
get { return _value; }
|
||||
}
|
||||
|
||||
public NBTStringNode (string name, NBTOptions options)
|
||||
public SchemaNodeString (string name, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
}
|
||||
|
||||
public NBTStringNode (string name, string value)
|
||||
public SchemaNodeString (string name, string value)
|
||||
: base(name)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public NBTStringNode (string name, int length)
|
||||
public SchemaNodeString (string name, int length)
|
||||
: base(name)
|
||||
{
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public override TagValue BuildDefaultTree ()
|
||||
public override TagNode BuildDefaultTree ()
|
||||
{
|
||||
if (_value.Length > 0) {
|
||||
return new TagString(_value);
|
||||
return new TagNodeString(_value);
|
||||
}
|
||||
|
||||
return new TagString();
|
||||
return new TagNodeString();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NBTArrayNode : NBTSchemaNode
|
||||
public sealed class SchemaNodeArray : SchemaNode
|
||||
{
|
||||
private int _length;
|
||||
|
||||
|
@ -144,41 +144,41 @@ namespace Substrate.NBT
|
|||
get { return _length; }
|
||||
}
|
||||
|
||||
public NBTArrayNode (string name)
|
||||
public SchemaNodeArray (string name)
|
||||
: base(name)
|
||||
{
|
||||
_length = 0;
|
||||
}
|
||||
|
||||
public NBTArrayNode (string name, NBTOptions options)
|
||||
public SchemaNodeArray (string name, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_length = 0;
|
||||
}
|
||||
|
||||
public NBTArrayNode (string name, int length)
|
||||
public SchemaNodeArray (string name, int length)
|
||||
: base(name)
|
||||
{
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public NBTArrayNode (string name, int length, NBTOptions options)
|
||||
public SchemaNodeArray (string name, int length, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public override TagValue BuildDefaultTree ()
|
||||
public override TagNode BuildDefaultTree ()
|
||||
{
|
||||
return new TagByteArray(new byte[_length]);
|
||||
return new TagNodeByteArray(new byte[_length]);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NBTListNode : NBTSchemaNode
|
||||
public sealed class SchemaNodeList : SchemaNode
|
||||
{
|
||||
private TagType _type;
|
||||
private int _length;
|
||||
private NBTSchemaNode _subschema;
|
||||
private SchemaNode _subschema;
|
||||
|
||||
public int Length
|
||||
{
|
||||
|
@ -190,52 +190,52 @@ namespace Substrate.NBT
|
|||
get { return _type; }
|
||||
}
|
||||
|
||||
public NBTSchemaNode SubSchema
|
||||
public SchemaNode SubSchema
|
||||
{
|
||||
get { return _subschema; }
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type)
|
||||
public SchemaNodeList (string name, TagType type)
|
||||
: base(name)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type, NBTOptions options)
|
||||
public SchemaNodeList (string name, TagType type, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type, int length)
|
||||
public SchemaNodeList (string name, TagType type, int length)
|
||||
: base(name)
|
||||
{
|
||||
_type = type;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type, int length, NBTOptions options)
|
||||
public SchemaNodeList (string name, TagType type, int length, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_type = type;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type, NBTSchemaNode subschema)
|
||||
public SchemaNodeList (string name, TagType type, SchemaNode subschema)
|
||||
: base(name)
|
||||
{
|
||||
_type = type;
|
||||
_subschema = subschema;
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type, NBTSchemaNode subschema, NBTOptions options)
|
||||
public SchemaNodeList (string name, TagType type, SchemaNode subschema, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_type = type;
|
||||
_subschema = subschema;
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type, int length, NBTSchemaNode subschema)
|
||||
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema)
|
||||
: base(name)
|
||||
{
|
||||
_type = type;
|
||||
|
@ -243,7 +243,7 @@ namespace Substrate.NBT
|
|||
_subschema = subschema;
|
||||
}
|
||||
|
||||
public NBTListNode (string name, TagType type, int length, NBTSchemaNode subschema, NBTOptions options)
|
||||
public SchemaNodeList (string name, TagType type, int length, SchemaNode subschema, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_type = type;
|
||||
|
@ -251,13 +251,13 @@ namespace Substrate.NBT
|
|||
_subschema = subschema;
|
||||
}
|
||||
|
||||
public override TagValue BuildDefaultTree ()
|
||||
public override TagNode BuildDefaultTree ()
|
||||
{
|
||||
if (_length == 0) {
|
||||
return new TagList(_type);
|
||||
return new TagNodeList(_type);
|
||||
}
|
||||
|
||||
TagList list = new TagList(_type);
|
||||
TagNodeList list = new TagNodeList(_type);
|
||||
for (int i = 0; i < _length; i++) {
|
||||
list.Add(_subschema.BuildDefaultTree());
|
||||
}
|
||||
|
@ -266,13 +266,13 @@ namespace Substrate.NBT
|
|||
}
|
||||
}
|
||||
|
||||
public sealed class NBTCompoundNode : NBTSchemaNode, ICollection<NBTSchemaNode>
|
||||
public sealed class SchemaNodeCompound : SchemaNode, ICollection<SchemaNode>
|
||||
{
|
||||
private List<NBTSchemaNode> _subnodes;
|
||||
private List<SchemaNode> _subnodes;
|
||||
|
||||
#region ICollection<NBTSchemaNode> Members
|
||||
|
||||
public void Add (NBTSchemaNode item)
|
||||
public void Add (SchemaNode item)
|
||||
{
|
||||
_subnodes.Add(item);
|
||||
}
|
||||
|
@ -282,12 +282,12 @@ namespace Substrate.NBT
|
|||
_subnodes.Clear();
|
||||
}
|
||||
|
||||
public bool Contains (NBTSchemaNode item)
|
||||
public bool Contains (SchemaNode item)
|
||||
{
|
||||
return _subnodes.Contains(item);
|
||||
}
|
||||
|
||||
public void CopyTo (NBTSchemaNode[] array, int arrayIndex)
|
||||
public void CopyTo (SchemaNode[] array, int arrayIndex)
|
||||
{
|
||||
_subnodes.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ namespace Substrate.NBT
|
|||
get { return false; }
|
||||
}
|
||||
|
||||
public bool Remove (NBTSchemaNode item)
|
||||
public bool Remove (SchemaNode item)
|
||||
{
|
||||
return _subnodes.Remove(item);
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ namespace Substrate.NBT
|
|||
|
||||
#region IEnumerable<NBTSchemaNode> Members
|
||||
|
||||
public IEnumerator<NBTSchemaNode> GetEnumerator ()
|
||||
public IEnumerator<SchemaNode> GetEnumerator ()
|
||||
{
|
||||
return _subnodes.GetEnumerator();
|
||||
}
|
||||
|
@ -327,65 +327,65 @@ namespace Substrate.NBT
|
|||
|
||||
#endregion
|
||||
|
||||
public NBTCompoundNode ()
|
||||
public SchemaNodeCompound ()
|
||||
: base("")
|
||||
{
|
||||
_subnodes = new List<NBTSchemaNode>();
|
||||
_subnodes = new List<SchemaNode>();
|
||||
}
|
||||
|
||||
public NBTCompoundNode (NBTOptions options)
|
||||
public SchemaNodeCompound (SchemaOptions options)
|
||||
: base("", options)
|
||||
{
|
||||
_subnodes = new List<NBTSchemaNode>();
|
||||
_subnodes = new List<SchemaNode>();
|
||||
}
|
||||
|
||||
public NBTCompoundNode (string name)
|
||||
public SchemaNodeCompound (string name)
|
||||
: base(name)
|
||||
{
|
||||
_subnodes = new List<NBTSchemaNode>();
|
||||
_subnodes = new List<SchemaNode>();
|
||||
}
|
||||
|
||||
public NBTCompoundNode (string name, NBTOptions options)
|
||||
public SchemaNodeCompound (string name, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_subnodes = new List<NBTSchemaNode>();
|
||||
_subnodes = new List<SchemaNode>();
|
||||
}
|
||||
|
||||
public NBTCompoundNode (string name, NBTSchemaNode subschema)
|
||||
public SchemaNodeCompound (string name, SchemaNode subschema)
|
||||
: base(name)
|
||||
{
|
||||
_subnodes = new List<NBTSchemaNode>();
|
||||
_subnodes = new List<SchemaNode>();
|
||||
|
||||
NBTCompoundNode schema = subschema as NBTCompoundNode;
|
||||
SchemaNodeCompound schema = subschema as SchemaNodeCompound;
|
||||
if (schema == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (NBTSchemaNode node in schema._subnodes)
|
||||
foreach (SchemaNode node in schema._subnodes)
|
||||
{
|
||||
_subnodes.Add(node);
|
||||
}
|
||||
}
|
||||
|
||||
public NBTCompoundNode (string name, NBTSchemaNode subschema, NBTOptions options)
|
||||
public SchemaNodeCompound (string name, SchemaNode subschema, SchemaOptions options)
|
||||
: base(name, options)
|
||||
{
|
||||
_subnodes = new List<NBTSchemaNode>();
|
||||
_subnodes = new List<SchemaNode>();
|
||||
|
||||
NBTCompoundNode schema = subschema as NBTCompoundNode;
|
||||
SchemaNodeCompound schema = subschema as SchemaNodeCompound;
|
||||
if (schema == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (NBTSchemaNode node in schema._subnodes) {
|
||||
foreach (SchemaNode node in schema._subnodes) {
|
||||
_subnodes.Add(node);
|
||||
}
|
||||
}
|
||||
|
||||
public NBTCompoundNode MergeInto (NBTCompoundNode tree)
|
||||
public SchemaNodeCompound MergeInto (SchemaNodeCompound tree)
|
||||
{
|
||||
foreach (NBTSchemaNode node in _subnodes) {
|
||||
NBTSchemaNode f = tree._subnodes.Find(n => n.Name == node.Name);
|
||||
foreach (SchemaNode node in _subnodes) {
|
||||
SchemaNode f = tree._subnodes.Find(n => n.Name == node.Name);
|
||||
if (f != null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -395,10 +395,10 @@ namespace Substrate.NBT
|
|||
return tree;
|
||||
}
|
||||
|
||||
public override TagValue BuildDefaultTree ()
|
||||
public override TagNode BuildDefaultTree ()
|
||||
{
|
||||
TagCompound list = new TagCompound();
|
||||
foreach (NBTSchemaNode node in _subnodes) {
|
||||
TagNodeCompound list = new TagNodeCompound();
|
||||
foreach (SchemaNode node in _subnodes) {
|
||||
list[node.Name] = node.BuildDefaultTree();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,811 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.NBT {
|
||||
|
||||
using Substrate.Utility;
|
||||
|
||||
public enum TagType
|
||||
{
|
||||
TAG_END = 0,
|
||||
TAG_BYTE = 1, // 8 bits signed
|
||||
TAG_SHORT = 2, // 16 bits signed
|
||||
TAG_INT = 3, // 32 bits signed
|
||||
TAG_LONG = 4, // 64 bits signed
|
||||
TAG_FLOAT = 5,
|
||||
TAG_DOUBLE = 6,
|
||||
TAG_BYTE_ARRAY = 7,
|
||||
TAG_STRING = 8,
|
||||
TAG_LIST = 9,
|
||||
TAG_COMPOUND = 10
|
||||
}
|
||||
|
||||
public abstract class TagValue : ICopyable<TagValue>
|
||||
{
|
||||
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(); }
|
||||
|
||||
public virtual TagType GetTagType () { return TagType.TAG_END; }
|
||||
|
||||
public virtual bool IsCastableTo (TagType type)
|
||||
{
|
||||
return type == GetTagType();
|
||||
}
|
||||
|
||||
public virtual TagValue Copy ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TagNull : TagValue
|
||||
{
|
||||
public override TagNull ToTagNull () { return this; }
|
||||
public override TagType GetTagType () { return TagType.TAG_END; }
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagNull();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TagByte : TagValue
|
||||
{
|
||||
private byte _data = 0;
|
||||
|
||||
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
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public TagByte () { }
|
||||
|
||||
public TagByte (byte d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagByte(_data);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
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 sealed class TagShort : TagValue
|
||||
{
|
||||
private short _data = 0;
|
||||
|
||||
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
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public TagShort () { }
|
||||
|
||||
public TagShort (short d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagShort(_data);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
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 sealed class TagInt : TagValue
|
||||
{
|
||||
private int _data = 0;
|
||||
|
||||
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
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public TagInt () { }
|
||||
|
||||
public TagInt (int d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagInt(_data);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
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 sealed class TagLong : TagValue
|
||||
{
|
||||
private long _data = 0;
|
||||
|
||||
public override TagLong ToTagLong () { return this; }
|
||||
|
||||
public override TagType GetTagType () { return TagType.TAG_LONG; }
|
||||
|
||||
public long Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public TagLong () { }
|
||||
|
||||
public TagLong (long d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagLong(_data);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
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 sealed class TagFloat : TagValue
|
||||
{
|
||||
private float _data = 0;
|
||||
|
||||
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
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public TagFloat () { }
|
||||
|
||||
public TagFloat (float d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagFloat(_data);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
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 sealed class TagDouble : TagValue
|
||||
{
|
||||
private double _data = 0;
|
||||
|
||||
public override TagDouble ToTagDouble () { return this; }
|
||||
|
||||
public override TagType GetTagType () { return TagType.TAG_DOUBLE; }
|
||||
|
||||
public double Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public TagDouble () { }
|
||||
|
||||
public TagDouble (double d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagDouble(_data);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
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 sealed class TagByteArray : TagValue
|
||||
{
|
||||
private byte[] _data = null;
|
||||
|
||||
public override TagByteArray ToTagByteArray () { return this; }
|
||||
|
||||
public override TagType GetTagType () { return TagType.TAG_BYTE_ARRAY; }
|
||||
|
||||
public byte[] Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public int Length
|
||||
{
|
||||
get { return _data.Length; }
|
||||
}
|
||||
|
||||
public TagByteArray () { }
|
||||
|
||||
public TagByteArray (byte[] d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
byte[] arr = new byte[_data.Length];
|
||||
_data.CopyTo(arr, 0);
|
||||
|
||||
return new TagByteArray(arr);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
public byte this [int index] {
|
||||
get { return _data[index]; }
|
||||
set { _data[index] = value; }
|
||||
}
|
||||
|
||||
public static implicit operator TagByteArray (byte[] b)
|
||||
{
|
||||
return new TagByteArray(b);
|
||||
}
|
||||
|
||||
public static implicit operator byte[] (TagByteArray b)
|
||||
{
|
||||
return b._data;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TagString : TagValue
|
||||
{
|
||||
private string _data = "";
|
||||
|
||||
public override TagString ToTagString () { return this; }
|
||||
|
||||
public override TagType GetTagType () { return TagType.TAG_STRING; }
|
||||
|
||||
public string Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
public int Length
|
||||
{
|
||||
get { return _data.Length; }
|
||||
}
|
||||
|
||||
public TagString () { }
|
||||
|
||||
public TagString (string d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
return new TagString(_data);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
public static implicit operator TagString (string s)
|
||||
{
|
||||
return new TagString(s);
|
||||
}
|
||||
|
||||
public static implicit operator string (TagString s)
|
||||
{
|
||||
return s._data;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TagList : TagValue, IList<TagValue>
|
||||
{
|
||||
private TagType _type = TagType.TAG_END;
|
||||
|
||||
private List<TagValue> _items = null;
|
||||
|
||||
public override TagList ToTagList () { return this; }
|
||||
|
||||
public override TagType GetTagType () { return TagType.TAG_LIST; }
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return _items.Count; }
|
||||
}
|
||||
|
||||
public TagType ValueType
|
||||
{
|
||||
get { return _type; }
|
||||
}
|
||||
|
||||
public TagList (TagType type)
|
||||
{
|
||||
_type = type;
|
||||
_items = new List<TagValue>();
|
||||
}
|
||||
|
||||
public TagList (TagType type, List<TagValue> items)
|
||||
{
|
||||
_type = type;
|
||||
_items = items;
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
TagList list = new TagList(_type);
|
||||
foreach (TagValue item in _items) {
|
||||
list.Add(item.Copy());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<TagValue> FindAll(Predicate<TagValue> match)
|
||||
{
|
||||
return _items.FindAll(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 (TagValue item)
|
||||
{
|
||||
return _items.IndexOf(item);
|
||||
}
|
||||
|
||||
public void Insert (int index, TagValue item)
|
||||
{
|
||||
_items.Insert(index, item);
|
||||
}
|
||||
|
||||
public void RemoveAt (int index)
|
||||
{
|
||||
_items.RemoveAt(index);
|
||||
}
|
||||
|
||||
public TagValue this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _items[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
_items[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection<NBT_Value> Members
|
||||
|
||||
public void Add (TagValue item)
|
||||
{
|
||||
_items.Add(item);
|
||||
}
|
||||
|
||||
public void Clear ()
|
||||
{
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
public bool Contains (TagValue item)
|
||||
{
|
||||
return _items.Contains(item);
|
||||
}
|
||||
|
||||
public void CopyTo (TagValue[] array, int arrayIndex)
|
||||
{
|
||||
_items.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool Remove (TagValue item)
|
||||
{
|
||||
return _items.Remove(item);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable<NBT_Value> Members
|
||||
|
||||
public IEnumerator<TagValue> GetEnumerator ()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public sealed class TagCompound : TagValue, IDictionary<string, TagValue>
|
||||
{
|
||||
private Dictionary<string, TagValue> _tags;
|
||||
|
||||
public override TagCompound ToTagCompound () { return this; }
|
||||
|
||||
public override TagType GetTagType () { return TagType.TAG_COMPOUND; }
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return _tags.Count; }
|
||||
}
|
||||
|
||||
public TagCompound ()
|
||||
{
|
||||
_tags = new Dictionary<string, TagValue>();
|
||||
}
|
||||
|
||||
public override TagValue Copy ()
|
||||
{
|
||||
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, TagValue value)
|
||||
{
|
||||
_tags.Add(key, value);
|
||||
}
|
||||
|
||||
public bool ContainsKey (string key)
|
||||
{
|
||||
return _tags.ContainsKey(key);
|
||||
}
|
||||
|
||||
public ICollection<string> Keys
|
||||
{
|
||||
get { return _tags.Keys; }
|
||||
}
|
||||
|
||||
public bool Remove (string key)
|
||||
{
|
||||
return _tags.Remove(key);
|
||||
}
|
||||
|
||||
public bool TryGetValue (string key, out TagValue value)
|
||||
{
|
||||
return _tags.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public ICollection<TagValue> Values
|
||||
{
|
||||
get { return _tags.Values; }
|
||||
}
|
||||
|
||||
public TagValue this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _tags[key];
|
||||
}
|
||||
set
|
||||
{
|
||||
_tags[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection<KeyValuePair<string,NBT_Value>> Members
|
||||
|
||||
public void Add (KeyValuePair<string, TagValue> item)
|
||||
{
|
||||
_tags.Add(item.Key, item.Value);
|
||||
}
|
||||
|
||||
public void Clear ()
|
||||
{
|
||||
_tags.Clear();
|
||||
}
|
||||
|
||||
public bool Contains (KeyValuePair<string, TagValue> item)
|
||||
{
|
||||
TagValue value;
|
||||
if (!_tags.TryGetValue(item.Key, out value)) {
|
||||
return false;
|
||||
}
|
||||
return value == item.Value;
|
||||
}
|
||||
|
||||
public void CopyTo (KeyValuePair<string, TagValue>[] array, int arrayIndex)
|
||||
{
|
||||
if (array == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
if (arrayIndex < 0) {
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
if (array.Length - arrayIndex < _tags.Count) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, TagValue> item in _tags) {
|
||||
array[arrayIndex] = item;
|
||||
arrayIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool Remove (KeyValuePair<string, TagValue> item)
|
||||
{
|
||||
if (Contains(item)) {
|
||||
_tags.Remove(item.Key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable<KeyValuePair<string,NBT_Value>> Members
|
||||
|
||||
public IEnumerator<KeyValuePair<string, TagValue>> GetEnumerator ()
|
||||
{
|
||||
return _tags.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return _tags.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@ namespace Substrate.NBT
|
|||
public class TagEventArgs : EventArgs
|
||||
{
|
||||
protected string _tagName;
|
||||
protected TagValue _tag;
|
||||
protected NBTSchemaNode _schema;
|
||||
protected TagNode _tag;
|
||||
protected SchemaNode _schema;
|
||||
|
||||
public string TagName
|
||||
{
|
||||
|
@ -34,14 +34,14 @@ namespace Substrate.NBT
|
|||
_tagName = tagName;
|
||||
}
|
||||
|
||||
public TagEventArgs (string tagName, TagValue tag)
|
||||
public TagEventArgs (string tagName, TagNode tag)
|
||||
: base()
|
||||
{
|
||||
_tag = tag;
|
||||
_tagName = tagName;
|
||||
}
|
||||
|
||||
public TagEventArgs (NBTSchemaNode schema, TagValue tag)
|
||||
public TagEventArgs (SchemaNode schema, TagNode tag)
|
||||
: base()
|
||||
{
|
||||
_tag = tag;
|
||||
|
@ -51,18 +51,18 @@ namespace Substrate.NBT
|
|||
|
||||
public class NBTVerifier : INBTVerifier
|
||||
{
|
||||
private TagValue _root;
|
||||
private NBTSchemaNode _schema;
|
||||
private TagNode _root;
|
||||
private SchemaNode _schema;
|
||||
|
||||
public event MissingTagHandler MissingTag;
|
||||
public event InvalidTagTypeHandler InvalidTagType;
|
||||
public event InvalidTagValueHandler InvalidTagValue;
|
||||
|
||||
private Dictionary<string, TagValue> _scratch = new Dictionary<string,TagValue>();
|
||||
private Dictionary<string, TagNode> _scratch = new Dictionary<string,TagNode>();
|
||||
|
||||
public NBTVerifier () { }
|
||||
|
||||
public NBTVerifier (TagValue root, NBTSchemaNode schema)
|
||||
public NBTVerifier (TagNode root, SchemaNode schema)
|
||||
{
|
||||
_root = root;
|
||||
_schema = schema;
|
||||
|
@ -73,34 +73,34 @@ namespace Substrate.NBT
|
|||
return Verify(_root, _schema);
|
||||
}
|
||||
|
||||
private bool Verify (TagValue tag, NBTSchemaNode schema)
|
||||
private bool Verify (TagNode tag, SchemaNode schema)
|
||||
{
|
||||
if (tag == null) {
|
||||
OnMissingTag(new TagEventArgs(schema.Name));
|
||||
return false;
|
||||
}
|
||||
|
||||
NBTScalerNode scaler = schema as NBTScalerNode;
|
||||
SchemaNodeScaler scaler = schema as SchemaNodeScaler;
|
||||
if (scaler != null) {
|
||||
return VerifyScaler(tag, scaler);
|
||||
}
|
||||
|
||||
NBTStringNode str = schema as NBTStringNode;
|
||||
SchemaNodeString str = schema as SchemaNodeString;
|
||||
if (str != null) {
|
||||
return VerifyString(tag, str);
|
||||
}
|
||||
|
||||
NBTArrayNode array = schema as NBTArrayNode;
|
||||
SchemaNodeArray array = schema as SchemaNodeArray;
|
||||
if (array != null) {
|
||||
return VerifyArray(tag, array);
|
||||
}
|
||||
|
||||
NBTListNode list = schema as NBTListNode;
|
||||
SchemaNodeList list = schema as SchemaNodeList;
|
||||
if (list != null) {
|
||||
return VerifyList(tag, list);
|
||||
}
|
||||
|
||||
NBTCompoundNode compound = schema as NBTCompoundNode;
|
||||
SchemaNodeCompound compound = schema as SchemaNodeCompound;
|
||||
if (compound != null) {
|
||||
return VerifyCompound(tag, compound);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ namespace Substrate.NBT
|
|||
return false;
|
||||
}
|
||||
|
||||
private bool VerifyScaler (TagValue tag, NBTScalerNode schema)
|
||||
private bool VerifyScaler (TagNode tag, SchemaNodeScaler schema)
|
||||
{
|
||||
if (!tag.IsCastableTo(schema.Type)) {
|
||||
OnInvalidTagType(new TagEventArgs(schema.Name, tag));
|
||||
|
@ -118,9 +118,9 @@ namespace Substrate.NBT
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool VerifyString (TagValue tag, NBTStringNode schema)
|
||||
private bool VerifyString (TagNode tag, SchemaNodeString schema)
|
||||
{
|
||||
TagString stag = tag as TagString;
|
||||
TagNodeString stag = tag as TagNodeString;
|
||||
if (stag == null) {
|
||||
OnInvalidTagType(new TagEventArgs(schema, tag));
|
||||
return false;
|
||||
|
@ -138,9 +138,9 @@ namespace Substrate.NBT
|
|||
}
|
||||
|
||||
|
||||
private bool VerifyArray (TagValue tag, NBTArrayNode schema)
|
||||
private bool VerifyArray (TagNode tag, SchemaNodeArray schema)
|
||||
{
|
||||
TagByteArray atag = tag as TagByteArray;
|
||||
TagNodeByteArray atag = tag as TagNodeByteArray;
|
||||
if (atag == null) {
|
||||
OnInvalidTagType(new TagEventArgs(schema, tag));
|
||||
return false;
|
||||
|
@ -153,9 +153,9 @@ namespace Substrate.NBT
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool VerifyList (TagValue tag, NBTListNode schema)
|
||||
private bool VerifyList (TagNode tag, SchemaNodeList schema)
|
||||
{
|
||||
TagList ltag = tag as TagList;
|
||||
TagNodeList ltag = tag as TagNodeList;
|
||||
if (ltag == null) {
|
||||
OnInvalidTagType(new TagEventArgs(schema, tag));
|
||||
return false;
|
||||
|
@ -179,7 +179,7 @@ namespace Substrate.NBT
|
|||
// If a subschema is set, test all items in list against it
|
||||
|
||||
if (schema.SubSchema != null) {
|
||||
foreach (TagValue v in ltag) {
|
||||
foreach (TagNode v in ltag) {
|
||||
pass = Verify(v, schema.SubSchema) && pass;
|
||||
}
|
||||
}
|
||||
|
@ -187,9 +187,9 @@ namespace Substrate.NBT
|
|||
return pass;
|
||||
}
|
||||
|
||||
private bool VerifyCompound (TagValue tag, NBTCompoundNode schema)
|
||||
private bool VerifyCompound (TagNode tag, SchemaNodeCompound schema)
|
||||
{
|
||||
TagCompound ctag = tag as TagCompound;
|
||||
TagNodeCompound ctag = tag as TagNodeCompound;
|
||||
if (ctag == null) {
|
||||
OnInvalidTagType(new TagEventArgs(schema, tag));
|
||||
return false;
|
||||
|
@ -197,16 +197,16 @@ namespace Substrate.NBT
|
|||
|
||||
bool pass = true;
|
||||
|
||||
foreach (NBTSchemaNode node in schema) {
|
||||
TagValue value;
|
||||
foreach (SchemaNode node in schema) {
|
||||
TagNode value;
|
||||
ctag.TryGetValue(node.Name, out value);
|
||||
|
||||
if (value == null) {
|
||||
if ((node.Options & NBTOptions.CREATE_ON_MISSING) == NBTOptions.CREATE_ON_MISSING) {
|
||||
if ((node.Options & SchemaOptions.CREATE_ON_MISSING) == SchemaOptions.CREATE_ON_MISSING) {
|
||||
_scratch[node.Name] = node.BuildDefaultTree();
|
||||
continue;
|
||||
}
|
||||
else if ((node.Options & NBTOptions.OPTIONAL) == NBTOptions.OPTIONAL) {
|
||||
else if ((node.Options & SchemaOptions.OPTIONAL) == SchemaOptions.OPTIONAL) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ namespace Substrate.NBT
|
|||
pass = Verify(value, node) && pass;
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, TagValue> item in _scratch) {
|
||||
foreach (KeyValuePair<string, TagNode> item in _scratch) {
|
||||
ctag[item.Key] = item.Value;
|
||||
}
|
||||
|
||||
|
|
141
Substrate/SubstrateCS/Source/NBT/TagNode.cs
Normal file
141
Substrate/SubstrateCS/Source/NBT/TagNode.cs
Normal file
|
@ -0,0 +1,141 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Substrate.NBT {
|
||||
|
||||
using Substrate.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// An abstract base class representing a node in an NBT tree.
|
||||
/// </summary>
|
||||
public abstract class TagNode : ICopyable<TagNode>
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert this node to a null tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new null node.</returns>
|
||||
public virtual TagNodeNull ToTagNull ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a byte tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new byte node.</returns>
|
||||
public virtual TagNodeByte ToTagByte ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a short tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new short node.</returns>
|
||||
public virtual TagNodeShort ToTagShort ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to an int tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new int node.</returns>
|
||||
public virtual TagNodeInt ToTagInt ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a long tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new long node.</returns>
|
||||
public virtual TagNodeLong ToTagLong ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a float tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new float node.</returns>
|
||||
public virtual TagNodeFloat ToTagFloat ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a double tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new double node.</returns>
|
||||
public virtual TagNodeDouble ToTagDouble ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a byte array tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new byte array node.</returns>
|
||||
public virtual TagNodeByteArray ToTagByteArray ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a string tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new string node.</returns>
|
||||
public virtual TagNodeString ToTagString ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a list tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new list node.</returns>
|
||||
public virtual TagNodeList ToTagList ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert this node to a compound tag type if supported.
|
||||
/// </summary>
|
||||
/// <returns>A new compound node.</returns>
|
||||
public virtual TagNodeCompound ToTagCompound ()
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>An NBT tag type.</returns>
|
||||
public virtual TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_END;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this node is castable to another node of a given tag type.
|
||||
/// </summary>
|
||||
/// <param name="type">An NBT tag type.</param>
|
||||
/// <returns>Status indicating whether this object could be cast to a node type represented by the given tag type.</returns>
|
||||
public virtual bool IsCastableTo (TagType type)
|
||||
{
|
||||
return type == GetTagType();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the NBT node.
|
||||
/// </summary>
|
||||
/// <returns>A new NBT node.</returns>
|
||||
public virtual TagNode Copy ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
161
Substrate/SubstrateCS/Source/NBT/TagNodeByte.cs
Normal file
161
Substrate/SubstrateCS/Source/NBT/TagNodeByte.cs
Normal file
|
@ -0,0 +1,161 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a signed byte tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeByte : TagNode
|
||||
{
|
||||
private byte _data = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeByte ToTagByte ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to a new short node.
|
||||
/// </summary>
|
||||
/// <returns>A short node representing the same data.</returns>
|
||||
public override TagNodeShort ToTagShort ()
|
||||
{
|
||||
return new TagNodeShort(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to a new int node.
|
||||
/// </summary>
|
||||
/// <returns>An int node representing the same data.</returns>
|
||||
public override TagNodeInt ToTagInt ()
|
||||
{
|
||||
return new TagNodeInt(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to a new long node.
|
||||
/// </summary>
|
||||
/// <returns>A long node representing the same data.</returns>
|
||||
public override TagNodeLong ToTagLong ()
|
||||
{
|
||||
return new TagNodeLong(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_BYTE tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_BYTE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the node is castable to another node of a given tag type.
|
||||
/// </summary>
|
||||
/// <param name="type">An NBT tag type.</param>
|
||||
/// <returns>Status indicating whether this object could be cast to a node type represented by the given tag type.</returns>
|
||||
public override bool IsCastableTo (TagType type)
|
||||
{
|
||||
return (type == TagType.TAG_BYTE ||
|
||||
type == TagType.TAG_SHORT ||
|
||||
type == TagType.TAG_INT ||
|
||||
type == TagType.TAG_LONG);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a byte of tag data.
|
||||
/// </summary>
|
||||
public byte Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new byte node with a data value of 0.
|
||||
/// </summary>
|
||||
public TagNodeByte () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new byte node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeByte (byte d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new byte node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeByte(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system byte to a byte node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte value.</param>
|
||||
/// <returns>A new byte node containing the given value.</returns>
|
||||
public static implicit operator TagNodeByte (byte b)
|
||||
{
|
||||
return new TagNodeByte(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a byte node to a system byte representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte node.</param>
|
||||
/// <returns>A system byte set to the node's data value.</returns>
|
||||
public static implicit operator byte (TagNodeByte b)
|
||||
{
|
||||
return b._data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a byte node to a system short representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte node.</param>
|
||||
/// <returns>A system short set to the node's data value.</returns>
|
||||
public static implicit operator short (TagNodeByte b)
|
||||
{
|
||||
return b._data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a byte node to a system int representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte node.</param>
|
||||
/// <returns>A system int set to the node's data value.</returns>
|
||||
public static implicit operator int (TagNodeByte b)
|
||||
{
|
||||
return b._data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a byte node to a system long representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte node.</param>
|
||||
/// <returns>A system long set to the node's data value.</returns>
|
||||
public static implicit operator long (TagNodeByte b)
|
||||
{
|
||||
return b._data;
|
||||
}
|
||||
}
|
||||
}
|
113
Substrate/SubstrateCS/Source/NBT/TagNodeByteArray.cs
Normal file
113
Substrate/SubstrateCS/Source/NBT/TagNodeByteArray.cs
Normal file
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing an unsigned byte array tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeByteArray : TagNode
|
||||
{
|
||||
private byte[] _data = null;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeByteArray ToTagByteArray ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_BYTE_ARRAY tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_BYTE_ARRAY;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a byte array of tag data.
|
||||
/// </summary>
|
||||
public byte[] Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the stored byte array.
|
||||
/// </summary>
|
||||
public int Length
|
||||
{
|
||||
get { return _data.Length; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new byte array node with a null data value.
|
||||
/// </summary>
|
||||
public TagNodeByteArray () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new byte array node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeByteArray (byte[] d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new byte array node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
byte[] arr = new byte[_data.Length];
|
||||
_data.CopyTo(arr, 0);
|
||||
|
||||
return new TagNodeByteArray(arr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a single byte at the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">Valid index within stored byte array.</param>
|
||||
/// <returns>The byte value at the given index of the stored byte array.</returns>
|
||||
public byte this[int index]
|
||||
{
|
||||
get { return _data[index]; }
|
||||
set { _data[index] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system byte array to a byte array node representing the same data.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte array.</param>
|
||||
/// <returns>A new byte array node containing the given value.</returns>
|
||||
public static implicit operator TagNodeByteArray (byte[] b)
|
||||
{
|
||||
return new TagNodeByteArray(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a byte array node to a system byte array representing the same data.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte array node.</param>
|
||||
/// <returns>A system byte array set to the node's data.</returns>
|
||||
public static implicit operator byte[] (TagNodeByteArray b)
|
||||
{
|
||||
return b._data;
|
||||
}
|
||||
}
|
||||
}
|
265
Substrate/SubstrateCS/Source/NBT/TagNodeCompound.cs
Normal file
265
Substrate/SubstrateCS/Source/NBT/TagNodeCompound.cs
Normal file
|
@ -0,0 +1,265 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a compound tag type containing other nodes.
|
||||
/// </summary>
|
||||
public sealed class TagNodeCompound : TagNode, IDictionary<string, TagNode>
|
||||
{
|
||||
private Dictionary<string, TagNode> _tags;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeCompound ToTagCompound ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_STRING tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_COMPOUND;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of subnodes contained in node.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return _tags.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new empty compound node.
|
||||
/// </summary>
|
||||
public TagNodeCompound ()
|
||||
{
|
||||
_tags = new Dictionary<string, TagNode>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new compound node containing new subnodes representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
TagNodeCompound list = new TagNodeCompound();
|
||||
foreach (KeyValuePair<string, TagNode> item in _tags) {
|
||||
list[item.Key] = item.Value.Copy();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _tags.ToString();
|
||||
}
|
||||
|
||||
#region IDictionary<string,NBT_Value> Members
|
||||
|
||||
/// <summary>
|
||||
/// Adds a named subnode to the set.
|
||||
/// </summary>
|
||||
/// <param name="key">The name of the subnode.</param>
|
||||
/// <param name="value">The subnode to add.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">A subnode with the same key already exists in the set.</exception>
|
||||
public void Add (string key, TagNode value)
|
||||
{
|
||||
_tags.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a subnode exists in the set with the specified name.
|
||||
/// </summary>
|
||||
/// <param name="key">The name of a subnode to check.</param>
|
||||
/// <returns>Status indicating whether a subnode with the specified name exists.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
|
||||
public bool ContainsKey (string key)
|
||||
{
|
||||
return _tags.ContainsKey(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection containing all the names of subnodes in this set.
|
||||
/// </summary>
|
||||
public ICollection<string> Keys
|
||||
{
|
||||
get { return _tags.Keys; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a subnode with the specified name.
|
||||
/// </summary>
|
||||
/// <param name="key">The name of the subnode to remove.</param>
|
||||
/// <returns>Status indicating whether a subnode was removed.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
|
||||
public bool Remove (string key)
|
||||
{
|
||||
return _tags.Remove(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the subnode associated with the given name.
|
||||
/// </summary>
|
||||
/// <param name="key">The name of the subnode to get.</param>
|
||||
/// <param name="value">When the function returns, contains the subnode assicated with the specified key. If no subnode was found, contains a default value.</param>
|
||||
/// <returns>Status indicating whether a subnode was found.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
|
||||
public bool TryGetValue (string key, out TagNode value)
|
||||
{
|
||||
return _tags.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection containing all the subnodes in this set.
|
||||
/// </summary>
|
||||
public ICollection<TagNode> Values
|
||||
{
|
||||
get { return _tags.Values; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the subnode with the associated name.
|
||||
/// </summary>
|
||||
/// <param name="key">The name of the subnode to get or set.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
|
||||
/// <exception cref="KeyNotFoundException">The property is retrieved and key does not exist in the collection.</exception>
|
||||
public TagNode this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _tags[key];
|
||||
}
|
||||
set
|
||||
{
|
||||
_tags[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection<KeyValuePair<string,NBT_Value>> Members
|
||||
|
||||
/// <summary>
|
||||
/// Adds a subnode to the to the set with the specified name.
|
||||
/// </summary>
|
||||
/// <param name="item">The <see cref="KeyValuePair{TKey, TVal}"/> structure representing the key and subnode to add to the set.</param>
|
||||
/// <exception cref="ArgumentNullException">The key of <paramref name="item"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">A subnode with the same key already exists in the set.</exception>
|
||||
public void Add (KeyValuePair<string, TagNode> item)
|
||||
{
|
||||
_tags.Add(item.Key, item.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all of the subnodes from this node.
|
||||
/// </summary>
|
||||
public void Clear ()
|
||||
{
|
||||
_tags.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a specific subnode with a specific name is contained in the set.
|
||||
/// </summary>
|
||||
/// <param name="item">The <see cref="KeyValuePair{TKey, TValue}"/> structure representing the key and subnode to look for.</param>
|
||||
/// <returns>Status indicating if the subnode and key combination exists in the set.</returns>
|
||||
public bool Contains (KeyValuePair<string, TagNode> item)
|
||||
{
|
||||
TagNode value;
|
||||
if (!_tags.TryGetValue(item.Key, out value)) {
|
||||
return false;
|
||||
}
|
||||
return value == item.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the elements of the <see cref="ICollection{T}"/> to an array of type <see cref="KeyValuePair{TKey, TVal}"/>, starting at the specified array index.
|
||||
/// </summary>
|
||||
/// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the subnodes copied. The Array must have zero-based indexing.</param>
|
||||
/// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="array"/> is null.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than 0.</exception>
|
||||
/// <exception cref="ArgumentException">The number of elements in the source <see cref="ICollection{T}"/> is greater than the available space from <paramref name="arrayIndex"/> to the end of the destination <paramref name="array"/>.</exception>
|
||||
public void CopyTo (KeyValuePair<string, TagNode>[] array, int arrayIndex)
|
||||
{
|
||||
if (array == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
if (arrayIndex < 0) {
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
if (array.Length - arrayIndex < _tags.Count) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, TagNode> item in _tags) {
|
||||
array[arrayIndex] = item;
|
||||
arrayIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the node is readonly.
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified key and subnode combination from the set.
|
||||
/// </summary>
|
||||
/// <param name="item">The <see cref="KeyValuePair{TKey, TVal}"/> structure representing the key and value to remove from the set.</param>
|
||||
/// <returns>Status indicating whether a subnode was removed.</returns>
|
||||
public bool Remove (KeyValuePair<string, TagNode> item)
|
||||
{
|
||||
if (Contains(item)) {
|
||||
_tags.Remove(item.Key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable<KeyValuePair<string,NBT_Value>> Members
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through all of the subnodes in the set.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for this node.</returns>
|
||||
public IEnumerator<KeyValuePair<string, TagNode>> GetEnumerator ()
|
||||
{
|
||||
return _tags.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through all of the subnodes in the set.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for this node.</returns>
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return _tags.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
101
Substrate/SubstrateCS/Source/NBT/TagNodeDouble.cs
Normal file
101
Substrate/SubstrateCS/Source/NBT/TagNodeDouble.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a double-precision floating point tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeDouble : TagNode
|
||||
{
|
||||
private double _data = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeDouble ToTagDouble ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_DOUBLE tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_DOUBLE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a double of tag data.
|
||||
/// </summary>
|
||||
public double Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new double node with a data value of 0.0.
|
||||
/// </summary>
|
||||
public TagNodeDouble () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new double node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeDouble (double d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new double node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeDouble(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system float to a double node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="f">A float value.</param>
|
||||
/// <returns>A new double node containing the given value.</returns>
|
||||
public static implicit operator TagNodeDouble (float f)
|
||||
{
|
||||
return new TagNodeDouble(f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system double to a double node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="f">A double value.</param>
|
||||
/// <returns>A new double node containing the given value.</returns>
|
||||
public static implicit operator TagNodeDouble (double d)
|
||||
{
|
||||
return new TagNodeDouble(d);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a double node to a system double representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="d">A double node.</param>
|
||||
/// <returns>A system double set to the node's data value.</returns>
|
||||
public static implicit operator double (TagNodeDouble d)
|
||||
{
|
||||
return d._data;
|
||||
}
|
||||
}
|
||||
}
|
121
Substrate/SubstrateCS/Source/NBT/TagNodeFloat.cs
Normal file
121
Substrate/SubstrateCS/Source/NBT/TagNodeFloat.cs
Normal file
|
@ -0,0 +1,121 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a single-precision floating point tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeFloat : TagNode
|
||||
{
|
||||
private float _data = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeFloat ToTagFloat ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to a new double node.
|
||||
/// </summary>
|
||||
/// <returns>A double node representing the same data.</returns>
|
||||
public override TagNodeDouble ToTagDouble ()
|
||||
{
|
||||
return new TagNodeDouble(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_FLOAT tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_FLOAT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the node is castable to another node of a given tag type.
|
||||
/// </summary>
|
||||
/// <param name="type">An NBT tag type.</param>
|
||||
/// <returns>Status indicating whether this object could be cast to a node type represented by the given tag type.</returns>
|
||||
public override bool IsCastableTo (TagType type)
|
||||
{
|
||||
return (type == TagType.TAG_FLOAT ||
|
||||
type == TagType.TAG_DOUBLE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a float of tag data.
|
||||
/// </summary>
|
||||
public float Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new float node with a data value of 0.0.
|
||||
/// </summary>
|
||||
public TagNodeFloat () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new float node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeFloat (float d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new float node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeFloat(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system float to a float node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="f">A float value.</param>
|
||||
/// <returns>A new float node containing the given value.</returns>
|
||||
public static implicit operator TagNodeFloat (float f)
|
||||
{
|
||||
return new TagNodeFloat(f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a float node to a system float representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="f">A float node.</param>
|
||||
/// <returns>A system float set to the node's data value.</returns>
|
||||
public static implicit operator float (TagNodeFloat f)
|
||||
{
|
||||
return f._data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a float node to a system double representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="f">A float node.</param>
|
||||
/// <returns>A system double set to the node's data value.</returns>
|
||||
public static implicit operator double (TagNodeFloat f)
|
||||
{
|
||||
return f._data;
|
||||
}
|
||||
}
|
||||
}
|
141
Substrate/SubstrateCS/Source/NBT/TagNodeInt.cs
Normal file
141
Substrate/SubstrateCS/Source/NBT/TagNodeInt.cs
Normal file
|
@ -0,0 +1,141 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a signed int tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeInt : TagNode
|
||||
{
|
||||
private int _data = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeInt ToTagInt ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to a new long node.
|
||||
/// </summary>
|
||||
/// <returns>A long node representing the same data.</returns>
|
||||
public override TagNodeLong ToTagLong ()
|
||||
{
|
||||
return new TagNodeLong(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_INT tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_INT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the node is castable to another node of a given tag type.
|
||||
/// </summary>
|
||||
/// <param name="type">An NBT tag type.</param>
|
||||
/// <returns>Status indicating whether this object could be cast to a node type represented by the given tag type.</returns>
|
||||
public override bool IsCastableTo (TagType type)
|
||||
{
|
||||
return (type == TagType.TAG_INT ||
|
||||
type == TagType.TAG_LONG);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an int of tag data.
|
||||
/// </summary>
|
||||
public int Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new int node with a data value of 0.
|
||||
/// </summary>
|
||||
public TagNodeInt () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new int node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeInt (int d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new int node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeInt(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system byte to an int node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte value.</param>
|
||||
/// <returns>A new int node containing the given value.</returns>
|
||||
public static implicit operator TagNodeInt (byte b)
|
||||
{
|
||||
return new TagNodeInt(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system short to an int node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="s">A short value.</param>
|
||||
/// <returns>A new int node containing the given value.</returns>
|
||||
public static implicit operator TagNodeInt (short s)
|
||||
{
|
||||
return new TagNodeInt(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system int to an int node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="i">An int value.</param>
|
||||
/// <returns>A new int node containing the given value.</returns>
|
||||
public static implicit operator TagNodeInt (int i)
|
||||
{
|
||||
return new TagNodeInt(i);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an int node to a system int representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="i">An int node.</param>
|
||||
/// <returns>A system int set to the node's data value.</returns>
|
||||
public static implicit operator int (TagNodeInt i)
|
||||
{
|
||||
return i._data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an int node to a system long representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="i">An int node.</param>
|
||||
/// <returns>A system long set to the node's data value.</returns>
|
||||
public static implicit operator long (TagNodeInt i)
|
||||
{
|
||||
return i._data;
|
||||
}
|
||||
}
|
||||
}
|
264
Substrate/SubstrateCS/Source/NBT/TagNodeList.cs
Normal file
264
Substrate/SubstrateCS/Source/NBT/TagNodeList.cs
Normal file
|
@ -0,0 +1,264 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a list tag type containing other nodes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A list node contains 0 or more nodes of the same type. The nodes are unnamed
|
||||
/// but can be accessed by sequential index.
|
||||
/// </remarks>
|
||||
public sealed class TagNodeList : TagNode, IList<TagNode>
|
||||
{
|
||||
private TagType _type = TagType.TAG_END;
|
||||
|
||||
private List<TagNode> _items = null;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeList ToTagList ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_STRING tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_LIST;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of subnodes contained in the list.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return _items.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the subnodes contained in the list.
|
||||
/// </summary>
|
||||
public TagType ValueType
|
||||
{
|
||||
get { return _type; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new empty list node.
|
||||
/// </summary>
|
||||
/// <param name="type">The tag type of the list's subnodes.</param>
|
||||
public TagNodeList (TagType type)
|
||||
{
|
||||
_type = type;
|
||||
_items = new List<TagNode>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new list node from a list of nodes.
|
||||
/// </summary>
|
||||
/// <param name="type">The tag type of the list's subnodes.</param>
|
||||
/// <param name="items">A list containing node objects matching the type parameter.</param>
|
||||
public TagNodeList (TagType type, List<TagNode> items)
|
||||
{
|
||||
_type = type;
|
||||
_items = items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new list node containing new subnodes representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
TagNodeList list = new TagNodeList(_type);
|
||||
foreach (TagNode item in _items) {
|
||||
list.Add(item.Copy());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all the subnodes that match the conditions defined by the specified predicate.
|
||||
/// </summary>
|
||||
/// <param name="match">The <see cref="Predicate{TagNode}"/> delegate that defines the conditions of the subnode to search for.</param>
|
||||
/// <returns>A list of all subnodes matching the predicate.</returns>
|
||||
public List<TagNode> FindAll (Predicate<TagNode> match)
|
||||
{
|
||||
return _items.FindAll(match);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all subnodes that match the conditions defined by the specified predicate.
|
||||
/// </summary>
|
||||
/// <param name="match">The <see cref="Predicate{TagNode}"/> delegate that defines the conditions of the subnode to search for.</param>
|
||||
/// <returns>The number of subnodes removed from the node.</returns>
|
||||
public int RemoveAll (Predicate<TagNode> match)
|
||||
{
|
||||
return _items.RemoveAll(match);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _items.ToString();
|
||||
}
|
||||
|
||||
#region IList<NBT_Value> Members
|
||||
|
||||
/// <summary>
|
||||
/// Searches for the specified subnode and returns the zero-based index of the first occurrence within the entire node's list.
|
||||
/// </summary>
|
||||
/// <param name="item">The subnode to locate.</param>
|
||||
/// <returns>The zero-based index of the subnode within the node's list if found, or -1 otherwise.</returns>
|
||||
public int IndexOf (TagNode item)
|
||||
{
|
||||
return _items.IndexOf(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a subnode into the node's list at the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index at which the subnode should be inserted.</param>
|
||||
/// <param name="item">The subnode to insert.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when a subnode being inserted has the wrong tag type.</exception>
|
||||
public void Insert (int index, TagNode item)
|
||||
{
|
||||
if (item.GetTagType() != _type) {
|
||||
throw new ArgumentException("The tag type of item is invalid for this node");
|
||||
}
|
||||
_items.Insert(index, item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the subnode from the node's list at the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index to remove a subnode at.</param>
|
||||
public void RemoveAt (int index)
|
||||
{
|
||||
_items.RemoveAt(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the subnode in the node's list at the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index to get or set from.</param>
|
||||
/// <returns>The subnode at the specified index.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when a subnode being assigned has the wrong tag type.</exception>
|
||||
public TagNode this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _items[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.GetTagType() != _type) {
|
||||
throw new ArgumentException("The tag type of the assigned subnode is invalid for this node");
|
||||
}
|
||||
_items[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection<NBT_Value> Members
|
||||
|
||||
/// <summary>
|
||||
/// Adds a subnode to the end of the node's list.
|
||||
/// </summary>
|
||||
/// <param name="item">The subnode to add.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when a subnode being added has the wrong tag type.</exception>
|
||||
public void Add (TagNode item)
|
||||
{
|
||||
if (item.GetTagType() != _type) {
|
||||
throw new ArgumentException("The tag type of item is invalid for this node");
|
||||
}
|
||||
|
||||
_items.Add(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all subnode's from the node's list.
|
||||
/// </summary>
|
||||
public void Clear ()
|
||||
{
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a subnode is contained within the node's list.
|
||||
/// </summary>
|
||||
/// <param name="item">The subnode to check for existance.</param>
|
||||
/// <returns>Status indicating if the subnode exists in the node's list.</returns>
|
||||
public bool Contains (TagNode item)
|
||||
{
|
||||
return _items.Contains(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the entire node's list to a compatible one-dimensional array, starting at the specified index of the target array.
|
||||
/// </summary>
|
||||
/// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the subnodes copied. The Array must have zero-based indexing.</param>
|
||||
/// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
|
||||
public void CopyTo (TagNode[] array, int arrayIndex)
|
||||
{
|
||||
_items.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the node is readonly.
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the first occurance of a subnode from the node's list.
|
||||
/// </summary>
|
||||
/// <param name="item">The subnode to remove.</param>
|
||||
/// <returns>Status indicating whether a subnode was removed.</returns>
|
||||
public bool Remove (TagNode item)
|
||||
{
|
||||
return _items.Remove(item);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable<NBT_Value> Members
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through all of the subnodes in the node's list.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for this node.</returns>
|
||||
public IEnumerator<TagNode> GetEnumerator ()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through all of the subnodes in the node's list.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for this node.</returns>
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
121
Substrate/SubstrateCS/Source/NBT/TagNodeLong.cs
Normal file
121
Substrate/SubstrateCS/Source/NBT/TagNodeLong.cs
Normal file
|
@ -0,0 +1,121 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a signed long tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeLong : TagNode
|
||||
{
|
||||
private long _data = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeLong ToTagLong ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_LONG tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_LONG;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a long of tag data.
|
||||
/// </summary>
|
||||
public long Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new long node with a data value of 0.
|
||||
/// </summary>
|
||||
public TagNodeLong () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new long node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeLong (long d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new long node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeLong(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system byte to a long node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte value.</param>
|
||||
/// <returns>A new long node containing the given value.</returns>
|
||||
public static implicit operator TagNodeLong (byte b)
|
||||
{
|
||||
return new TagNodeLong(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system shprt to a long node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="s">A short value.</param>
|
||||
/// <returns>A new long node containing the given value.</returns>
|
||||
public static implicit operator TagNodeLong (short s)
|
||||
{
|
||||
return new TagNodeLong(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system int to a long node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="i">An int value.</param>
|
||||
/// <returns>A new long node containing the given value.</returns>
|
||||
public static implicit operator TagNodeLong (int i)
|
||||
{
|
||||
return new TagNodeLong(i);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system long to a long node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="l">A long value.</param>
|
||||
/// <returns>A new long node containing the given value.</returns>
|
||||
public static implicit operator TagNodeLong (long l)
|
||||
{
|
||||
return new TagNodeLong(l);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a long node to a system long representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="l">A long node.</param>
|
||||
/// <returns>A system long set to the node's data value.</returns>
|
||||
public static implicit operator long (TagNodeLong l)
|
||||
{
|
||||
return l._data;
|
||||
}
|
||||
}
|
||||
}
|
37
Substrate/SubstrateCS/Source/NBT/TagNodeNull.cs
Normal file
37
Substrate/SubstrateCS/Source/NBT/TagNodeNull.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a null tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeNull : TagNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeNull ToTagNull ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_END tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_END;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new null node.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeNull();
|
||||
}
|
||||
}
|
||||
}
|
151
Substrate/SubstrateCS/Source/NBT/TagNodeShort.cs
Normal file
151
Substrate/SubstrateCS/Source/NBT/TagNodeShort.cs
Normal file
|
@ -0,0 +1,151 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a signed short tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeShort : TagNode
|
||||
{
|
||||
private short _data = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeShort ToTagShort ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to a new int node.
|
||||
/// </summary>
|
||||
/// <returns>An int node representing the same data.</returns>
|
||||
public override TagNodeInt ToTagInt ()
|
||||
{
|
||||
return new TagNodeInt(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to a new long node.
|
||||
/// </summary>
|
||||
/// <returns>A long node representing the same data.</returns>
|
||||
public override TagNodeLong ToTagLong ()
|
||||
{
|
||||
return new TagNodeLong(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_SHORT tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_SHORT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the node is castable to another node of a given tag type.
|
||||
/// </summary>
|
||||
/// <param name="type">An NBT tag type.</param>
|
||||
/// <returns>Status indicating whether this object could be cast to a node type represented by the given tag type.</returns>
|
||||
public override bool IsCastableTo (TagType type)
|
||||
{
|
||||
return (type == TagType.TAG_SHORT ||
|
||||
type == TagType.TAG_INT ||
|
||||
type == TagType.TAG_LONG);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a short of tag data.
|
||||
/// </summary>
|
||||
public short Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new short node with a data value of 0.
|
||||
/// </summary>
|
||||
public TagNodeShort () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new short node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeShort (short d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new short node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeShort(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system byte to a short node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="b">A byte value.</param>
|
||||
/// <returns>A new short node containing the given value.</returns>
|
||||
public static implicit operator TagNodeShort (byte b)
|
||||
{
|
||||
return new TagNodeShort(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system short to a short node representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="s">A short value.</param>
|
||||
/// <returns>A new short node containing the given value.</returns>
|
||||
public static implicit operator TagNodeShort (short s)
|
||||
{
|
||||
return new TagNodeShort(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a short node to a system short representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="s">A short node.</param>
|
||||
/// <returns>A system short set to the node's data value.</returns>
|
||||
public static implicit operator short (TagNodeShort s)
|
||||
{
|
||||
return s._data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a short node to a system int representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="s">A short node.</param>
|
||||
/// <returns>A system int set to the node's data value.</returns>
|
||||
public static implicit operator int (TagNodeShort s)
|
||||
{
|
||||
return s._data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a short node to a system long representing the same value.
|
||||
/// </summary>
|
||||
/// <param name="s">A short node.</param>
|
||||
/// <returns>A system long set to the node's data value.</returns>
|
||||
public static implicit operator long (TagNodeShort s)
|
||||
{
|
||||
return s._data;
|
||||
}
|
||||
}
|
||||
}
|
99
Substrate/SubstrateCS/Source/NBT/TagNodeString.cs
Normal file
99
Substrate/SubstrateCS/Source/NBT/TagNodeString.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// An NBT node representing a string tag type.
|
||||
/// </summary>
|
||||
public sealed class TagNodeString : TagNode
|
||||
{
|
||||
private string _data = "";
|
||||
|
||||
/// <summary>
|
||||
/// Converts the node to itself.
|
||||
/// </summary>
|
||||
/// <returns>A reference to itself.</returns>
|
||||
public override TagNodeString ToTagString ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag type of the node.
|
||||
/// </summary>
|
||||
/// <returns>The TAG_STRING tag type.</returns>
|
||||
public override TagType GetTagType ()
|
||||
{
|
||||
return TagType.TAG_STRING;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a string of tag data.
|
||||
/// </summary>
|
||||
public string Data
|
||||
{
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the stored string.
|
||||
/// </summary>
|
||||
public int Length
|
||||
{
|
||||
get { return _data.Length; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new byte array node with an empty string.
|
||||
/// </summary>
|
||||
public TagNodeString () { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new string node.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to set the node's tag data value.</param>
|
||||
public TagNodeString (string d)
|
||||
{
|
||||
_data = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a deep copy of the node.
|
||||
/// </summary>
|
||||
/// <returns>A new string node representing the same data.</returns>
|
||||
public override TagNode Copy ()
|
||||
{
|
||||
return new TagNodeString(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation of the node's data.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the node's data.</returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
return _data.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a system string to a string node representing the same data.
|
||||
/// </summary>
|
||||
/// <param name="s">A string.</param>
|
||||
/// <returns>A new string node containing the given value.</returns>
|
||||
public static implicit operator TagNodeString (string s)
|
||||
{
|
||||
return new TagNodeString(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string node to a system string representing the same data.
|
||||
/// </summary>
|
||||
/// <param name="b">A string node.</param>
|
||||
/// <returns>A system string set to the node's data.</returns>
|
||||
public static implicit operator string (TagNodeString s)
|
||||
{
|
||||
return s._data;
|
||||
}
|
||||
}
|
||||
}
|
65
Substrate/SubstrateCS/Source/NBT/TagType.cs
Normal file
65
Substrate/SubstrateCS/Source/NBT/TagType.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
|
||||
namespace Substrate.NBT
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the type of an NBT tag.
|
||||
/// </summary>
|
||||
public enum TagType
|
||||
{
|
||||
/// <summary>
|
||||
/// A null tag, used to terminate lists.
|
||||
/// </summary>
|
||||
TAG_END = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing an 8-bit signed integer.
|
||||
/// </summary>
|
||||
TAG_BYTE = 1,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a 16-bit signed integer.
|
||||
/// </summary>
|
||||
TAG_SHORT = 2,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a 32-bit signed integer.
|
||||
/// </summary>
|
||||
TAG_INT = 3,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a 64-bit signed integer.
|
||||
/// </summary>
|
||||
TAG_LONG = 4,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a 32-bit (single precision) floating-point value.
|
||||
/// </summary>
|
||||
TAG_FLOAT = 5,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a 64-bit (double precision) floating-point value.
|
||||
/// </summary>
|
||||
TAG_DOUBLE = 6,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing an array of unsigned 8-bit byte values.
|
||||
/// </summary>
|
||||
TAG_BYTE_ARRAY = 7,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a string of text.
|
||||
/// </summary>
|
||||
TAG_STRING = 8,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a sequential list of tags, where all tags of of the same type.
|
||||
/// </summary>
|
||||
TAG_LIST = 9,
|
||||
|
||||
/// <summary>
|
||||
/// A tag containing a key-value store of tags, where each tag can be of any type.
|
||||
/// </summary>
|
||||
TAG_COMPOUND = 10
|
||||
}
|
||||
}
|
|
@ -9,20 +9,20 @@ namespace Substrate
|
|||
|
||||
public class Player : UntypedEntity, INBTObject<Player>, ICopyable<Player>, IItemContainer
|
||||
{
|
||||
public static readonly NBTCompoundNode PlayerSchema = UTBaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound PlayerSchema = UTBaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTScalerNode("AttackTime", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("DeathTime", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("Health", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("HurtTime", TagType.TAG_SHORT),
|
||||
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),
|
||||
new SchemaNodeScaler("AttackTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("DeathTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Health", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("HurtTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("Dimension", TagType.TAG_INT),
|
||||
new SchemaNodeList("Inventory", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
new SchemaNodeScaler("World", TagType.TAG_STRING, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("Sleeping", TagType.TAG_BYTE, SchemaOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeScaler("SleepTimer", TagType.TAG_SHORT, SchemaOptions.CREATE_ON_MISSING),
|
||||
new SchemaNodeScaler("SpawnX", TagType.TAG_INT, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("SpawnY", TagType.TAG_INT, SchemaOptions.OPTIONAL),
|
||||
new SchemaNodeScaler("SpawnZ", TagType.TAG_INT, SchemaOptions.OPTIONAL),
|
||||
});
|
||||
|
||||
private const int _CAPACITY = 105;
|
||||
|
@ -145,9 +145,9 @@ namespace Substrate
|
|||
|
||||
#region INBTObject<Player> Members
|
||||
|
||||
public virtual new Player LoadTree (TagValue tree)
|
||||
public virtual new Player LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ namespace Substrate
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual new Player LoadTreeSafe (TagValue tree)
|
||||
public virtual new Player LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -189,26 +189,26 @@ namespace Substrate
|
|||
return LoadTree(tree);
|
||||
}
|
||||
|
||||
public virtual new TagValue BuildTree ()
|
||||
public virtual new TagNode BuildTree ()
|
||||
{
|
||||
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);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["AttackTime"] = new TagNodeShort(_attackTime);
|
||||
tree["DeathTime"] = new TagNodeShort(_deathTime);
|
||||
tree["Health"] = new TagNodeShort(_health);
|
||||
tree["HurtTime"] = new TagNodeShort(_hurtTime);
|
||||
|
||||
tree["Dimension"] = new TagInt(_dimension);
|
||||
tree["Sleeping"] = new TagByte(_sleeping);
|
||||
tree["SleepTimer"] = new TagShort(_sleepTimer);
|
||||
tree["Dimension"] = new TagNodeInt(_dimension);
|
||||
tree["Sleeping"] = new TagNodeByte(_sleeping);
|
||||
tree["SleepTimer"] = new TagNodeShort(_sleepTimer);
|
||||
|
||||
if (_spawnX != null && _spawnY != null && _spawnZ != null) {
|
||||
tree["SpawnX"] = new TagInt(_spawnX ?? 0);
|
||||
tree["SpawnY"] = new TagInt(_spawnY ?? 0);
|
||||
tree["SpawnZ"] = new TagInt(_spawnZ ?? 0);
|
||||
tree["SpawnX"] = new TagNodeInt(_spawnX ?? 0);
|
||||
tree["SpawnY"] = new TagNodeInt(_spawnY ?? 0);
|
||||
tree["SpawnZ"] = new TagNodeInt(_spawnZ ?? 0);
|
||||
}
|
||||
|
||||
if (_world != null) {
|
||||
tree["World"] = new TagString(_world);
|
||||
tree["World"] = new TagNodeString(_world);
|
||||
}
|
||||
|
||||
tree["Inventory"] = _inventory.BuildTree();
|
||||
|
@ -216,7 +216,7 @@ namespace Substrate
|
|||
return tree;
|
||||
}
|
||||
|
||||
public virtual new bool ValidateTree (TagValue tree)
|
||||
public virtual new bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, PlayerSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace Substrate
|
|||
|
||||
public bool SetPlayer (string name, Player player)
|
||||
{
|
||||
return SavePlayerTree(name, new NBT_Tree(player.BuildTree() as TagCompound));
|
||||
return SavePlayerTree(name, new NBT_Tree(player.BuildTree() as TagNodeCompound));
|
||||
}
|
||||
|
||||
public bool PlayerExists (string name)
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.TileEntities
|
|||
|
||||
public class TileEntityChest : TileEntity, IItemContainer
|
||||
{
|
||||
public static readonly NBTCompoundNode ChestSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound ChestSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Chest"),
|
||||
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
new SchemaNodeString("id", "Chest"),
|
||||
new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
});
|
||||
|
||||
private const int _CAPACITY = 27;
|
||||
|
@ -58,28 +58,28 @@ namespace Substrate.TileEntities
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public override TileEntity LoadTree (TagValue tree)
|
||||
public override TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TagList items = ctree["Items"].ToTagList();
|
||||
TagNodeList items = ctree["Items"].ToTagList();
|
||||
_items = new ItemCollection(_CAPACITY).LoadTree(items);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Items"] = _items.BuildTree();
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, ChestSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ namespace Substrate.TileEntities
|
|||
|
||||
public class TileEntityFurnace : TileEntity, IItemContainer
|
||||
{
|
||||
public static readonly NBTCompoundNode FurnaceSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound FurnaceSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Furnace"),
|
||||
new NBTScalerNode("BurnTime", TagType.TAG_SHORT),
|
||||
new NBTScalerNode("CookTime", TagType.TAG_SHORT),
|
||||
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
new SchemaNodeString("id", "Furnace"),
|
||||
new SchemaNodeScaler("BurnTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeScaler("CookTime", TagType.TAG_SHORT),
|
||||
new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
});
|
||||
|
||||
private const int _CAPACITY = 3;
|
||||
|
@ -78,9 +78,9 @@ namespace Substrate.TileEntities
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public override TileEntity LoadTree (TagValue tree)
|
||||
public override TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -88,23 +88,23 @@ namespace Substrate.TileEntities
|
|||
_burnTime = ctree["BurnTime"].ToTagShort();
|
||||
_cookTime = ctree["CookTime"].ToTagShort();
|
||||
|
||||
TagList items = ctree["Items"].ToTagList();
|
||||
TagNodeList items = ctree["Items"].ToTagList();
|
||||
_items = new ItemCollection(_CAPACITY).LoadTree(items);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["BurnTime"] = new TagShort(_burnTime);
|
||||
tree["CookTime"] = new TagShort(_cookTime);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["BurnTime"] = new TagNodeShort(_burnTime);
|
||||
tree["CookTime"] = new TagNodeShort(_cookTime);
|
||||
tree["Items"] = _items.BuildTree();
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, FurnaceSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace Substrate.TileEntities
|
|||
|
||||
public class TileEntityMobSpawner : TileEntity
|
||||
{
|
||||
public static readonly NBTCompoundNode MobSpawnerSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound MobSpawnerSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "MobSpawner"),
|
||||
new NBTScalerNode("EntityId", TagType.TAG_STRING),
|
||||
new NBTScalerNode("Delay", TagType.TAG_SHORT),
|
||||
new SchemaNodeString("id", "MobSpawner"),
|
||||
new SchemaNodeScaler("EntityId", TagType.TAG_STRING),
|
||||
new SchemaNodeScaler("Delay", TagType.TAG_SHORT),
|
||||
});
|
||||
|
||||
private short _delay;
|
||||
|
@ -58,9 +58,9 @@ namespace Substrate.TileEntities
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public override TileEntity LoadTree (TagValue tree)
|
||||
public override TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -71,16 +71,16 @@ namespace Substrate.TileEntities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["EntityID"] = new TagString(_entityID);
|
||||
tree["Delay"] = new TagShort(_delay);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["EntityID"] = new TagNodeString(_entityID);
|
||||
tree["Delay"] = new TagNodeShort(_delay);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, MobSpawnerSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.TileEntities
|
|||
|
||||
public class TileEntityMusic : TileEntity
|
||||
{
|
||||
public static readonly NBTCompoundNode MusicSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound MusicSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Music"),
|
||||
new NBTScalerNode("note", TagType.TAG_BYTE),
|
||||
new SchemaNodeString("id", "Music"),
|
||||
new SchemaNodeScaler("note", TagType.TAG_BYTE),
|
||||
});
|
||||
|
||||
private byte _note;
|
||||
|
@ -49,9 +49,9 @@ namespace Substrate.TileEntities
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public override TileEntity LoadTree (TagValue tree)
|
||||
public override TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -61,15 +61,15 @@ namespace Substrate.TileEntities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
tree["note"] = new TagByte(_note);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["note"] = new TagNodeByte(_note);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, MusicSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.TileEntities
|
|||
|
||||
public class TileEntityRecordPlayer : TileEntity
|
||||
{
|
||||
public static readonly NBTCompoundNode RecordPlayerSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound RecordPlayerSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "RecordPlayer"),
|
||||
new NBTScalerNode("Record", TagType.TAG_INT, NBTOptions.OPTIONAL),
|
||||
new SchemaNodeString("id", "RecordPlayer"),
|
||||
new SchemaNodeScaler("Record", TagType.TAG_INT, SchemaOptions.OPTIONAL),
|
||||
});
|
||||
|
||||
private int? _record = null;
|
||||
|
@ -49,9 +49,9 @@ namespace Substrate.TileEntities
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public override TileEntity LoadTree (TagValue tree)
|
||||
public override TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -63,18 +63,18 @@ namespace Substrate.TileEntities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
|
||||
if (_record != null) {
|
||||
tree["Record"] = new TagInt((int)_record);
|
||||
tree["Record"] = new TagNodeInt((int)_record);
|
||||
}
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, RecordPlayerSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ namespace Substrate.TileEntities
|
|||
|
||||
public class TileEntitySign : TileEntity
|
||||
{
|
||||
public static readonly NBTCompoundNode SignSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound SignSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Sign"),
|
||||
new NBTScalerNode("Text1", TagType.TAG_STRING),
|
||||
new NBTScalerNode("Text2", TagType.TAG_STRING),
|
||||
new NBTScalerNode("Text3", TagType.TAG_STRING),
|
||||
new NBTScalerNode("Text4", TagType.TAG_STRING),
|
||||
new SchemaNodeString("id", "Sign"),
|
||||
new SchemaNodeScaler("Text1", TagType.TAG_STRING),
|
||||
new SchemaNodeScaler("Text2", TagType.TAG_STRING),
|
||||
new SchemaNodeScaler("Text3", TagType.TAG_STRING),
|
||||
new SchemaNodeScaler("Text4", TagType.TAG_STRING),
|
||||
});
|
||||
|
||||
private string _text1 = "";
|
||||
|
@ -76,9 +76,9 @@ namespace Substrate.TileEntities
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public override TileEntity LoadTree (TagValue tree)
|
||||
public override TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -91,18 +91,18 @@ namespace Substrate.TileEntities
|
|||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
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);
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Text1"] = new TagNodeString(_text1);
|
||||
tree["Text2"] = new TagNodeString(_text2);
|
||||
tree["Text3"] = new TagNodeString(_text3);
|
||||
tree["Text4"] = new TagNodeString(_text4);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, SignSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace Substrate.TileEntities
|
|||
|
||||
public class TileEntityTrap : TileEntity, IItemContainer
|
||||
{
|
||||
public static readonly NBTCompoundNode TrapSchema = BaseSchema.MergeInto(new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound TrapSchema = BaseSchema.MergeInto(new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTStringNode("id", "Trap"),
|
||||
new NBTListNode("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
new SchemaNodeString("id", "Trap"),
|
||||
new SchemaNodeList("Items", TagType.TAG_COMPOUND, ItemCollection.InventorySchema),
|
||||
});
|
||||
|
||||
private const int _CAPACITY = 8;
|
||||
|
@ -59,28 +59,28 @@ namespace Substrate.TileEntities
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public override TileEntity LoadTree (TagValue tree)
|
||||
public override TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null || base.LoadTree(tree) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TagList items = ctree["Items"].ToTagList();
|
||||
TagNodeList items = ctree["Items"].ToTagList();
|
||||
_items = new ItemCollection(_CAPACITY).LoadTree(items);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override TagValue BuildTree ()
|
||||
public override TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = base.BuildTree() as TagCompound;
|
||||
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
||||
tree["Items"] = _items.BuildTree();
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public override bool ValidateTree (TagValue tree)
|
||||
public override bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, TrapSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ namespace Substrate
|
|||
|
||||
public class TileEntity : INBTObject<TileEntity>, ICopyable<TileEntity>
|
||||
{
|
||||
public static readonly NBTCompoundNode BaseSchema = new NBTCompoundNode("")
|
||||
public static readonly SchemaNodeCompound BaseSchema = new SchemaNodeCompound("")
|
||||
{
|
||||
new NBTScalerNode("id", TagType.TAG_STRING),
|
||||
new NBTScalerNode("x", TagType.TAG_INT),
|
||||
new NBTScalerNode("y", TagType.TAG_INT),
|
||||
new NBTScalerNode("z", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("id", TagType.TAG_STRING),
|
||||
new SchemaNodeScaler("x", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("y", TagType.TAG_INT),
|
||||
new SchemaNodeScaler("z", TagType.TAG_INT),
|
||||
};
|
||||
|
||||
private string _id;
|
||||
|
@ -76,9 +76,9 @@ namespace Substrate
|
|||
|
||||
#region INBTObject<TileEntity> Members
|
||||
|
||||
public virtual TileEntity LoadTree (TagValue tree)
|
||||
public virtual TileEntity LoadTree (TagNode tree)
|
||||
{
|
||||
TagCompound ctree = tree as TagCompound;
|
||||
TagNodeCompound ctree = tree as TagNodeCompound;
|
||||
if (ctree == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ namespace Substrate
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual TileEntity LoadTreeSafe (TagValue tree)
|
||||
public virtual TileEntity LoadTreeSafe (TagNode tree)
|
||||
{
|
||||
if (!ValidateTree(tree)) {
|
||||
return null;
|
||||
|
@ -100,18 +100,18 @@ namespace Substrate
|
|||
return LoadTree(tree);
|
||||
}
|
||||
|
||||
public virtual TagValue BuildTree ()
|
||||
public virtual TagNode BuildTree ()
|
||||
{
|
||||
TagCompound tree = new TagCompound();
|
||||
tree["id"] = new TagString(_id);
|
||||
tree["x"] = new TagInt(_x);
|
||||
tree["y"] = new TagInt(_y);
|
||||
tree["z"] = new TagInt(_z);
|
||||
TagNodeCompound tree = new TagNodeCompound();
|
||||
tree["id"] = new TagNodeString(_id);
|
||||
tree["x"] = new TagNodeInt(_x);
|
||||
tree["y"] = new TagNodeInt(_y);
|
||||
tree["z"] = new TagNodeInt(_z);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
public virtual bool ValidateTree (TagValue tree)
|
||||
public virtual bool ValidateTree (TagNode tree)
|
||||
{
|
||||
return new NBTVerifier(tree, BaseSchema).Verify();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Substrate
|
|||
return Activator.CreateInstance(t) as TileEntity;
|
||||
}
|
||||
|
||||
public static TileEntity Create (TagCompound tree)
|
||||
public static TileEntity Create (TagNodeCompound tree)
|
||||
{
|
||||
string type = tree["id"].ToTagString();
|
||||
|
||||
|
|
|
@ -76,6 +76,19 @@
|
|||
<Compile Include="Source\BlockLight.cs" />
|
||||
<Compile Include="Source\BlockTileEntities.cs" />
|
||||
<Compile Include="Source\Level.cs" />
|
||||
<Compile Include="Source\NBT\TagNode.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeByteArray.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeCompound.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeDouble.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeFloat.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeInt.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeList.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeLong.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeShort.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeString.cs" />
|
||||
<Compile Include="Source\NBT\TagType.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeByte.cs" />
|
||||
<Compile Include="Source\NBT\TagNodeNull.cs" />
|
||||
<Compile Include="Source\PlayerManager.cs" />
|
||||
<Compile Include="Source\PlayerFile.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -126,7 +139,6 @@
|
|||
<Compile Include="Source\NBT\JSONSerializer.cs" />
|
||||
<Compile Include="Source\NBT\NBT.cs" />
|
||||
<Compile Include="Source\NBT\NBTSchema.cs" />
|
||||
<Compile Include="Source\NBT\NBTValues.cs" />
|
||||
<Compile Include="Source\NBT\NBTVerifier.cs" />
|
||||
<Compile Include="Source\Player.cs" />
|
||||
<Compile Include="Source\Region.cs" />
|
||||
|
|
Loading…
Reference in a new issue