    001    package net.minecraft.nbt;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.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
    049            for (int var2 = 0; var2 < this.tagList.size(); ++var2)
    050            {
    051                ((NBTBase)this.tagList.get(var2)).write(par1DataOutput);
    052            }
    053        }
    054
    055        /**
    056         * Read the actual data contents of the tag, implemented in NBT extension classes
    057         */
    058        void load(DataInput par1DataInput) throws IOException
    059        {
    060            this.tagType = par1DataInput.readByte();
    061            int var2 = par1DataInput.readInt();
    062            this.tagList = new ArrayList();
    063
    064            for (int var3 = 0; var3 < var2; ++var3)
    065            {
    066                NBTBase var4 = NBTBase.newTag(this.tagType, (String)null);
    067                var4.load(par1DataInput);
    068                this.tagList.add(var4);
    069            }
    070        }
    071
    072        /**
    073         * Gets the type byte for the tag.
    074         */
    075        public byte getId()
    076        {
    077            return (byte)9;
    078        }
    079
    080        public String toString()
    081        {
    082            return "" + this.tagList.size() + " entries of type " + NBTBase.getTagName(this.tagType);
    083        }
    084
    085        /**
    086         * 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
    087         * previous tag.
    088         */
    089        public void appendTag(NBTBase par1NBTBase)
    090        {
    091            this.tagType = par1NBTBase.getId();
    092            this.tagList.add(par1NBTBase);
    093        }
    094
    095        @SideOnly(Side.CLIENT)
    096
    097        /**
    098         * Removes a tag at the given index.
    099         */
    100        public NBTBase removeTag(int par1)
    101        {
    102            return (NBTBase)this.tagList.remove(par1);
    103        }
    104
    105        /**
    106         * Retrieves the tag at the specified index from the list.
    107         */
    108        public NBTBase tagAt(int par1)
    109        {
    110            return (NBTBase)this.tagList.get(par1);
    111        }
    112
    113        /**
    114         * Returns the number of tags in the list.
    115         */
    116        public int tagCount()
    117        {
    118            return this.tagList.size();
    119        }
    120
    121        /**
    122         * Creates a clone of the tag.
    123         */
    124        public NBTBase copy()
    125        {
    126            NBTTagList var1 = new NBTTagList(this.getName());
    127            var1.tagType = this.tagType;
    128            Iterator var2 = this.tagList.iterator();
    129
    130            while (var2.hasNext())
    131            {
    132                NBTBase var3 = (NBTBase)var2.next();
    133                NBTBase var4 = var3.copy();
    134                var1.tagList.add(var4);
    135            }
    136
    137            return var1;
    138        }
    139
    140        public boolean equals(Object par1Obj)
    141        {
    142            if (super.equals(par1Obj))
    143            {
    144                NBTTagList var2 = (NBTTagList)par1Obj;
    145
    146                if (this.tagType == var2.tagType)
    147                {
    148                    return this.tagList.equals(var2.tagList);
    149                }
    150            }
    151
    152            return false;
    153        }
    154
    155        public int hashCode()
    156        {
    157            return super.hashCode() ^ this.tagList.hashCode();
    158        }
    159    }