2using System.Collections;
3using System.Collections.Generic;
16 private Dictionary<string, object>
dict =
new Dictionary<string, object>();
19 dict.TryGetValue(key, out tag);
25 $
"NBT Deserialization (type={typeof(T)}," +
26 $
"entry={TagPrinter.Print(new KeyValuePair<string, object>(key, tag))})", e);
31 public void Set(
string key,
object value) =>
Set(key, value,
false);
34 public void Set(
string key,
object value,
bool replace =
false) {
45 var valueInfo =
"value=" + value;
46 if (value.GetType().ToString() != value.ToString())
47 valueInfo =
"type=" + value.GetType() +
"," + valueInfo;
48 throw new IOException($
"NBT Serialization (key={key},{valueInfo})", e);
51 dict[key] = serialized;
53 dict.Add(key, serialized);
60 [Obsolete]
public void SetTag(
string key,
object value) =>
Set(key, value);
65 public byte GetByte(
string key) => Get<byte>(key);
66 public short GetShort(
string key) => Get<short>(key);
67 public int GetInt(
string key) => Get<int>(key);
68 public long GetLong(
string key) => Get<long>(key);
69 public float GetFloat(
string key) => Get<float>(key);
70 public double GetDouble(
string key) => Get<double>(key);
73 public string GetString(
string key) => Get<string>(key);
74 public IList<T>
GetList<T>(
string key) => Get<List<T>>(key);
76 public bool GetBool(
string key) => Get<bool>(key);
80 var o = Get<object>(key);
81 return o as
short? ?? o as
byte? ?? 0;
85 var o = Get<object>(key);
86 return o as
int? ?? o as
short? ?? o as
byte? ?? 0;
90 var o = Get<object>(key);
91 return o as
long? ?? o as
int? ?? o as
short? ?? o as
byte? ?? 0;
95 var o = Get<object>(key);
96 return o as
double? ?? o as
float? ?? 0;
101 foreach (var entry
in this)
102 copy.Set(entry.Key,
TagIO.Clone(entry.Value));
111 public object this[
string key] {
112 get {
return Get<object>(key); }
113 set {
Set(key, value,
true); }
117 public void Add(
string key,
object value) =>
Set(key, value);
118 public void Add(KeyValuePair<string, object> entry) =>
Set(entry.Key, entry.Value);
void Set(string key, object value)
void SetTag(string key, object value)
IList< T > GetList< T >(string key)
IEnumerator< KeyValuePair< string, object > > GetEnumerator()
short GetShort(string key)
T GetTag< T >(string key)
byte[] GetByteArray(string key)
bool RemoveTag(string key)
int[] GetIntArray(string key)
TagCompound GetCompound(string key)
long GetAsLong(string key)
void Set(string key, object value, bool replace=false)
double GetDouble(string key)
double GetAsDouble(string key)
IEnumerator IEnumerable. GetEnumerator()
void Add(KeyValuePair< string, object > entry)
string GetString(string key)
bool ContainsKey(string key)
Dictionary< string, object > dict
override string ToString()
float GetFloat(string key)
void Add(string key, object value)
short GetAsShort(string key)
static object Deserialize(Type type, object tag)
static object Serialize(object value)
static string Print(TagCompound tag)