001package net.minecraft.item.crafting;
002
003import java.util.ArrayList;
004import net.minecraft.inventory.InventoryCrafting;
005import net.minecraft.item.Item;
006import net.minecraft.item.ItemDye;
007import net.minecraft.item.ItemStack;
008import net.minecraft.nbt.NBTTagCompound;
009import net.minecraft.nbt.NBTTagList;
010import net.minecraft.world.World;
011
012public class RecipeFireworks implements IRecipe
013{
014    private ItemStack field_92102_a;
015
016    /**
017     * Used to check if a recipe matches current crafting inventory
018     */
019    public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
020    {
021        this.field_92102_a = null;
022        int var3 = 0;
023        int var4 = 0;
024        int var5 = 0;
025        int var6 = 0;
026        int var7 = 0;
027        int var8 = 0;
028
029        for (int var9 = 0; var9 < par1InventoryCrafting.getSizeInventory(); ++var9)
030        {
031            ItemStack var10 = par1InventoryCrafting.getStackInSlot(var9);
032
033            if (var10 != null)
034            {
035                if (var10.itemID == Item.gunpowder.itemID)
036                {
037                    ++var4;
038                }
039                else if (var10.itemID == Item.fireworkCharge.itemID)
040                {
041                    ++var6;
042                }
043                else if (var10.itemID == Item.dyePowder.itemID)
044                {
045                    ++var5;
046                }
047                else if (var10.itemID == Item.paper.itemID)
048                {
049                    ++var3;
050                }
051                else if (var10.itemID == Item.lightStoneDust.itemID)
052                {
053                    ++var7;
054                }
055                else if (var10.itemID == Item.diamond.itemID)
056                {
057                    ++var7;
058                }
059                else if (var10.itemID == Item.fireballCharge.itemID)
060                {
061                    ++var8;
062                }
063                else if (var10.itemID == Item.feather.itemID)
064                {
065                    ++var8;
066                }
067                else if (var10.itemID == Item.goldNugget.itemID)
068                {
069                    ++var8;
070                }
071                else
072                {
073                    if (var10.itemID != Item.skull.itemID)
074                    {
075                        return false;
076                    }
077
078                    ++var8;
079                }
080            }
081        }
082
083        var7 += var5 + var8;
084
085        if (var4 <= 3 && var3 <= 1)
086        {
087            NBTTagCompound var15;
088            NBTTagCompound var18;
089
090            if (var4 >= 1 && var3 == 1 && var7 == 0)
091            {
092                this.field_92102_a = new ItemStack(Item.firework);
093
094                var15 = new NBTTagCompound();
095                if (var6 > 0)
096                {
097                    var18 = new NBTTagCompound("Fireworks");
098                    NBTTagList var25 = new NBTTagList("Explosions");
099
100                    for (int var22 = 0; var22 < par1InventoryCrafting.getSizeInventory(); ++var22)
101                    {
102                        ItemStack var26 = par1InventoryCrafting.getStackInSlot(var22);
103
104                        if (var26 != null && var26.itemID == Item.fireworkCharge.itemID && var26.hasTagCompound() && var26.getTagCompound().hasKey("Explosion"))
105                        {
106                            var25.appendTag(var26.getTagCompound().getCompoundTag("Explosion"));
107                        }
108                    }
109
110                    var18.setTag("Explosions", var25);
111                    var18.setByte("Flight", (byte)var4);
112                    var15.setTag("Fireworks", var18);
113                }
114
115                this.field_92102_a.setTagCompound(var15);
116                return true;
117            }
118            else if (var4 == 1 && var3 == 0 && var6 == 0 && var5 > 0 && var8 <= 1)
119            {
120                this.field_92102_a = new ItemStack(Item.fireworkCharge);
121                var15 = new NBTTagCompound();
122                var18 = new NBTTagCompound("Explosion");
123                byte var21 = 0;
124                ArrayList var12 = new ArrayList();
125
126                for (int var13 = 0; var13 < par1InventoryCrafting.getSizeInventory(); ++var13)
127                {
128                    ItemStack var14 = par1InventoryCrafting.getStackInSlot(var13);
129
130                    if (var14 != null)
131                    {
132                        if (var14.itemID == Item.dyePowder.itemID)
133                        {
134                            var12.add(Integer.valueOf(ItemDye.dyeColors[var14.getItemDamage()]));
135                        }
136                        else if (var14.itemID == Item.lightStoneDust.itemID)
137                        {
138                            var18.setBoolean("Flicker", true);
139                        }
140                        else if (var14.itemID == Item.diamond.itemID)
141                        {
142                            var18.setBoolean("Trail", true);
143                        }
144                        else if (var14.itemID == Item.fireballCharge.itemID)
145                        {
146                            var21 = 1;
147                        }
148                        else if (var14.itemID == Item.feather.itemID)
149                        {
150                            var21 = 4;
151                        }
152                        else if (var14.itemID == Item.goldNugget.itemID)
153                        {
154                            var21 = 2;
155                        }
156                        else if (var14.itemID == Item.skull.itemID)
157                        {
158                            var21 = 3;
159                        }
160                    }
161                }
162
163                int[] var24 = new int[var12.size()];
164
165                for (int var27 = 0; var27 < var24.length; ++var27)
166                {
167                    var24[var27] = ((Integer)var12.get(var27)).intValue();
168                }
169
170                var18.setIntArray("Colors", var24);
171                var18.setByte("Type", var21);
172                var15.setTag("Explosion", var18);
173                this.field_92102_a.setTagCompound(var15);
174                return true;
175            }
176            else if (var4 == 0 && var3 == 0 && var6 == 1 && var5 > 0 && var5 == var7)
177            {
178                ArrayList var16 = new ArrayList();
179
180                for (int var20 = 0; var20 < par1InventoryCrafting.getSizeInventory(); ++var20)
181                {
182                    ItemStack var11 = par1InventoryCrafting.getStackInSlot(var20);
183
184                    if (var11 != null)
185                    {
186                        if (var11.itemID == Item.dyePowder.itemID)
187                        {
188                            var16.add(Integer.valueOf(ItemDye.dyeColors[var11.getItemDamage()]));
189                        }
190                        else if (var11.itemID == Item.fireworkCharge.itemID)
191                        {
192                            this.field_92102_a = var11.copy();
193                            this.field_92102_a.stackSize = 1;
194                        }
195                    }
196                }
197
198                int[] var17 = new int[var16.size()];
199
200                for (int var19 = 0; var19 < var17.length; ++var19)
201                {
202                    var17[var19] = ((Integer)var16.get(var19)).intValue();
203                }
204
205                if (this.field_92102_a != null && this.field_92102_a.hasTagCompound())
206                {
207                    NBTTagCompound var23 = this.field_92102_a.getTagCompound().getCompoundTag("Explosion");
208
209                    if (var23 == null)
210                    {
211                        return false;
212                    }
213                    else
214                    {
215                        var23.setIntArray("FadeColors", var17);
216                        return true;
217                    }
218                }
219                else
220                {
221                    return false;
222                }
223            }
224            else
225            {
226                return false;
227            }
228        }
229        else
230        {
231            return false;
232        }
233    }
234
235    /**
236     * Returns an Item that is the result of this recipe
237     */
238    public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
239    {
240        return this.field_92102_a.copy();
241    }
242
243    /**
244     * Returns the size of the recipe area
245     */
246    public int getRecipeSize()
247    {
248        return 10;
249    }
250
251    public ItemStack getRecipeOutput()
252    {
253        return this.field_92102_a;
254    }
255}