001package net.minecraft.item;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.util.List;
006import net.minecraft.client.renderer.texture.IconRegister;
007import net.minecraft.entity.player.EntityPlayer;
008import net.minecraft.nbt.NBTBase;
009import net.minecraft.nbt.NBTTagCompound;
010import net.minecraft.nbt.NBTTagIntArray;
011import net.minecraft.util.Icon;
012import net.minecraft.util.StatCollector;
013
014public class ItemFireworkCharge extends Item
015{
016    @SideOnly(Side.CLIENT)
017    private Icon theIcon;
018
019    public ItemFireworkCharge(int par1)
020    {
021        super(par1);
022    }
023
024    @SideOnly(Side.CLIENT)
025
026    /**
027     * Gets an icon index based on an item's damage value and the given render pass
028     */
029    public Icon getIconFromDamageForRenderPass(int par1, int par2)
030    {
031        return par2 > 0 ? this.theIcon : super.getIconFromDamageForRenderPass(par1, par2);
032    }
033
034    @SideOnly(Side.CLIENT)
035    public int getColorFromItemStack(ItemStack par1ItemStack, int par2)
036    {
037        if (par2 != 1)
038        {
039            return super.getColorFromItemStack(par1ItemStack, par2);
040        }
041        else
042        {
043            NBTBase nbtbase = func_92108_a(par1ItemStack, "Colors");
044
045            if (nbtbase == null)
046            {
047                return 9079434;
048            }
049            else
050            {
051                NBTTagIntArray nbttagintarray = (NBTTagIntArray)nbtbase;
052
053                if (nbttagintarray.intArray.length == 1)
054                {
055                    return nbttagintarray.intArray[0];
056                }
057                else
058                {
059                    int j = 0;
060                    int k = 0;
061                    int l = 0;
062                    int[] aint = nbttagintarray.intArray;
063                    int i1 = aint.length;
064
065                    for (int j1 = 0; j1 < i1; ++j1)
066                    {
067                        int k1 = aint[j1];
068                        j += (k1 & 16711680) >> 16;
069                        k += (k1 & 65280) >> 8;
070                        l += (k1 & 255) >> 0;
071                    }
072
073                    j /= nbttagintarray.intArray.length;
074                    k /= nbttagintarray.intArray.length;
075                    l /= nbttagintarray.intArray.length;
076                    return j << 16 | k << 8 | l;
077                }
078            }
079        }
080    }
081
082    @SideOnly(Side.CLIENT)
083    public boolean requiresMultipleRenderPasses()
084    {
085        return true;
086    }
087
088    @SideOnly(Side.CLIENT)
089    public static NBTBase func_92108_a(ItemStack par0ItemStack, String par1Str)
090    {
091        if (par0ItemStack.hasTagCompound())
092        {
093            NBTTagCompound nbttagcompound = par0ItemStack.getTagCompound().getCompoundTag("Explosion");
094
095            if (nbttagcompound != null)
096            {
097                return nbttagcompound.getTag(par1Str);
098            }
099        }
100
101        return null;
102    }
103
104    @SideOnly(Side.CLIENT)
105
106    /**
107     * allows items to add custom lines of information to the mouseover description
108     */
109    public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
110    {
111        if (par1ItemStack.hasTagCompound())
112        {
113            NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound().getCompoundTag("Explosion");
114
115            if (nbttagcompound != null)
116            {
117                func_92107_a(nbttagcompound, par3List);
118            }
119        }
120    }
121
122    @SideOnly(Side.CLIENT)
123    public static void func_92107_a(NBTTagCompound par0NBTTagCompound, List par1List)
124    {
125        byte b0 = par0NBTTagCompound.getByte("Type");
126
127        if (b0 >= 0 && b0 <= 4)
128        {
129            par1List.add(StatCollector.translateToLocal("item.fireworksCharge.type." + b0).trim());
130        }
131        else
132        {
133            par1List.add(StatCollector.translateToLocal("item.fireworksCharge.type").trim());
134        }
135
136        int[] aint = par0NBTTagCompound.getIntArray("Colors");
137        int i;
138        int j;
139
140        if (aint.length > 0)
141        {
142            boolean flag = true;
143            String s = "";
144            int[] aint1 = aint;
145            int k = aint.length;
146
147            for (i = 0; i < k; ++i)
148            {
149                j = aint1[i];
150
151                if (!flag)
152                {
153                    s = s + ", ";
154                }
155
156                flag = false;
157                boolean flag1 = false;
158
159                for (int l = 0; l < 16; ++l)
160                {
161                    if (j == ItemDye.dyeColors[l])
162                    {
163                        flag1 = true;
164                        s = s + StatCollector.translateToLocal("item.fireworksCharge." + ItemDye.dyeColorNames[l]);
165                        break;
166                    }
167                }
168
169                if (!flag1)
170                {
171                    s = s + StatCollector.translateToLocal("item.fireworksCharge.customColor");
172                }
173            }
174
175            par1List.add(s);
176        }
177
178        int[] aint2 = par0NBTTagCompound.getIntArray("FadeColors");
179        boolean flag2;
180
181        if (aint2.length > 0)
182        {
183            flag2 = true;
184            String s1 = StatCollector.translateToLocal("item.fireworksCharge.fadeTo") + " ";
185            int[] aint3 = aint2;
186            i = aint2.length;
187
188            for (j = 0; j < i; ++j)
189            {
190                int i1 = aint3[j];
191
192                if (!flag2)
193                {
194                    s1 = s1 + ", ";
195                }
196
197                flag2 = false;
198                boolean flag3 = false;
199
200                for (int j1 = 0; j1 < 16; ++j1)
201                {
202                    if (i1 == ItemDye.dyeColors[j1])
203                    {
204                        flag3 = true;
205                        s1 = s1 + StatCollector.translateToLocal("item.fireworksCharge." + ItemDye.dyeColorNames[j1]);
206                        break;
207                    }
208                }
209
210                if (!flag3)
211                {
212                    s1 = s1 + StatCollector.translateToLocal("item.fireworksCharge.customColor");
213                }
214            }
215
216            par1List.add(s1);
217        }
218
219        flag2 = par0NBTTagCompound.getBoolean("Trail");
220
221        if (flag2)
222        {
223            par1List.add(StatCollector.translateToLocal("item.fireworksCharge.trail"));
224        }
225
226        boolean flag4 = par0NBTTagCompound.getBoolean("Flicker");
227
228        if (flag4)
229        {
230            par1List.add(StatCollector.translateToLocal("item.fireworksCharge.flicker"));
231        }
232    }
233
234    @SideOnly(Side.CLIENT)
235    public void registerIcons(IconRegister par1IconRegister)
236    {
237        super.registerIcons(par1IconRegister);
238        this.theIcon = par1IconRegister.registerIcon("fireworksCharge_overlay");
239    }
240}