2011-04-06 04:43:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2011-04-06 21:20:35 +00:00
|
|
|
|
namespace Substrate.NBT {
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-06 22:01:22 +00:00
|
|
|
|
using Substrate.Utility;
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public enum TagType
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public abstract class TagValue : ICopyable<TagValue>
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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 ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagNull : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagNull ToTagNull () { return this; }
|
|
|
|
|
public override TagType GetTagType () { return TagType.TAG_END; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagNull();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagByte : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private byte _data = 0;
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public byte Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagByte () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagByte (byte d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
|
|
|
|
{
|
|
|
|
|
return new TagByte(_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString ()
|
|
|
|
|
{
|
|
|
|
|
return _data.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator TagByte (byte b)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagByte(b);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator byte (TagByte b)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return b._data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator short (TagByte b)
|
|
|
|
|
{
|
|
|
|
|
return b._data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator int (TagByte b)
|
|
|
|
|
{
|
|
|
|
|
return b._data;
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator long (TagByte b)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return b._data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagShort : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private short _data = 0;
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public short Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagShort () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagShort (short d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagShort(_data);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override string ToString ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return _data.ToString();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return s._data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagInt : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private int _data = 0;
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public int Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagInt () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagInt (int d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagInt(_data);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override string ToString ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return _data.ToString();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return i._data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagLong : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private long _data = 0;
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagLong ToTagLong () { return this; }
|
|
|
|
|
|
|
|
|
|
public override TagType GetTagType () { return TagType.TAG_LONG; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public long Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagLong () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagLong (long d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
|
|
|
|
{
|
|
|
|
|
return new TagLong(_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return _data.ToString();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator TagLong (byte b)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagLong(b);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return l._data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagFloat : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private float _data = 0;
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public float Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagFloat () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagFloat (float d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagFloat(_data);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override string ToString ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return _data.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator TagFloat (float f)
|
|
|
|
|
{
|
|
|
|
|
return new TagFloat(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator float (TagFloat f)
|
|
|
|
|
{
|
|
|
|
|
return f._data;
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator double (TagFloat f)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return f._data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagDouble : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private double _data = 0;
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagDouble ToTagDouble () { return this; }
|
|
|
|
|
|
|
|
|
|
public override TagType GetTagType () { return TagType.TAG_DOUBLE; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public double Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagDouble () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagDouble (double d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
|
|
|
|
{
|
|
|
|
|
return new TagDouble(_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString ()
|
|
|
|
|
{
|
|
|
|
|
return _data.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator TagDouble (float f)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagDouble(f);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator TagDouble (double d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagDouble(d);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator double (TagDouble d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return d._data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagByteArray : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private byte[] _data = null;
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagByteArray ToTagByteArray () { return this; }
|
|
|
|
|
|
|
|
|
|
public override TagType GetTagType () { return TagType.TAG_BYTE_ARRAY; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public byte[] Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Length
|
|
|
|
|
{
|
|
|
|
|
get { return _data.Length; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagByteArray () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagByteArray (byte[] d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
byte[] arr = new byte[_data.Length];
|
|
|
|
|
_data.CopyTo(arr, 0);
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagByteArray(arr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString ()
|
|
|
|
|
{
|
|
|
|
|
return _data.ToString();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte this [int index] {
|
|
|
|
|
get { return _data[index]; }
|
|
|
|
|
set { _data[index] = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator TagByteArray (byte[] b)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagByteArray(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator byte[] (TagByteArray b)
|
|
|
|
|
{
|
|
|
|
|
return b._data;
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagString : TagValue
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
private string _data = "";
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagString ToTagString () { return this; }
|
|
|
|
|
|
|
|
|
|
public override TagType GetTagType () { return TagType.TAG_STRING; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public string Data
|
|
|
|
|
{
|
|
|
|
|
get { return _data; }
|
|
|
|
|
set { _data = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Length
|
|
|
|
|
{
|
|
|
|
|
get { return _data.Length; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagString () { }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagString (string d)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_data = d;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return new TagString(_data);
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override string ToString ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
return _data.ToString();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public static implicit operator TagString (string s)
|
|
|
|
|
{
|
|
|
|
|
return new TagString(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator string (TagString s)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return s._data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagList : TagValue, IList<TagValue>
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
private TagType _type = TagType.TAG_END;
|
|
|
|
|
|
|
|
|
|
private List<TagValue> _items = null;
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagList ToTagList () { return this; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagType GetTagType () { return TagType.TAG_LIST; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
|
{
|
|
|
|
|
get { return _items.Count; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagType ValueType
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
get { return _type; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagList (TagType type)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_type = type;
|
2011-04-09 02:50:42 +00:00
|
|
|
|
_items = new List<TagValue>();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagList (TagType type, List<TagValue> items)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_type = type;
|
|
|
|
|
_items = items;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
TagList list = new TagList(_type);
|
|
|
|
|
foreach (TagValue item in _items) {
|
2011-04-06 04:43:54 +00:00
|
|
|
|
list.Add(item.Copy());
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public List<TagValue> FindAll(Predicate<TagValue> match)
|
2011-04-06 23:54:41 +00:00
|
|
|
|
{
|
|
|
|
|
return _items.FindAll(match);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public int RemoveAll (Predicate<TagValue> match)
|
2011-04-06 23:54:41 +00:00
|
|
|
|
{
|
|
|
|
|
return _items.RemoveAll(match);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override string ToString ()
|
|
|
|
|
{
|
|
|
|
|
return _items.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 04:43:54 +00:00
|
|
|
|
#region IList<NBT_Value> Members
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public int IndexOf (TagValue item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _items.IndexOf(item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public void Insert (int index, TagValue item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_items.Insert(index, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAt (int index)
|
|
|
|
|
{
|
|
|
|
|
_items.RemoveAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagValue this[int index]
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _items[index];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_items[index] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ICollection<NBT_Value> Members
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public void Add (TagValue item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear ()
|
|
|
|
|
{
|
|
|
|
|
_items.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public bool Contains (TagValue item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _items.Contains(item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public void CopyTo (TagValue[] array, int arrayIndex)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_items.CopyTo(array, arrayIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsReadOnly
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public bool Remove (TagValue item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _items.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEnumerable<NBT_Value> Members
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public IEnumerator<TagValue> GetEnumerator ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _items.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEnumerable Members
|
|
|
|
|
|
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
|
|
|
|
|
{
|
|
|
|
|
return _items.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public class TagCompound : TagValue, IDictionary<string, TagValue>
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
private Dictionary<string, TagValue> _tags;
|
|
|
|
|
|
|
|
|
|
public override TagCompound ToTagCompound () { return this; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagType GetTagType () { return TagType.TAG_COMPOUND; }
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
|
{
|
|
|
|
|
get { return _tags.Count; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagCompound ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
_tags = new Dictionary<string, TagValue>();
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override TagValue Copy ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
TagCompound list = new TagCompound();
|
|
|
|
|
foreach (KeyValuePair<string, TagValue> item in _tags) {
|
2011-04-06 04:43:54 +00:00
|
|
|
|
list[item.Key] = item.Value.Copy();
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public override string ToString ()
|
|
|
|
|
{
|
|
|
|
|
return _tags.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 04:43:54 +00:00
|
|
|
|
#region IDictionary<string,NBT_Value> Members
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public void Add (string key, TagValue value)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_tags.Add(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ContainsKey (string key)
|
|
|
|
|
{
|
|
|
|
|
return _tags.ContainsKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICollection<string> Keys
|
|
|
|
|
{
|
|
|
|
|
get { return _tags.Keys; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Remove (string key)
|
|
|
|
|
{
|
|
|
|
|
return _tags.Remove(key);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public bool TryGetValue (string key, out TagValue value)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _tags.TryGetValue(key, out value);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public ICollection<TagValue> Values
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
get { return _tags.Values; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public TagValue this[string key]
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _tags[key];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_tags[key] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ICollection<KeyValuePair<string,NBT_Value>> Members
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public void Add (KeyValuePair<string, TagValue> item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
_tags.Add(item.Key, item.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear ()
|
|
|
|
|
{
|
|
|
|
|
_tags.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public bool Contains (KeyValuePair<string, TagValue> item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-09 02:50:42 +00:00
|
|
|
|
TagValue value;
|
2011-04-06 04:43:54 +00:00
|
|
|
|
if (!_tags.TryGetValue(item.Key, out value)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return value == item.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public void CopyTo (KeyValuePair<string, TagValue>[] array, int arrayIndex)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (array == null) {
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
if (arrayIndex < 0) {
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
if (array.Length - arrayIndex < _tags.Count) {
|
|
|
|
|
throw new ArgumentException();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
foreach (KeyValuePair<string, TagValue> item in _tags) {
|
2011-04-06 04:43:54 +00:00
|
|
|
|
array[arrayIndex] = item;
|
|
|
|
|
arrayIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsReadOnly
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public bool Remove (KeyValuePair<string, TagValue> item)
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (Contains(item)) {
|
|
|
|
|
_tags.Remove(item.Key);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEnumerable<KeyValuePair<string,NBT_Value>> Members
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
public IEnumerator<KeyValuePair<string, TagValue>> GetEnumerator ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _tags.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEnumerable Members
|
|
|
|
|
|
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
|
|
|
|
|
{
|
|
|
|
|
return _tags.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|