internal static ListTag ListTagDeserialize(JArray json, string key = "") { ListTag tag = new ListTag(key, NBTTagType.BYTE); foreach (JToken token in json) { if (token is JValue) { JValue value = (JValue)token; object t = value.Value; if (t is byte) { tag.ListTagType = NBTTagType.BYTE; tag.Add(new ByteTag((byte)t)); } else if (t is double) { tag.ListTagType = NBTTagType.DOUBLE; tag.Add(new DoubleTag((double)t)); } else if (t is float) { tag.ListTagType = NBTTagType.FLOAT; tag.Add(new FloatTag((float)t)); } else if (t is int) { tag.ListTagType = NBTTagType.INT; tag.Add(new IntTag((int)t)); } else if (t is long) { tag.ListTagType = NBTTagType.LONG; tag.Add(new LongTag((long)t)); } else if (t is short) { tag.ListTagType = NBTTagType.SHORT; tag.Add(new ShortTag((short)t)); } else if (t is string) { tag.ListTagType = NBTTagType.STRING; tag.Add(new StringTag((string)t)); } } else if (token is JObject) { tag.Add(NBTJsonSerializer.CompoundTagDeserialize((JObject)token)); } else { tag.Add(NBTJsonSerializer.ListTagDeserialize((JArray)token)); } } return(tag); }
internal static CompoundTag CompoundTagDeserialize(JObject json) { CompoundTag tag = new CompoundTag(); foreach (KeyValuePair <string, JToken> kv in json) { JToken token = kv.Value; if (token is JValue) { JValue value = (JValue)token; object t = value.Value; if (t is byte) { tag.PutByte(kv.Key, (byte)t); } else if (t is double) { tag.PutDouble(kv.Key, (double)t); } else if (t is float) { tag.PutFloat(kv.Key, (float)t); } else if (t is int) { tag.PutInt(kv.Key, (int)t); } else if (t is long) { tag.PutLong(kv.Key, (long)t); } else if (t is short) { tag.PutShort(kv.Key, (short)t); } else if (t is string) { tag.PutString(kv.Key, (string)t); } } else if (token is JObject) { tag.PutCompound(kv.Key, NBTJsonSerializer.CompoundTagDeserialize((JObject)token)); } else { tag.PutList(NBTJsonSerializer.ListTagDeserialize((JArray)token, kv.Key)); } } return(tag); }