public bool RenameTag(TagNode tag, string name)
        {
            if (_tag.ContainsKey(name))
            {
                return(false);
            }

            string oldName = GetTagName(tag);

            _tag.Remove(oldName);
            _tag.Add(name, tag);

            return(true);
        }
Esempio n. 2
0
        public TagNode BuildTree()
        {
            TagNodeCompound level     = _tree.Root["Level"] as TagNodeCompound;
            TagNodeCompound levelCopy = new TagNodeCompound();

            foreach (KeyValuePair <string, TagNode> node in level)
            {
                levelCopy.Add(node.Key, node.Value);
            }

            TagNodeList sections = new TagNodeList(TagType.TAG_COMPOUND);

            for (int i = 0; i < _sections.Length; i++)
            {
                if (ShouldIncludeSection(_sections[i]))
                {
                    sections.Add(_sections[i].BuildTree());
                }
            }

            levelCopy["Sections"] = sections;

            if (_tileTicks.Count == 0)
            {
                levelCopy.Remove("TileTicks");
            }

            return(levelCopy);
        }
Esempio n. 3
0
        public TagNode BuildTree()
        {
            TagNodeCompound copy = new TagNodeCompound();

            foreach (KeyValuePair <string, TagNode> node in _tree)
            {
                copy.Add(node.Key, node.Value);
            }

            if (CheckAddBlocksEmpty())
            {
                copy.Remove("AddBlocks");
            }

            return(copy);
        }
Esempio n. 4
0
        /// <summary>
        /// Builds a Player subtree from the current data.
        /// </summary>
        /// <returns>The root node of a Player subtree representing the current data.</returns>
        public virtual new TagNode BuildTree()
        {
            TagNodeCompound tree = base.BuildTree() as TagNodeCompound;

            tree["AttackTime"] = new TagNodeShort(_attackTime);
            tree["DeathTime"]  = new TagNodeShort(_deathTime);
            tree["Health"]     = new TagNodeShort(_health);
            tree["HurtTime"]   = new TagNodeShort(_hurtTime);

            tree["Dimension"]  = new TagNodeInt(_dimension);
            tree["Sleeping"]   = new TagNodeByte(_sleeping);
            tree["SleepTimer"] = new TagNodeShort(_sleepTimer);

            if (_spawnX != null && _spawnY != null && _spawnZ != null)
            {
                tree["SpawnX"] = new TagNodeInt(_spawnX ?? 0);
                tree["SpawnY"] = new TagNodeInt(_spawnY ?? 0);
                tree["SpawnZ"] = new TagNodeInt(_spawnZ ?? 0);
            }
            else
            {
                tree.Remove("SpawnX");
                tree.Remove("SpawnY");
                tree.Remove("SpawnZ");
            }

            if (_world != null)
            {
                tree["World"] = new TagNodeString(_world);
            }

            if (_foodLevel != null)
            {
                tree["foodLevel"] = new TagNodeInt(_foodLevel ?? 0);
            }
            if (_foodTickTimer != null)
            {
                tree["foodTickTimer"] = new TagNodeInt(_foodTickTimer ?? 0);
            }
            if (_foodExhaustion != null)
            {
                tree["foodExhaustionLevel"] = new TagNodeFloat(_foodExhaustion ?? 0);
            }
            if (_foodSaturation != null)
            {
                tree["foodSaturation"] = new TagNodeFloat(_foodSaturation ?? 0);
            }
            if (_xpP != null)
            {
                tree["XpP"] = new TagNodeFloat(_xpP ?? 0);
            }
            if (_xpLevel != null)
            {
                tree["XpLevel"] = new TagNodeInt(_xpLevel ?? 0);
            }
            if (_xpTotal != null)
            {
                tree["XpTotal"] = new TagNodeInt(_xpTotal ?? 0);
            }
            if (_score != null)
            {
                tree["Score"] = new TagNodeInt(_score ?? 0);
            }

            if (_gameType != null)
            {
                tree["PlayerGameType"] = new TagNodeInt((int)(_gameType ?? PlayerGameType.Survival));
            }

            if (AbilitiesSet())
            {
                TagNodeCompound pb = new TagNodeCompound();
                pb["flying"]       = new TagNodeByte(_abilities.Flying ? (byte)1 : (byte)0);
                pb["instabuild"]   = new TagNodeByte(_abilities.InstantBuild ? (byte)1 : (byte)0);
                pb["mayfly"]       = new TagNodeByte(_abilities.MayFly ? (byte)1 : (byte)0);
                pb["invulnerable"] = new TagNodeByte(_abilities.Invulnerable ? (byte)1 : (byte)0);
                pb["mayBuild"]     = new TagNodeByte(_abilities.MayBuild ? (byte)1 : (byte)0);
                pb["walkSpeed"]    = new TagNodeFloat(_abilities.WalkSpeed);
                pb["flySpeed"]     = new TagNodeFloat(_abilities.FlySpeed);

                tree["abilities"] = pb;
            }

            tree["Inventory"]  = _inventory.BuildTree();
            tree["EnderItems"] = _enderItems.BuildTree();

            return(tree);
        }
Esempio n. 5
0
        private static bool FixSpawnData(TagNodeCompound spawnData)
        {
            if (!spawnData.ContainsKey("potionValue") && !spawnData.ContainsKey("Potion"))
            {
                return(false);
            }
            int damage = 0;

            spawnData["id"] = new TagNodeString("minecraft:potion");
            if (spawnData.ContainsKey("potionValue"))
            {
                damage = spawnData["potionValue"].ToTagInt();
                spawnData.Remove("potionValue");
            }
            if (!spawnData.ContainsKey("Potion"))
            {
                spawnData["Potion"] = new TagNodeCompound();
            }
            TagNodeCompound potion = spawnData["Potion"].ToTagCompound();

            if (!potion.ContainsKey("tag"))
            {
                potion["tag"] = new TagNodeCompound();
            }
            TagNodeCompound tag = potion["tag"].ToTagCompound();

            if (!potion.ContainsKey("Count"))
            {
                potion["Count"] = new TagNodeByte(1);
            }
            if (potion.ContainsKey("Damage"))
            {
                if (damage == 0)
                {
                    damage = potion["Damage"].ToTagInt();
                }
                potion.Remove("Damage");
            }
            potion["id"] = new TagNodeString(ItemInfo.SplashPotion.NameID);
            if (damage != 0)
            {
                string potionEffect = PotionEffects[damage & 15];
                string potionPrefix = "";
                if ((damage & 32) == 32)
                {
                    potionPrefix = "strong_";
                }
                else if ((damage & 64) == 64)
                {
                    potionPrefix = "long_";
                }
                if (potionPrefix == "strong_" && (potionEffect == "fire_resistance" || potionEffect == "night_vision" || potionEffect == "weakness" || potionEffect == "slowness" || potionEffect == "water_breating" || potionEffect == "invisibility"))
                {
                    tag["Potion"] = new TagNodeString("minecraft:" + potionEffect);
                }
                else if (potionPrefix == "long_" && (potionEffect == "healing" || potionEffect == "harming"))
                {
                    tag["Potion"] = new TagNodeString("minecraft:" + potionEffect);
                }
                else
                {
                    tag["Potion"] = new TagNodeString("minecraft:" + potionPrefix + potionEffect);
                }
            }
            return(true);
        }