diff --git a/Substrate/SubstrateCS/Properties/AssemblyInfo.cs b/Substrate/SubstrateCS/Properties/AssemblyInfo.cs index 833ee80..d03ee62 100644 --- a/Substrate/SubstrateCS/Properties/AssemblyInfo.cs +++ b/Substrate/SubstrateCS/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs b/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs index 0f339cb..f2b6120 100644 --- a/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs +++ b/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs @@ -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; diff --git a/Substrate/SubstrateCS/Source/BlockTileEntities.cs b/Substrate/SubstrateCS/Source/BlockTileEntities.cs index d6d98ab..c368a79 100644 --- a/Substrate/SubstrateCS/Source/BlockTileEntities.cs +++ b/Substrate/SubstrateCS/Source/BlockTileEntities.cs @@ -11,13 +11,13 @@ namespace Substrate public class BlockTileEntities { private XZYByteArray _blocks; - private TagList _tileEntities; + private TagNodeList _tileEntities; - private Dictionary _tileEntityTable; + private Dictionary _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(); + _tileEntityTable = new Dictionary(); - 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(); diff --git a/Substrate/SubstrateCS/Source/Chunk.cs b/Substrate/SubstrateCS/Source/Chunk.cs index dd6afea..bad97d8 100644 --- a/Substrate/SubstrateCS/Source/Chunk.cs +++ b/Substrate/SubstrateCS/Source/Chunk.cs @@ -22,21 +22,21 @@ namespace Substrate /// /// An NBT Schema definition for valid chunk data. /// - 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 /// /// Root node of an NBT tree. /// A reference to the current Chunk, or null if the tree is unparsable. - 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 /// /// Root node of an NBT tree. /// A reference to the current Chunk, or null if the tree does not conform to the chunk's NBT Schema definition. - 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. /// /// The root node of the Chunk's NBT tree. - public TagValue BuildTree () + public TagNode BuildTree () { return _tree.Root; } @@ -263,7 +263,7 @@ namespace Substrate /// /// The root node of the NBT tree to verify. /// Status indicating if the tree represents a valid chunk. - 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); diff --git a/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs b/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs index 46af987..73f7a9b 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityArrow.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, ArrowSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityBoat.cs b/Substrate/SubstrateCS/Source/Entities/EntityBoat.cs index 77746c0..483b5e1 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityBoat.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityBoat.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, BoatSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityChicken.cs b/Substrate/SubstrateCS/Source/Entities/EntityChicken.cs index 8315fc8..6185159 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityChicken.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityChicken.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, ChickenSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityCow.cs b/Substrate/SubstrateCS/Source/Entities/EntityCow.cs index cd27d4f..2170ea3 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityCow.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityCow.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, CowSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityCreeper.cs b/Substrate/SubstrateCS/Source/Entities/EntityCreeper.cs index ca61856..50d3fbf 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityCreeper.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityCreeper.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, CreeperSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityEgg.cs b/Substrate/SubstrateCS/Source/Entities/EntityEgg.cs index b8a417f..9b15a77 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityEgg.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityEgg.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, EggSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs b/Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs index 2b65ad9..280cf9a 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityFallingSand.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityGhast.cs b/Substrate/SubstrateCS/Source/Entities/EntityGhast.cs index 9dd8a7e..d9758b7 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityGhast.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityGhast.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, GhastSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityGiant.cs b/Substrate/SubstrateCS/Source/Entities/EntityGiant.cs index a0f468d..c334091 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityGiant.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityGiant.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, GiantSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityItem.cs b/Substrate/SubstrateCS/Source/Entities/EntityItem.cs index f746bca..f13bbfd 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityItem.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityItem.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs b/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs index 21f27f8..9f54f3e 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityMinecart.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs b/Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs index af3516c..69057f3 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityMinecartChest.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs b/Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs index f3fe539..83ba287 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityMinecartFurnace.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMob.cs b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs index d1c176d..1f93868 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityMob.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityMob.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityMonster.cs b/Substrate/SubstrateCS/Source/Entities/EntityMonster.cs index 8f34944..adfd477 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityMonster.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityMonster.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, MonsterSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs b/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs index 26fe6c6..6c62a3f 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityPainting.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPig.cs b/Substrate/SubstrateCS/Source/Entities/EntityPig.cs index 38341d0..0e61368 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityPig.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityPig.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPigZombie.cs b/Substrate/SubstrateCS/Source/Entities/EntityPigZombie.cs index a21540d..b88fe9a 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityPigZombie.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityPigZombie.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, PigZombieSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs b/Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs index b23ceef..c574202 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityPrimedTnt.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySheep.cs b/Substrate/SubstrateCS/Source/Entities/EntitySheep.cs index bfc5ec5..71b6e18 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntitySheep.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntitySheep.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySkeleton.cs b/Substrate/SubstrateCS/Source/Entities/EntitySkeleton.cs index 49dd933..8beaecb 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntitySkeleton.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntitySkeleton.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, SkeletonSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySlime.cs b/Substrate/SubstrateCS/Source/Entities/EntitySlime.cs index 7357aa2..0b82c1f 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntitySlime.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntitySlime.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySnowball.cs b/Substrate/SubstrateCS/Source/Entities/EntitySnowball.cs index 881bc7f..00d5d7a 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntitySnowball.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntitySnowball.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, SnowballSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySpider.cs b/Substrate/SubstrateCS/Source/Entities/EntitySpider.cs index 8270f0e..7aa9fbc 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntitySpider.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntitySpider.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, SpiderSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntitySquid.cs b/Substrate/SubstrateCS/Source/Entities/EntitySquid.cs index ea7d6cb..3aa979b 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntitySquid.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntitySquid.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, SquidSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs b/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs index 48c96e0..58d47cc 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityThrowable.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityWolf.cs b/Substrate/SubstrateCS/Source/Entities/EntityWolf.cs index 52a9c23..5bb02e8 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityWolf.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityWolf.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/Entities/EntityZombie.cs b/Substrate/SubstrateCS/Source/Entities/EntityZombie.cs index 6aecf62..c3e8efc 100644 --- a/Substrate/SubstrateCS/Source/Entities/EntityZombie.cs +++ b/Substrate/SubstrateCS/Source/Entities/EntityZombie.cs @@ -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 Members - public override bool ValidateTree (TagValue tree) + public override bool ValidateTree (TagNode tree) { return new NBTVerifier(tree, ZombieSchema).Verify(); } diff --git a/Substrate/SubstrateCS/Source/Entity.cs b/Substrate/SubstrateCS/Source/Entity.cs index 9c0cd83..ad15384 100644 --- a/Substrate/SubstrateCS/Source/Entity.cs +++ b/Substrate/SubstrateCS/Source/Entity.cs @@ -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 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, ICopyable { - 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 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(); } diff --git a/Substrate/SubstrateCS/Source/EntityCollection.cs b/Substrate/SubstrateCS/Source/EntityCollection.cs index 48bf1d2..9343e19 100644 --- a/Substrate/SubstrateCS/Source/EntityCollection.cs +++ b/Substrate/SubstrateCS/Source/EntityCollection.cs @@ -8,7 +8,7 @@ namespace Substrate public class EntityCollection : IEnumerable { - 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 set = new List(); - 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 set = new List(); - 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 { - private IEnumerator _enum; + private IEnumerator _enum; private Entity _cur; - public EntityEnumerator (TagList entities) + public EntityEnumerator (TagNodeList entities) { _enum = entities.GetEnumerator(); } diff --git a/Substrate/SubstrateCS/Source/EntityFactory.cs b/Substrate/SubstrateCS/Source/EntityFactory.cs index 279da64..a4a848c 100644 --- a/Substrate/SubstrateCS/Source/EntityFactory.cs +++ b/Substrate/SubstrateCS/Source/EntityFactory.cs @@ -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; } diff --git a/Substrate/SubstrateCS/Source/Item.cs b/Substrate/SubstrateCS/Source/Item.cs index f852705..c4ba7aa 100644 --- a/Substrate/SubstrateCS/Source/Item.cs +++ b/Substrate/SubstrateCS/Source/Item.cs @@ -14,11 +14,11 @@ namespace Substrate public class Item : INBTObject, ICopyable { - 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 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, ICopyable { - 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 _items; protected int _capacity; @@ -190,14 +190,14 @@ namespace Substrate #region INBTObject 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 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(); } diff --git a/Substrate/SubstrateCS/Source/Level.cs b/Substrate/SubstrateCS/Source/Level.cs index 09ff730..65b4bda 100644 --- a/Substrate/SubstrateCS/Source/Level.cs +++ b/Substrate/SubstrateCS/Source/Level.cs @@ -10,24 +10,24 @@ namespace Substrate public class Level : INBTObject, ICopyable { - 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 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(); } diff --git a/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs b/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs index c8c4c18..c70f51c 100644 --- a/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs +++ b/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs @@ -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> en = tag.GetEnumerator(); + IEnumerator> en = tag.GetEnumerator(); bool first = true; while (en.MoveNext()) { if (!first) { @@ -48,14 +48,14 @@ namespace Substrate.NBT str.AppendLine(); } - KeyValuePair item = en.Current; + KeyValuePair 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 en = tag.GetEnumerator(); + IEnumerator 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: diff --git a/Substrate/SubstrateCS/Source/NBT/NBT.cs b/Substrate/SubstrateCS/Source/NBT/NBT.cs index aac872e..eb0a1a3 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBT.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBT.cs @@ -8,43 +8,93 @@ namespace Substrate.NBT { using Substrate.Utility; + /// + /// Defines methods for loading or extracting an NBT tree. + /// + /// Object type that supports this interface. public interface INBTObject { - T LoadTree (TagValue tree); - T LoadTreeSafe (TagValue tree); + /// + /// Attempt to load an NBT tree into the object without validation. + /// + /// The root node of an NBT tree. + /// The object returns itself on success, or null if the tree was unparsable. + T LoadTree (TagNode tree); - TagValue BuildTree (); + /// + /// Attempt to load an NBT tree into the object with validation. + /// + /// The root node of an NBT tree. + /// The object returns itself on success, or null if the tree failed validation. + T LoadTreeSafe (TagNode tree); - bool ValidateTree (TagValue tree); + /// + /// Builds an NBT tree from the object's data. + /// + /// The root node of an NBT tree representing the object's data. + TagNode BuildTree (); + + /// + /// Validate an NBT tree, usually against an object-supplied schema. + /// + /// The root node of an NBT tree. + /// Status indicating whether the tree was valid for this object. + bool ValidateTree (TagNode tree); } + /// + /// Contains the root node of an NBT tree and handles IO of tree nodes. + /// + /// + /// 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. + /// public class NBT_Tree : ICopyable { 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 + /// + /// Gets the root node of this tree. + /// + public TagNodeCompound Root { get { return _root; } } + /// + /// Constructs a wrapper around a new NBT tree with an empty root node. + /// public NBT_Tree () { - _root = new TagCompound(); + _root = new TagNodeCompound(); } - public NBT_Tree (TagCompound tree) + /// + /// Constructs a wrapper around another NBT tree. + /// + /// The root node of an NBT tree. + public NBT_Tree (TagNodeCompound tree) { _root = tree; } + /// + /// Constructs and wrapper around a new NBT tree parsed from a source data stream. + /// + /// An open, readable data stream containing NBT data. public NBT_Tree (Stream s) { ReadFrom(s); } + /// + /// Rebuild the internal NBT tree from a source data stream. + /// + /// An open, readable data stream containing NBT data. public void ReadFrom (Stream s) { if (s != null) { @@ -54,6 +104,10 @@ namespace Substrate.NBT } } + /// + /// Writes out the internal NBT tree to a destination data stream. + /// + /// An open, writable data stream. 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 item in val) { + foreach (KeyValuePair 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 Members + /// + /// Creates a deep copy of the NBT_Tree and underlying nodes. + /// + /// A new NBT_tree. 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"; diff --git a/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs b/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs index a95e714..2f9bc19 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs @@ -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 + public sealed class SchemaNodeCompound : SchemaNode, ICollection { - private List _subnodes; + private List _subnodes; #region ICollection 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 Members - public IEnumerator GetEnumerator () + public IEnumerator GetEnumerator () { return _subnodes.GetEnumerator(); } @@ -327,65 +327,65 @@ namespace Substrate.NBT #endregion - public NBTCompoundNode () + public SchemaNodeCompound () : base("") { - _subnodes = new List(); + _subnodes = new List(); } - public NBTCompoundNode (NBTOptions options) + public SchemaNodeCompound (SchemaOptions options) : base("", options) { - _subnodes = new List(); + _subnodes = new List(); } - public NBTCompoundNode (string name) + public SchemaNodeCompound (string name) : base(name) { - _subnodes = new List(); + _subnodes = new List(); } - public NBTCompoundNode (string name, NBTOptions options) + public SchemaNodeCompound (string name, SchemaOptions options) : base(name, options) { - _subnodes = new List(); + _subnodes = new List(); } - public NBTCompoundNode (string name, NBTSchemaNode subschema) + public SchemaNodeCompound (string name, SchemaNode subschema) : base(name) { - _subnodes = new List(); + _subnodes = new List(); - 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(); + _subnodes = new List(); - 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(); } diff --git a/Substrate/SubstrateCS/Source/NBT/NBTValues.cs b/Substrate/SubstrateCS/Source/NBT/NBTValues.cs deleted file mode 100644 index 7d788e5..0000000 --- a/Substrate/SubstrateCS/Source/NBT/NBTValues.cs +++ /dev/null @@ -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 - { - 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 - { - private TagType _type = TagType.TAG_END; - - private List _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(); - } - - public TagList (TagType type, List 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 FindAll(Predicate match) - { - return _items.FindAll(match); - } - - public int RemoveAll (Predicate match) - { - return _items.RemoveAll(match); - } - - public override string ToString () - { - return _items.ToString(); - } - - #region IList 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 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 Members - - public IEnumerator 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 - { - private Dictionary _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(); - } - - public override TagValue Copy () - { - TagCompound list = new TagCompound(); - foreach (KeyValuePair item in _tags) { - list[item.Key] = item.Value.Copy(); - } - return list; - } - - public override string ToString () - { - return _tags.ToString(); - } - - #region IDictionary Members - - public void Add (string key, TagValue value) - { - _tags.Add(key, value); - } - - public bool ContainsKey (string key) - { - return _tags.ContainsKey(key); - } - - public ICollection 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 Values - { - get { return _tags.Values; } - } - - public TagValue this[string key] - { - get - { - return _tags[key]; - } - set - { - _tags[key] = value; - } - } - - #endregion - - #region ICollection> Members - - public void Add (KeyValuePair item) - { - _tags.Add(item.Key, item.Value); - } - - public void Clear () - { - _tags.Clear(); - } - - public bool Contains (KeyValuePair item) - { - TagValue value; - if (!_tags.TryGetValue(item.Key, out value)) { - return false; - } - return value == item.Value; - } - - public void CopyTo (KeyValuePair[] 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 item in _tags) { - array[arrayIndex] = item; - arrayIndex++; - } - } - - public bool IsReadOnly - { - get { return false; } - } - - public bool Remove (KeyValuePair item) - { - if (Contains(item)) { - _tags.Remove(item.Key); - return true; - } - return false; - } - - #endregion - - #region IEnumerable> Members - - public IEnumerator> GetEnumerator () - { - return _tags.GetEnumerator(); - } - - #endregion - - #region IEnumerable Members - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () - { - return _tags.GetEnumerator(); - } - - #endregion - } -} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs b/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs index 31973de..b2a4bce 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBTVerifier.cs @@ -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 _scratch = new Dictionary(); + private Dictionary _scratch = new Dictionary(); 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 item in _scratch) { + foreach (KeyValuePair item in _scratch) { ctag[item.Key] = item.Value; } diff --git a/Substrate/SubstrateCS/Source/NBT/TagNode.cs b/Substrate/SubstrateCS/Source/NBT/TagNode.cs new file mode 100644 index 0000000..d9791a8 --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNode.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Substrate.NBT { + + using Substrate.Utility; + + /// + /// An abstract base class representing a node in an NBT tree. + /// + public abstract class TagNode : ICopyable + { + /// + /// Convert this node to a null tag type if supported. + /// + /// A new null node. + public virtual TagNodeNull ToTagNull () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a byte tag type if supported. + /// + /// A new byte node. + public virtual TagNodeByte ToTagByte () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a short tag type if supported. + /// + /// A new short node. + public virtual TagNodeShort ToTagShort () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to an int tag type if supported. + /// + /// A new int node. + public virtual TagNodeInt ToTagInt () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a long tag type if supported. + /// + /// A new long node. + public virtual TagNodeLong ToTagLong () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a float tag type if supported. + /// + /// A new float node. + public virtual TagNodeFloat ToTagFloat () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a double tag type if supported. + /// + /// A new double node. + public virtual TagNodeDouble ToTagDouble () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a byte array tag type if supported. + /// + /// A new byte array node. + public virtual TagNodeByteArray ToTagByteArray () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a string tag type if supported. + /// + /// A new string node. + public virtual TagNodeString ToTagString () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a list tag type if supported. + /// + /// A new list node. + public virtual TagNodeList ToTagList () + { + throw new InvalidCastException(); + } + + /// + /// Convert this node to a compound tag type if supported. + /// + /// A new compound node. + public virtual TagNodeCompound ToTagCompound () + { + throw new InvalidCastException(); + } + + /// + /// Gets the underlying tag type of the node. + /// + /// An NBT tag type. + public virtual TagType GetTagType () + { + return TagType.TAG_END; + } + + /// + /// Checks if this node is castable to another node of a given tag type. + /// + /// An NBT tag type. + /// Status indicating whether this object could be cast to a node type represented by the given tag type. + public virtual bool IsCastableTo (TagType type) + { + return type == GetTagType(); + } + + /// + /// Makes a deep copy of the NBT node. + /// + /// A new NBT node. + public virtual TagNode Copy () + { + return null; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeByte.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeByte.cs new file mode 100644 index 0000000..1a14bdd --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeByte.cs @@ -0,0 +1,161 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a signed byte tag type. + /// + public sealed class TagNodeByte : TagNode + { + private byte _data = 0; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeByte ToTagByte () + { + return this; + } + + /// + /// Converts the node to a new short node. + /// + /// A short node representing the same data. + public override TagNodeShort ToTagShort () + { + return new TagNodeShort(_data); + } + + /// + /// Converts the node to a new int node. + /// + /// An int node representing the same data. + public override TagNodeInt ToTagInt () + { + return new TagNodeInt(_data); + } + + /// + /// Converts the node to a new long node. + /// + /// A long node representing the same data. + public override TagNodeLong ToTagLong () + { + return new TagNodeLong(_data); + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_BYTE tag type. + public override TagType GetTagType () + { + return TagType.TAG_BYTE; + } + + /// + /// Checks if the node is castable to another node of a given tag type. + /// + /// An NBT tag type. + /// Status indicating whether this object could be cast to a node type represented by the given tag type. + public override bool IsCastableTo (TagType type) + { + return (type == TagType.TAG_BYTE || + type == TagType.TAG_SHORT || + type == TagType.TAG_INT || + type == TagType.TAG_LONG); + } + + /// + /// Gets or sets a byte of tag data. + /// + public byte Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Constructs a new byte node with a data value of 0. + /// + public TagNodeByte () { } + + /// + /// Constructs a new byte node. + /// + /// The value to set the node's tag data value. + public TagNodeByte (byte d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new byte node representing the same data. + public override TagNode Copy () + { + return new TagNodeByte(_data); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Converts a system byte to a byte node representing the same value. + /// + /// A byte value. + /// A new byte node containing the given value. + public static implicit operator TagNodeByte (byte b) + { + return new TagNodeByte(b); + } + + /// + /// Converts a byte node to a system byte representing the same value. + /// + /// A byte node. + /// A system byte set to the node's data value. + public static implicit operator byte (TagNodeByte b) + { + return b._data; + } + + /// + /// Converts a byte node to a system short representing the same value. + /// + /// A byte node. + /// A system short set to the node's data value. + public static implicit operator short (TagNodeByte b) + { + return b._data; + } + + /// + /// Converts a byte node to a system int representing the same value. + /// + /// A byte node. + /// A system int set to the node's data value. + public static implicit operator int (TagNodeByte b) + { + return b._data; + } + + /// + /// Converts a byte node to a system long representing the same value. + /// + /// A byte node. + /// A system long set to the node's data value. + public static implicit operator long (TagNodeByte b) + { + return b._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeByteArray.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeByteArray.cs new file mode 100644 index 0000000..ba9fc36 --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeByteArray.cs @@ -0,0 +1,113 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing an unsigned byte array tag type. + /// + public sealed class TagNodeByteArray : TagNode + { + private byte[] _data = null; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeByteArray ToTagByteArray () + { + return this; + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_BYTE_ARRAY tag type. + public override TagType GetTagType () + { + return TagType.TAG_BYTE_ARRAY; + } + + /// + /// Gets or sets a byte array of tag data. + /// + public byte[] Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Gets the length of the stored byte array. + /// + public int Length + { + get { return _data.Length; } + } + + /// + /// Constructs a new byte array node with a null data value. + /// + public TagNodeByteArray () { } + + /// + /// Constructs a new byte array node. + /// + /// The value to set the node's tag data value. + public TagNodeByteArray (byte[] d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new byte array node representing the same data. + public override TagNode Copy () + { + byte[] arr = new byte[_data.Length]; + _data.CopyTo(arr, 0); + + return new TagNodeByteArray(arr); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Gets or sets a single byte at the specified index. + /// + /// Valid index within stored byte array. + /// The byte value at the given index of the stored byte array. + public byte this[int index] + { + get { return _data[index]; } + set { _data[index] = value; } + } + + /// + /// Converts a system byte array to a byte array node representing the same data. + /// + /// A byte array. + /// A new byte array node containing the given value. + public static implicit operator TagNodeByteArray (byte[] b) + { + return new TagNodeByteArray(b); + } + + /// + /// Converts a byte array node to a system byte array representing the same data. + /// + /// A byte array node. + /// A system byte array set to the node's data. + public static implicit operator byte[] (TagNodeByteArray b) + { + return b._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeCompound.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeCompound.cs new file mode 100644 index 0000000..7f31801 --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeCompound.cs @@ -0,0 +1,265 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a compound tag type containing other nodes. + /// + public sealed class TagNodeCompound : TagNode, IDictionary + { + private Dictionary _tags; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeCompound ToTagCompound () + { + return this; + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_STRING tag type. + public override TagType GetTagType () + { + return TagType.TAG_COMPOUND; + } + + /// + /// Gets the number of subnodes contained in node. + /// + public int Count + { + get { return _tags.Count; } + } + + /// + /// Constructs a new empty compound node. + /// + public TagNodeCompound () + { + _tags = new Dictionary(); + } + + /// + /// Makes a deep copy of the node. + /// + /// A new compound node containing new subnodes representing the same data. + public override TagNode Copy () + { + TagNodeCompound list = new TagNodeCompound(); + foreach (KeyValuePair item in _tags) { + list[item.Key] = item.Value.Copy(); + } + return list; + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _tags.ToString(); + } + + #region IDictionary Members + + /// + /// Adds a named subnode to the set. + /// + /// The name of the subnode. + /// The subnode to add. + /// is null. + /// A subnode with the same key already exists in the set. + public void Add (string key, TagNode value) + { + _tags.Add(key, value); + } + + /// + /// Checks if a subnode exists in the set with the specified name. + /// + /// The name of a subnode to check. + /// Status indicating whether a subnode with the specified name exists. + /// is null. + public bool ContainsKey (string key) + { + return _tags.ContainsKey(key); + } + + /// + /// Gets a collection containing all the names of subnodes in this set. + /// + public ICollection Keys + { + get { return _tags.Keys; } + } + + /// + /// Removes a subnode with the specified name. + /// + /// The name of the subnode to remove. + /// Status indicating whether a subnode was removed. + /// is null. + public bool Remove (string key) + { + return _tags.Remove(key); + } + + /// + /// Gets the subnode associated with the given name. + /// + /// The name of the subnode to get. + /// When the function returns, contains the subnode assicated with the specified key. If no subnode was found, contains a default value. + /// Status indicating whether a subnode was found. + /// is null. + public bool TryGetValue (string key, out TagNode value) + { + return _tags.TryGetValue(key, out value); + } + + /// + /// Gets a collection containing all the subnodes in this set. + /// + public ICollection Values + { + get { return _tags.Values; } + } + + /// + /// Gets or sets the subnode with the associated name. + /// + /// The name of the subnode to get or set. + /// is null. + /// The property is retrieved and key does not exist in the collection. + public TagNode this[string key] + { + get + { + return _tags[key]; + } + set + { + _tags[key] = value; + } + } + + #endregion + + #region ICollection> Members + + /// + /// Adds a subnode to the to the set with the specified name. + /// + /// The structure representing the key and subnode to add to the set. + /// The key of is null. + /// A subnode with the same key already exists in the set. + public void Add (KeyValuePair item) + { + _tags.Add(item.Key, item.Value); + } + + /// + /// Removes all of the subnodes from this node. + /// + public void Clear () + { + _tags.Clear(); + } + + /// + /// Checks if a specific subnode with a specific name is contained in the set. + /// + /// The structure representing the key and subnode to look for. + /// Status indicating if the subnode and key combination exists in the set. + public bool Contains (KeyValuePair item) + { + TagNode value; + if (!_tags.TryGetValue(item.Key, out value)) { + return false; + } + return value == item.Value; + } + + /// + /// Copies the elements of the to an array of type , starting at the specified array index. + /// + /// The one-dimensional that is the destination of the subnodes copied. The Array must have zero-based indexing. + /// The zero-based index in at which copying begins. + /// is null. + /// is less than 0. + /// The number of elements in the source is greater than the available space from to the end of the destination . + public void CopyTo (KeyValuePair[] 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 item in _tags) { + array[arrayIndex] = item; + arrayIndex++; + } + } + + /// + /// Gets a value indicating whether the node is readonly. + /// + public bool IsReadOnly + { + get { return false; } + } + + /// + /// Removes the specified key and subnode combination from the set. + /// + /// The structure representing the key and value to remove from the set. + /// Status indicating whether a subnode was removed. + public bool Remove (KeyValuePair item) + { + if (Contains(item)) { + _tags.Remove(item.Key); + return true; + } + return false; + } + + #endregion + + #region IEnumerable> Members + + /// + /// Returns an enumerator that iterates through all of the subnodes in the set. + /// + /// An enumerator for this node. + public IEnumerator> GetEnumerator () + { + return _tags.GetEnumerator(); + } + + #endregion + + #region IEnumerable Members + + /// + /// Returns an enumerator that iterates through all of the subnodes in the set. + /// + /// An enumerator for this node. + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () + { + return _tags.GetEnumerator(); + } + + #endregion + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeDouble.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeDouble.cs new file mode 100644 index 0000000..03bbda7 --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeDouble.cs @@ -0,0 +1,101 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a double-precision floating point tag type. + /// + public sealed class TagNodeDouble : TagNode + { + private double _data = 0; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeDouble ToTagDouble () + { + return this; + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_DOUBLE tag type. + public override TagType GetTagType () + { + return TagType.TAG_DOUBLE; + } + + /// + /// Gets or sets a double of tag data. + /// + public double Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Constructs a new double node with a data value of 0.0. + /// + public TagNodeDouble () { } + + /// + /// Constructs a new double node. + /// + /// The value to set the node's tag data value. + public TagNodeDouble (double d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new double node representing the same data. + public override TagNode Copy () + { + return new TagNodeDouble(_data); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Converts a system float to a double node representing the same value. + /// + /// A float value. + /// A new double node containing the given value. + public static implicit operator TagNodeDouble (float f) + { + return new TagNodeDouble(f); + } + + /// + /// Converts a system double to a double node representing the same value. + /// + /// A double value. + /// A new double node containing the given value. + public static implicit operator TagNodeDouble (double d) + { + return new TagNodeDouble(d); + } + + /// + /// Converts a double node to a system double representing the same value. + /// + /// A double node. + /// A system double set to the node's data value. + public static implicit operator double (TagNodeDouble d) + { + return d._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeFloat.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeFloat.cs new file mode 100644 index 0000000..28ff89e --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeFloat.cs @@ -0,0 +1,121 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a single-precision floating point tag type. + /// + public sealed class TagNodeFloat : TagNode + { + private float _data = 0; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeFloat ToTagFloat () + { + return this; + } + + /// + /// Converts the node to a new double node. + /// + /// A double node representing the same data. + public override TagNodeDouble ToTagDouble () + { + return new TagNodeDouble(_data); + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_FLOAT tag type. + public override TagType GetTagType () + { + return TagType.TAG_FLOAT; + } + + /// + /// Checks if the node is castable to another node of a given tag type. + /// + /// An NBT tag type. + /// Status indicating whether this object could be cast to a node type represented by the given tag type. + public override bool IsCastableTo (TagType type) + { + return (type == TagType.TAG_FLOAT || + type == TagType.TAG_DOUBLE); + } + + /// + /// Gets or sets a float of tag data. + /// + public float Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Constructs a new float node with a data value of 0.0. + /// + public TagNodeFloat () { } + + /// + /// Constructs a new float node. + /// + /// The value to set the node's tag data value. + public TagNodeFloat (float d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new float node representing the same data. + public override TagNode Copy () + { + return new TagNodeFloat(_data); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Converts a system float to a float node representing the same value. + /// + /// A float value. + /// A new float node containing the given value. + public static implicit operator TagNodeFloat (float f) + { + return new TagNodeFloat(f); + } + + /// + /// Converts a float node to a system float representing the same value. + /// + /// A float node. + /// A system float set to the node's data value. + public static implicit operator float (TagNodeFloat f) + { + return f._data; + } + + /// + /// Converts a float node to a system double representing the same value. + /// + /// A float node. + /// A system double set to the node's data value. + public static implicit operator double (TagNodeFloat f) + { + return f._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeInt.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeInt.cs new file mode 100644 index 0000000..0a7b396 --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeInt.cs @@ -0,0 +1,141 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a signed int tag type. + /// + public sealed class TagNodeInt : TagNode + { + private int _data = 0; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeInt ToTagInt () + { + return this; + } + + /// + /// Converts the node to a new long node. + /// + /// A long node representing the same data. + public override TagNodeLong ToTagLong () + { + return new TagNodeLong(_data); + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_INT tag type. + public override TagType GetTagType () + { + return TagType.TAG_INT; + } + + /// + /// Checks if the node is castable to another node of a given tag type. + /// + /// An NBT tag type. + /// Status indicating whether this object could be cast to a node type represented by the given tag type. + public override bool IsCastableTo (TagType type) + { + return (type == TagType.TAG_INT || + type == TagType.TAG_LONG); + } + + /// + /// Gets or sets an int of tag data. + /// + public int Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Constructs a new int node with a data value of 0. + /// + public TagNodeInt () { } + + /// + /// Constructs a new int node. + /// + /// The value to set the node's tag data value. + public TagNodeInt (int d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new int node representing the same data. + public override TagNode Copy () + { + return new TagNodeInt(_data); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Converts a system byte to an int node representing the same value. + /// + /// A byte value. + /// A new int node containing the given value. + public static implicit operator TagNodeInt (byte b) + { + return new TagNodeInt(b); + } + + /// + /// Converts a system short to an int node representing the same value. + /// + /// A short value. + /// A new int node containing the given value. + public static implicit operator TagNodeInt (short s) + { + return new TagNodeInt(s); + } + + /// + /// Converts a system int to an int node representing the same value. + /// + /// An int value. + /// A new int node containing the given value. + public static implicit operator TagNodeInt (int i) + { + return new TagNodeInt(i); + } + + /// + /// Converts an int node to a system int representing the same value. + /// + /// An int node. + /// A system int set to the node's data value. + public static implicit operator int (TagNodeInt i) + { + return i._data; + } + + /// + /// Converts an int node to a system long representing the same value. + /// + /// An int node. + /// A system long set to the node's data value. + public static implicit operator long (TagNodeInt i) + { + return i._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeList.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeList.cs new file mode 100644 index 0000000..b205e2f --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeList.cs @@ -0,0 +1,264 @@ +using System; +using System.Collections.Generic; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a list tag type containing other nodes. + /// + /// + /// A list node contains 0 or more nodes of the same type. The nodes are unnamed + /// but can be accessed by sequential index. + /// + public sealed class TagNodeList : TagNode, IList + { + private TagType _type = TagType.TAG_END; + + private List _items = null; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeList ToTagList () + { + return this; + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_STRING tag type. + public override TagType GetTagType () + { + return TagType.TAG_LIST; + } + + /// + /// Gets the number of subnodes contained in the list. + /// + public int Count + { + get { return _items.Count; } + } + + /// + /// Gets the tag type of the subnodes contained in the list. + /// + public TagType ValueType + { + get { return _type; } + } + + /// + /// Constructs a new empty list node. + /// + /// The tag type of the list's subnodes. + public TagNodeList (TagType type) + { + _type = type; + _items = new List(); + } + + /// + /// Constructs a new list node from a list of nodes. + /// + /// The tag type of the list's subnodes. + /// A list containing node objects matching the type parameter. + public TagNodeList (TagType type, List items) + { + _type = type; + _items = items; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new list node containing new subnodes representing the same data. + public override TagNode Copy () + { + TagNodeList list = new TagNodeList(_type); + foreach (TagNode item in _items) { + list.Add(item.Copy()); + } + return list; + } + + /// + /// Retrieves all the subnodes that match the conditions defined by the specified predicate. + /// + /// The delegate that defines the conditions of the subnode to search for. + /// A list of all subnodes matching the predicate. + public List FindAll (Predicate match) + { + return _items.FindAll(match); + } + + /// + /// Removes all subnodes that match the conditions defined by the specified predicate. + /// + /// The delegate that defines the conditions of the subnode to search for. + /// The number of subnodes removed from the node. + public int RemoveAll (Predicate match) + { + return _items.RemoveAll(match); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _items.ToString(); + } + + #region IList Members + + /// + /// Searches for the specified subnode and returns the zero-based index of the first occurrence within the entire node's list. + /// + /// The subnode to locate. + /// The zero-based index of the subnode within the node's list if found, or -1 otherwise. + public int IndexOf (TagNode item) + { + return _items.IndexOf(item); + } + + /// + /// Inserts a subnode into the node's list at the specified index. + /// + /// The zero-based index at which the subnode should be inserted. + /// The subnode to insert. + /// Thrown when a subnode being inserted has the wrong tag type. + 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); + } + + /// + /// Removes the subnode from the node's list at the specified index. + /// + /// The zero-based index to remove a subnode at. + public void RemoveAt (int index) + { + _items.RemoveAt(index); + } + + /// + /// Gets or sets the subnode in the node's list at the specified index. + /// + /// The zero-based index to get or set from. + /// The subnode at the specified index. + /// Thrown when a subnode being assigned has the wrong tag type. + 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 Members + + /// + /// Adds a subnode to the end of the node's list. + /// + /// The subnode to add. + /// Thrown when a subnode being added has the wrong tag type. + 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); + } + + /// + /// Removes all subnode's from the node's list. + /// + public void Clear () + { + _items.Clear(); + } + + /// + /// Checks if a subnode is contained within the node's list. + /// + /// The subnode to check for existance. + /// Status indicating if the subnode exists in the node's list. + public bool Contains (TagNode item) + { + return _items.Contains(item); + } + + /// + /// Copies the entire node's list to a compatible one-dimensional array, starting at the specified index of the target array. + /// + /// The one-dimensional that is the destination of the subnodes copied. The Array must have zero-based indexing. + /// The zero-based index in at which copying begins. + public void CopyTo (TagNode[] array, int arrayIndex) + { + _items.CopyTo(array, arrayIndex); + } + + /// + /// Gets a value indicating whether the node is readonly. + /// + public bool IsReadOnly + { + get { return false; } + } + + /// + /// Removes the first occurance of a subnode from the node's list. + /// + /// The subnode to remove. + /// Status indicating whether a subnode was removed. + public bool Remove (TagNode item) + { + return _items.Remove(item); + } + + #endregion + + #region IEnumerable Members + + /// + /// Returns an enumerator that iterates through all of the subnodes in the node's list. + /// + /// An enumerator for this node. + public IEnumerator GetEnumerator () + { + return _items.GetEnumerator(); + } + + #endregion + + #region IEnumerable Members + + /// + /// Returns an enumerator that iterates through all of the subnodes in the node's list. + /// + /// An enumerator for this node. + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () + { + return _items.GetEnumerator(); + } + + #endregion + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeLong.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeLong.cs new file mode 100644 index 0000000..b0fe2f5 --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeLong.cs @@ -0,0 +1,121 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a signed long tag type. + /// + public sealed class TagNodeLong : TagNode + { + private long _data = 0; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeLong ToTagLong () + { + return this; + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_LONG tag type. + public override TagType GetTagType () + { + return TagType.TAG_LONG; + } + + /// + /// Gets or sets a long of tag data. + /// + public long Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Constructs a new long node with a data value of 0. + /// + public TagNodeLong () { } + + /// + /// Constructs a new long node. + /// + /// The value to set the node's tag data value. + public TagNodeLong (long d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new long node representing the same data. + public override TagNode Copy () + { + return new TagNodeLong(_data); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Converts a system byte to a long node representing the same value. + /// + /// A byte value. + /// A new long node containing the given value. + public static implicit operator TagNodeLong (byte b) + { + return new TagNodeLong(b); + } + + /// + /// Converts a system shprt to a long node representing the same value. + /// + /// A short value. + /// A new long node containing the given value. + public static implicit operator TagNodeLong (short s) + { + return new TagNodeLong(s); + } + + /// + /// Converts a system int to a long node representing the same value. + /// + /// An int value. + /// A new long node containing the given value. + public static implicit operator TagNodeLong (int i) + { + return new TagNodeLong(i); + } + + /// + /// Converts a system long to a long node representing the same value. + /// + /// A long value. + /// A new long node containing the given value. + public static implicit operator TagNodeLong (long l) + { + return new TagNodeLong(l); + } + + /// + /// Converts a long node to a system long representing the same value. + /// + /// A long node. + /// A system long set to the node's data value. + public static implicit operator long (TagNodeLong l) + { + return l._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeNull.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeNull.cs new file mode 100644 index 0000000..1ed93a4 --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeNull.cs @@ -0,0 +1,37 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a null tag type. + /// + public sealed class TagNodeNull : TagNode + { + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeNull ToTagNull () + { + return this; + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_END tag type. + public override TagType GetTagType () + { + return TagType.TAG_END; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new null node. + public override TagNode Copy () + { + return new TagNodeNull(); + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeShort.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeShort.cs new file mode 100644 index 0000000..1cad0db --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeShort.cs @@ -0,0 +1,151 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a signed short tag type. + /// + public sealed class TagNodeShort : TagNode + { + private short _data = 0; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeShort ToTagShort () + { + return this; + } + + /// + /// Converts the node to a new int node. + /// + /// An int node representing the same data. + public override TagNodeInt ToTagInt () + { + return new TagNodeInt(_data); + } + + /// + /// Converts the node to a new long node. + /// + /// A long node representing the same data. + public override TagNodeLong ToTagLong () + { + return new TagNodeLong(_data); + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_SHORT tag type. + public override TagType GetTagType () + { + return TagType.TAG_SHORT; + } + + /// + /// Checks if the node is castable to another node of a given tag type. + /// + /// An NBT tag type. + /// Status indicating whether this object could be cast to a node type represented by the given tag type. + public override bool IsCastableTo (TagType type) + { + return (type == TagType.TAG_SHORT || + type == TagType.TAG_INT || + type == TagType.TAG_LONG); + } + + /// + /// Gets or sets a short of tag data. + /// + public short Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Constructs a new short node with a data value of 0. + /// + public TagNodeShort () { } + + /// + /// Constructs a new short node. + /// + /// The value to set the node's tag data value. + public TagNodeShort (short d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new short node representing the same data. + public override TagNode Copy () + { + return new TagNodeShort(_data); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Converts a system byte to a short node representing the same value. + /// + /// A byte value. + /// A new short node containing the given value. + public static implicit operator TagNodeShort (byte b) + { + return new TagNodeShort(b); + } + + /// + /// Converts a system short to a short node representing the same value. + /// + /// A short value. + /// A new short node containing the given value. + public static implicit operator TagNodeShort (short s) + { + return new TagNodeShort(s); + } + + /// + /// Converts a short node to a system short representing the same value. + /// + /// A short node. + /// A system short set to the node's data value. + public static implicit operator short (TagNodeShort s) + { + return s._data; + } + + /// + /// Converts a short node to a system int representing the same value. + /// + /// A short node. + /// A system int set to the node's data value. + public static implicit operator int (TagNodeShort s) + { + return s._data; + } + + /// + /// Converts a short node to a system long representing the same value. + /// + /// A short node. + /// A system long set to the node's data value. + public static implicit operator long (TagNodeShort s) + { + return s._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagNodeString.cs b/Substrate/SubstrateCS/Source/NBT/TagNodeString.cs new file mode 100644 index 0000000..f1df7bb --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagNodeString.cs @@ -0,0 +1,99 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// An NBT node representing a string tag type. + /// + public sealed class TagNodeString : TagNode + { + private string _data = ""; + + /// + /// Converts the node to itself. + /// + /// A reference to itself. + public override TagNodeString ToTagString () + { + return this; + } + + /// + /// Gets the tag type of the node. + /// + /// The TAG_STRING tag type. + public override TagType GetTagType () + { + return TagType.TAG_STRING; + } + + /// + /// Gets or sets a string of tag data. + /// + public string Data + { + get { return _data; } + set { _data = value; } + } + + /// + /// Gets the length of the stored string. + /// + public int Length + { + get { return _data.Length; } + } + + /// + /// Constructs a new byte array node with an empty string. + /// + public TagNodeString () { } + + /// + /// Constructs a new string node. + /// + /// The value to set the node's tag data value. + public TagNodeString (string d) + { + _data = d; + } + + /// + /// Makes a deep copy of the node. + /// + /// A new string node representing the same data. + public override TagNode Copy () + { + return new TagNodeString(_data); + } + + /// + /// Gets a string representation of the node's data. + /// + /// String representation of the node's data. + public override string ToString () + { + return _data.ToString(); + } + + /// + /// Converts a system string to a string node representing the same data. + /// + /// A string. + /// A new string node containing the given value. + public static implicit operator TagNodeString (string s) + { + return new TagNodeString(s); + } + + /// + /// Converts a string node to a system string representing the same data. + /// + /// A string node. + /// A system string set to the node's data. + public static implicit operator string (TagNodeString s) + { + return s._data; + } + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/NBT/TagType.cs b/Substrate/SubstrateCS/Source/NBT/TagType.cs new file mode 100644 index 0000000..c6a4a5a --- /dev/null +++ b/Substrate/SubstrateCS/Source/NBT/TagType.cs @@ -0,0 +1,65 @@ +using System; + +namespace Substrate.NBT +{ + /// + /// Defines the type of an NBT tag. + /// + public enum TagType + { + /// + /// A null tag, used to terminate lists. + /// + TAG_END = 0, + + /// + /// A tag containing an 8-bit signed integer. + /// + TAG_BYTE = 1, + + /// + /// A tag containing a 16-bit signed integer. + /// + TAG_SHORT = 2, + + /// + /// A tag containing a 32-bit signed integer. + /// + TAG_INT = 3, + + /// + /// A tag containing a 64-bit signed integer. + /// + TAG_LONG = 4, + + /// + /// A tag containing a 32-bit (single precision) floating-point value. + /// + TAG_FLOAT = 5, + + /// + /// A tag containing a 64-bit (double precision) floating-point value. + /// + TAG_DOUBLE = 6, + + /// + /// A tag containing an array of unsigned 8-bit byte values. + /// + TAG_BYTE_ARRAY = 7, + + /// + /// A tag containing a string of text. + /// + TAG_STRING = 8, + + /// + /// A tag containing a sequential list of tags, where all tags of of the same type. + /// + TAG_LIST = 9, + + /// + /// A tag containing a key-value store of tags, where each tag can be of any type. + /// + TAG_COMPOUND = 10 + } +} \ No newline at end of file diff --git a/Substrate/SubstrateCS/Source/Player.cs b/Substrate/SubstrateCS/Source/Player.cs index 931604c..6d82404 100644 --- a/Substrate/SubstrateCS/Source/Player.cs +++ b/Substrate/SubstrateCS/Source/Player.cs @@ -9,20 +9,20 @@ namespace Substrate public class Player : UntypedEntity, INBTObject, ICopyable, 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 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(); } diff --git a/Substrate/SubstrateCS/Source/PlayerManager.cs b/Substrate/SubstrateCS/Source/PlayerManager.cs index 8c8f5b5..3de7cbd 100644 --- a/Substrate/SubstrateCS/Source/PlayerManager.cs +++ b/Substrate/SubstrateCS/Source/PlayerManager.cs @@ -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) diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityChest.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityChest.cs index 17cca71..fc7a515 100644 --- a/Substrate/SubstrateCS/Source/TileEntities/TileEntityChest.cs +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityChest.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs index c4fdc31..57e4770 100644 --- a/Substrate/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityFurnace.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs index 2bc6e91..b83b607 100644 --- a/Substrate/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMobSpawner.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityMusic.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMusic.cs index c89a8e3..5a0aca1 100644 --- a/Substrate/SubstrateCS/Source/TileEntities/TileEntityMusic.cs +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityMusic.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs index e9b5ffb..2874168 100644 --- a/Substrate/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityRecordPlayer.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntitySign.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntitySign.cs index 6a622ff..3f00f9b 100644 --- a/Substrate/SubstrateCS/Source/TileEntities/TileEntitySign.cs +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntitySign.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntities/TileEntityTrap.cs b/Substrate/SubstrateCS/Source/TileEntities/TileEntityTrap.cs index c3828d7..cb691b3 100644 --- a/Substrate/SubstrateCS/Source/TileEntities/TileEntityTrap.cs +++ b/Substrate/SubstrateCS/Source/TileEntities/TileEntityTrap.cs @@ -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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntity.cs b/Substrate/SubstrateCS/Source/TileEntity.cs index f3e6a90..132af13 100644 --- a/Substrate/SubstrateCS/Source/TileEntity.cs +++ b/Substrate/SubstrateCS/Source/TileEntity.cs @@ -9,12 +9,12 @@ namespace Substrate public class TileEntity : INBTObject, ICopyable { - 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 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(); } diff --git a/Substrate/SubstrateCS/Source/TileEntityFactory.cs b/Substrate/SubstrateCS/Source/TileEntityFactory.cs index 4353644..1ca2bb4 100644 --- a/Substrate/SubstrateCS/Source/TileEntityFactory.cs +++ b/Substrate/SubstrateCS/Source/TileEntityFactory.cs @@ -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(); diff --git a/Substrate/SubstrateCS/Substrate.csproj b/Substrate/SubstrateCS/Substrate.csproj index 394ce3e..f835b24 100644 --- a/Substrate/SubstrateCS/Substrate.csproj +++ b/Substrate/SubstrateCS/Substrate.csproj @@ -76,6 +76,19 @@ + + + + + + + + + + + + + @@ -126,7 +139,6 @@ -