Example #1
0
 public static List <T> ToFrameworkList <T>(this NbtList list, INbtIoConfig config = null) where T : INbtIoCapable, new()
 {
     return(new List <T>(list.OfType <NbtCompound>().Select(c => CreateAndReadFromNbt <T>(c, config))));
 }
Example #2
0
 private static List <NamespacedBlock> ToNamespacedBlockList(NbtList list)
 {
     return(new List <NamespacedBlock>(list.OfType <NbtCompound>()
                                       .Select(c => NamespacedBlock.CreateFromNbt(c, IgnoreBlockProperty))));
 }
Example #3
0
        private static object CreateListFromNbt(NbtList list, NbtEntryType entryType)
        {
            switch (entryType.NestedType.Type)
            {
            case NbtTagType.Byte:
                if (entryType.NestedType.FwType == typeof(bool))
                {
                    return(new List <bool>(list.OfType <NbtByte>().Select(x => x.Value == 1)));
                }
                else
                {
                    return(new List <byte>(list.OfType <NbtByte>().Select(x => x.Value)));
                }

            case NbtTagType.Short:
                return(new List <short>(list.OfType <NbtShort>().Select(x => x.Value)));

            case NbtTagType.Int:
                return(new List <int>(list.OfType <NbtInt>().Select(x => x.Value)));

            case NbtTagType.Long:
                return(new List <long>(list.OfType <NbtLong>().Select(x => x.Value)));

            case NbtTagType.Float:
                return(new List <float>(list.OfType <NbtFloat>().Select(x => x.Value)));

            case NbtTagType.Double:
                return(new List <double>(list.OfType <NbtDouble>().Select(x => x.Value)));

            case NbtTagType.ByteArray:
                return(new List <byte[]>(list.OfType <NbtByteArray>().Select(x => x.Value)));

            case NbtTagType.String:
                return(new List <string>(list.OfType <NbtString>().Select(x => x.Value)));

            case NbtTagType.IntArray:
                return(new List <int[]>(list.OfType <NbtIntArray>().Select(x => x.Value)));

            case NbtTagType.LongArray:
                return(new List <long[]>(list.OfType <NbtLongArray>().Select(x => x.Value)));

            case NbtTagType.List:
            case NbtTagType.Compound:
                var inst = (IList)Activator.CreateInstance(entryType.FwType);
                foreach (var it in list.Select(t => CreateValueFromNbtTag(t, entryType.NestedType)))
                {
                    inst.Add(it);
                }
                return(inst);

            default:
                throw new NotSupportedException();
            }
        }