コード例 #1
0
ファイル: NBTTab.cs プロジェクト: thebigsmileXD/WorldObserver
        private void SetTag(List <int> indexes, NbtTag oldTag, NbtTag newTag)
        {
            NbtCompound _copyTag = new NbtCompound(_nbtFile.RootTag);
            NbtTag      current  = oldTag;

            try
            {
                while (current != null)
                {
                    Debug.WriteLine("Current");
                    Debug.WriteLine(current.TagType);
                    NbtTag parent = current.Parent;

                    if (parent != null)
                    {
                        ///////////////
                        if (current.Equals(oldTag) || parent is NbtByteArray || parent is NbtIntArray)
                        {
                            Debug.WriteLine("Equals");
                            switch (parent.TagType)
                            {
                            case NbtTagType.Compound:
                            {
                                ((NbtCompound)parent).Remove(oldTag);
                                ((NbtCompound)parent).Add(newTag);
                                break;
                            }

                            case NbtTagType.List:                 //TODO NOT GETTING CHANGED/SAVED!!!!!!
                            {
                                ((NbtList)parent).Remove(oldTag); //? unnamed?
                                ((NbtList)parent).Add(newTag);
                                break;
                            }

                            case NbtTagType.ByteArray:
                            {
                                //((NbtByteArray)current).Remove(oldTag);
                                //((NbtByteArray)current).Add(newTag);
                                byte[] val = ((NbtByteArray)current).ByteArrayValue;
                                Debug.WriteLine(((NbtByte)current).Name);
                                break;
                            }

                            case NbtTagType.IntArray:
                            {
                                //((NbtIntArray)current).Remove(oldTag);
                                //((NbtIntArray)current).Add(newTag);
                                break;
                            }
                            }
                        }
                        ///////////////
                        Debug.WriteLine("Parent?");
                        Debug.WriteLine(parent.TagType);
                    }
                    else if (current is NbtCompound)
                    {
                        _copyTag = new NbtCompound((NbtCompound)current);
                    }
                    current = parent;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                Debug.WriteLine(current);
            }
            _nbtFile.RootTag = new NbtCompound(_copyTag);
        }