예제 #1
0
        public ReadResults Parse(out Item result)
        {
            result = default;

            ReadResults readResults = ReadTag(out bool isTag);

            if (!readResults.Successful)
            {
                return(readResults);
            }

            readResults = ResourceLocation.TryRead(StringReader, out ResourceLocation item);
            if (!readResults.Successful)
            {
                return(readResults);
            }

            // Temporary
            if (UseBedrock)
            {
                result = new Item(item, null, isTag);
                return(ReadResults.Success());
            }

            if (!isTag && !Resources.Items.Contains(item))
            {
                return(ReadResults.Failure(CommandError.UnknownItem(item)));
            }

            if (StringReader.CanRead() && StringReader.Peek() == '{')
            {
                readResults = new NbtParser(StringReader).ReadCompound(out INbtTag nbt);
                if (readResults.Successful)
                {
                    result = new Item(item, nbt, isTag);
                }
                return(readResults);
            }

            result = new Item(item, null, isTag);
            return(ReadResults.Success());
        }