001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import java.io.DataInput;
006    import java.io.DataOutput;
007    import java.io.IOException;
008    import java.util.ArrayList;
009    import java.util.Iterator;
010    import java.util.List;
011    
012    public class NBTTagList extends NBTBase
013    {
014        /** The array list containing the tags encapsulated in this list. */
015        private List tagList = new ArrayList();
016    
017        /**
018         * The type byte for the tags in the list - they must all be of the same type.
019         */
020        private byte tagType;
021    
022        public NBTTagList()
023        {
024            super("");
025        }
026    
027        public NBTTagList(String par1Str)
028        {
029            super(par1Str);
030        }
031    
032        /**
033         * Write the actual data contents of the tag, implemented in NBT extension classes
034         */
035        void write(DataOutput par1DataOutput) throws IOException
036        {
037            if (!this.tagList.isEmpty())
038            {
039                this.tagType = ((NBTBase)this.tagList.get(0)).getId();
040            }
041            else
042            {
043                this.tagType = 1;
044            }
045    
046            par1DataOutput.writeByte(this.tagType);
047            par1DataOutput.writeInt(this.tagList.size());
048            Iterator var2 = this.tagList.iterator();
049    
050            while (var2.hasNext())
051            {
052                NBTBase var3 = (NBTBase)var2.next();
053                var3.write(par1DataOutput);
054            }
055        }
056    
057        /**
058         * Read the actual data contents of the tag, implemented in NBT extension classes
059         */
060        void load(DataInput par1DataInput) throws IOException
061        {
062            this.tagType = par1DataInput.readByte();
063            int var2 = par1DataInput.readInt();
064            this.tagList = new ArrayList();
065    
066            for (int var3 = 0; var3 < var2; ++var3)
067            {
068                NBTBase var4 = NBTBase.newTag(this.tagType, (String)null);
069                var4.load(par1DataInput);
070                this.tagList.add(var4);
071            }
072        }
073    
074        /**
075         * Gets the type byte for the tag.
076         */
077        public byte getId()
078        {
079            return (byte)9;
080        }
081    
082        public String toString()
083        {
084            return "" + this.tagList.size() + " entries of type " + NBTBase.getTagName(this.tagType);
085        }
086    
087        /**
088         * Adds the provided tag to the end of the list. There is no check to verify this tag is of the same type as any
089         * previous tag.
090         */
091        public void appendTag(NBTBase par1NBTBase)
092        {
093            this.tagType = par1NBTBase.getId();
094            this.tagList.add(par1NBTBase);
095        }
096    
097        @SideOnly(Side.CLIENT)
098    
099        /**
100         * Removes a tag at the given index.
101         */
102        public NBTBase removeTag(int par1)
103        {
104            return (NBTBase)this.tagList.remove(par1);
105        }
106    
107        /**
108         * Retrieves the tag at the specified index from the list.
109         */
110        public NBTBase tagAt(int par1)
111        {
112            return (NBTBase)this.tagList.get(par1);
113        }
114    
115        /**
116         * Returns the number of tags in the list.
117         */
118        public int tagCount()
119        {
120            return this.tagList.size();
121        }
122    
123        /**
124         * Creates a clone of the tag.
125         */
126        public NBTBase copy()
127        {
128            NBTTagList var1 = new NBTTagList(this.getName());
129            var1.tagType = this.tagType;
130            Iterator var2 = this.tagList.iterator();
131    
132            while (var2.hasNext())
133            {
134                NBTBase var3 = (NBTBase)var2.next();
135                NBTBase var4 = var3.copy();
136                var1.tagList.add(var4);
137            }
138    
139            return var1;
140        }
141    
142        public boolean equals(Object par1Obj)
143        {
144            if (super.equals(par1Obj))
145            {
146                NBTTagList var2 = (NBTTagList)par1Obj;
147    
148                if (this.tagType == var2.tagType)
149                {
150                    return this.tagList.equals(var2.tagList);
151                }
152            }
153    
154            return false;
155        }
156    
157        public int hashCode()
158        {
159            return super.hashCode() ^ this.tagList.hashCode();
160        }
161    }