예제 #1
0
        /// <summary>
        /// Removes all entities matching the given id (type) from the collection.
        /// </summary>
        /// <param name="id">The id (type) of entities that should be removed.</param>
        /// <returns>A count of the number of entities that were removed.</returns>
        public int RemoveAll(string id)
        {
            int rem = _entities.RemoveAll(val =>
            {
                TagNodeCompound cval = val as TagNodeCompound;
                if (cval == null)
                {
                    return(false);
                }

                TagNode sval;
                if (!cval.TryGetValue("id", out sval))
                {
                    return(false);
                }

                return(sval.ToTagString().Data == id);
            });

            if (rem > 0)
            {
                _dirty = true;
            }

            return(rem);
        }
예제 #2
0
 public TagNode GetTagNode(string name)
 {
     if (_tag.TryGetValue(name, out TagNode tag))
     {
         return(tag);
     }
     return(null);
 }
        /// <summary>
        /// Creates a new instance of a nonspecific <see cref="TypedEntity"/> object by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field.</param>
        /// <returns>A new instance of a <see cref="TypedEntity"/> object, or null if the entity is not typed.</returns>
        public static TypedEntity CreateGeneric (TagNodeCompound tree)
        {
            TagNode type;
            if (!tree.TryGetValue("id", out type)) {
                return null;
            }

            TypedEntity te = new TypedEntity(type.ToTagString().Data);

            return te.LoadTreeSafe(tree);
        }
예제 #4
0
        /// <summary>
        /// Creates a new instance of a nonspecific <see cref="TypedEntity"/> object by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field.</param>
        /// <returns>A new instance of a <see cref="TypedEntity"/> object, or null if the entity is not typed.</returns>
        public static TypedEntity CreateGeneric(TagNodeCompound tree)
        {
            TagNode type;

            if (!tree.TryGetValue("id", out type))
            {
                return(null);
            }

            TypedEntity te = new TypedEntity(type.ToTagString().Data);

            return(te.LoadTreeSafe(tree));
        }
예제 #5
0
        public override TileEntity LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

            if (ctree == null || base.LoadTree(tree) == null)
            {
                return(null);
            }

            TagNode node;

            if (ctree.TryGetValue("CustomName", out node))
            {
                CustomName = node.ToTagString();
            }
            BaseColor = (BannerColor)(int)ctree["Base"].ToTagInt();
            if (ctree.TryGetValue("Patterns", out node))
            {
                var items = node.ToTagList();
                List <BannerPattern> patterns = new List <BannerPattern>();
                foreach (var item in items)
                {
                    patterns.Add(
                        new BannerPattern(
                            (BannerColor)(int)(item.ToTagCompound()["Color"].ToTagInt()),
                            item.ToTagCompound()["Pattern"].ToTagString()
                            )
                        );
                }
                Patterns = patterns.ToArray();
            }
            else
            {
                Patterns = new BannerPattern[0];
            }

            return(this);
        }
        /// <summary>
        /// Create a new instance of a concrete <see cref="TypedEntity"/> type by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field of the Entity's registered name.</param>
        /// <returns>A new instance of a concrete <see cref="TypedEntity"/> type, or null if no type was registered with the given name.</returns>
        public static TypedEntity Create (TagNodeCompound tree)
        {
            TagNode type;
            if (!tree.TryGetValue("id", out type)) {
                return null;
            }

            Type t;
            if (!_registry.TryGetValue(type.ToTagString(), out t)) {
                return null;
            }

            TypedEntity te = Activator.CreateInstance(t) as TypedEntity;

            return te.LoadTreeSafe(tree);
        }
예제 #7
0
        /// <summary>
        /// Create a new instance of a concrete <see cref="EntityTyped"/> type by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field of the Entity's registered name.</param>
        /// <returns>A new instance of a concrete <see cref="EntityTyped"/> type, or null if no type was registered with the given name.</returns>
        public static EntityTyped Create(TagNodeCompound tree)
        {
            TagNode type;

            if (!tree.TryGetValue("id", out type))
            {
                return(null);
            }

            Type t;

            if (!_registry.TryGetValue(type.ToTagString(), out t))
            {
                return(null);
            }

            EntityTyped te = Activator.CreateInstance(t) as EntityTyped;

            return(te.LoadTreeSafe(tree));
        }