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 public NBTBase func_74744_a(int par1) 099 { 100 return (NBTBase)this.tagList.remove(par1); 101 } 102 103 /** 104 * Retrieves the tag at the specified index from the list. 105 */ 106 public NBTBase tagAt(int par1) 107 { 108 return (NBTBase)this.tagList.get(par1); 109 } 110 111 /** 112 * Returns the number of tags in the list. 113 */ 114 public int tagCount() 115 { 116 return this.tagList.size(); 117 } 118 119 /** 120 * Creates a clone of the tag. 121 */ 122 public NBTBase copy() 123 { 124 NBTTagList var1 = new NBTTagList(this.getName()); 125 var1.tagType = this.tagType; 126 Iterator var2 = this.tagList.iterator(); 127 128 while (var2.hasNext()) 129 { 130 NBTBase var3 = (NBTBase)var2.next(); 131 NBTBase var4 = var3.copy(); 132 var1.tagList.add(var4); 133 } 134 135 return var1; 136 } 137 138 public boolean equals(Object par1Obj) 139 { 140 if (super.equals(par1Obj)) 141 { 142 NBTTagList var2 = (NBTTagList)par1Obj; 143 144 if (this.tagType == var2.tagType) 145 { 146 return this.tagList.equals(var2.tagList); 147 } 148 } 149 150 return false; 151 } 152 153 public int hashCode() 154 { 155 return super.hashCode() ^ this.tagList.hashCode(); 156 } 157 }