001package net.minecraft.nbt; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.io.DataInput; 006import java.io.DataOutput; 007import java.io.IOException; 008import java.util.ArrayList; 009import java.util.Iterator; 010import java.util.List; 011 012public 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 i = 0; i < this.tagList.size(); ++i) 050 { 051 ((NBTBase)this.tagList.get(i)).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 i = par1DataInput.readInt(); 062 this.tagList = new ArrayList(); 063 064 for (int j = 0; j < i; ++j) 065 { 066 NBTBase nbtbase = NBTBase.newTag(this.tagType, (String)null); 067 nbtbase.load(par1DataInput); 068 this.tagList.add(nbtbase); 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 nbttaglist = new NBTTagList(this.getName()); 127 nbttaglist.tagType = this.tagType; 128 Iterator iterator = this.tagList.iterator(); 129 130 while (iterator.hasNext()) 131 { 132 NBTBase nbtbase = (NBTBase)iterator.next(); 133 NBTBase nbtbase1 = nbtbase.copy(); 134 nbttaglist.tagList.add(nbtbase1); 135 } 136 137 return nbttaglist; 138 } 139 140 public boolean equals(Object par1Obj) 141 { 142 if (super.equals(par1Obj)) 143 { 144 NBTTagList nbttaglist = (NBTTagList)par1Obj; 145 146 if (this.tagType == nbttaglist.tagType) 147 { 148 return this.tagList.equals(nbttaglist.tagList); 149 } 150 } 151 152 return false; 153 } 154 155 public int hashCode() 156 { 157 return super.hashCode() ^ this.tagList.hashCode(); 158 } 159}