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 i = 0; 023 int j = 0; 024 int k = 0; 025 int l = 0; 026 int i1 = 0; 027 int j1 = 0; 028 029 for (int k1 = 0; k1 < par1InventoryCrafting.getSizeInventory(); ++k1) 030 { 031 ItemStack itemstack = par1InventoryCrafting.getStackInSlot(k1); 032 033 if (itemstack != null) 034 { 035 if (itemstack.itemID == Item.gunpowder.itemID) 036 { 037 ++j; 038 } 039 else if (itemstack.itemID == Item.fireworkCharge.itemID) 040 { 041 ++l; 042 } 043 else if (itemstack.itemID == Item.dyePowder.itemID) 044 { 045 ++k; 046 } 047 else if (itemstack.itemID == Item.paper.itemID) 048 { 049 ++i; 050 } 051 else if (itemstack.itemID == Item.lightStoneDust.itemID) 052 { 053 ++i1; 054 } 055 else if (itemstack.itemID == Item.diamond.itemID) 056 { 057 ++i1; 058 } 059 else if (itemstack.itemID == Item.fireballCharge.itemID) 060 { 061 ++j1; 062 } 063 else if (itemstack.itemID == Item.feather.itemID) 064 { 065 ++j1; 066 } 067 else if (itemstack.itemID == Item.goldNugget.itemID) 068 { 069 ++j1; 070 } 071 else 072 { 073 if (itemstack.itemID != Item.skull.itemID) 074 { 075 return false; 076 } 077 078 ++j1; 079 } 080 } 081 } 082 083 i1 += k + j1; 084 085 if (j <= 3 && i <= 1) 086 { 087 NBTTagCompound nbttagcompound; 088 NBTTagCompound nbttagcompound1; 089 090 if (j >= 1 && i == 1 && i1 == 0) 091 { 092 this.field_92102_a = new ItemStack(Item.firework); 093 094 nbttagcompound = new NBTTagCompound(); 095 if (l > 0) 096 { 097 nbttagcompound1 = new NBTTagCompound("Fireworks"); 098 NBTTagList nbttaglist = new NBTTagList("Explosions"); 099 100 for (int l1 = 0; l1 < par1InventoryCrafting.getSizeInventory(); ++l1) 101 { 102 ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(l1); 103 104 if (itemstack1 != null && itemstack1.itemID == Item.fireworkCharge.itemID && itemstack1.hasTagCompound() && itemstack1.getTagCompound().hasKey("Explosion")) 105 { 106 nbttaglist.appendTag(itemstack1.getTagCompound().getCompoundTag("Explosion")); 107 } 108 } 109 110 nbttagcompound1.setTag("Explosions", nbttaglist); 111 nbttagcompound1.setByte("Flight", (byte)j); 112 nbttagcompound.setTag("Fireworks", nbttagcompound1); 113 } 114 115 this.field_92102_a.setTagCompound(nbttagcompound); 116 return true; 117 } 118 else if (j == 1 && i == 0 && l == 0 && k > 0 && j1 <= 1) 119 { 120 this.field_92102_a = new ItemStack(Item.fireworkCharge); 121 nbttagcompound = new NBTTagCompound(); 122 nbttagcompound1 = new NBTTagCompound("Explosion"); 123 byte b0 = 0; 124 ArrayList arraylist = new ArrayList(); 125 126 for (int i2 = 0; i2 < par1InventoryCrafting.getSizeInventory(); ++i2) 127 { 128 ItemStack itemstack2 = par1InventoryCrafting.getStackInSlot(i2); 129 130 if (itemstack2 != null) 131 { 132 if (itemstack2.itemID == Item.dyePowder.itemID) 133 { 134 arraylist.add(Integer.valueOf(ItemDye.dyeColors[itemstack2.getItemDamage()])); 135 } 136 else if (itemstack2.itemID == Item.lightStoneDust.itemID) 137 { 138 nbttagcompound1.setBoolean("Flicker", true); 139 } 140 else if (itemstack2.itemID == Item.diamond.itemID) 141 { 142 nbttagcompound1.setBoolean("Trail", true); 143 } 144 else if (itemstack2.itemID == Item.fireballCharge.itemID) 145 { 146 b0 = 1; 147 } 148 else if (itemstack2.itemID == Item.feather.itemID) 149 { 150 b0 = 4; 151 } 152 else if (itemstack2.itemID == Item.goldNugget.itemID) 153 { 154 b0 = 2; 155 } 156 else if (itemstack2.itemID == Item.skull.itemID) 157 { 158 b0 = 3; 159 } 160 } 161 } 162 163 int[] aint = new int[arraylist.size()]; 164 165 for (int j2 = 0; j2 < aint.length; ++j2) 166 { 167 aint[j2] = ((Integer)arraylist.get(j2)).intValue(); 168 } 169 170 nbttagcompound1.setIntArray("Colors", aint); 171 nbttagcompound1.setByte("Type", b0); 172 nbttagcompound.setTag("Explosion", nbttagcompound1); 173 this.field_92102_a.setTagCompound(nbttagcompound); 174 return true; 175 } 176 else if (j == 0 && i == 0 && l == 1 && k > 0 && k == i1) 177 { 178 ArrayList arraylist1 = new ArrayList(); 179 180 for (int k2 = 0; k2 < par1InventoryCrafting.getSizeInventory(); ++k2) 181 { 182 ItemStack itemstack3 = par1InventoryCrafting.getStackInSlot(k2); 183 184 if (itemstack3 != null) 185 { 186 if (itemstack3.itemID == Item.dyePowder.itemID) 187 { 188 arraylist1.add(Integer.valueOf(ItemDye.dyeColors[itemstack3.getItemDamage()])); 189 } 190 else if (itemstack3.itemID == Item.fireworkCharge.itemID) 191 { 192 this.field_92102_a = itemstack3.copy(); 193 this.field_92102_a.stackSize = 1; 194 } 195 } 196 } 197 198 int[] aint1 = new int[arraylist1.size()]; 199 200 for (int l2 = 0; l2 < aint1.length; ++l2) 201 { 202 aint1[l2] = ((Integer)arraylist1.get(l2)).intValue(); 203 } 204 205 if (this.field_92102_a != null && this.field_92102_a.hasTagCompound()) 206 { 207 NBTTagCompound nbttagcompound2 = this.field_92102_a.getTagCompound().getCompoundTag("Explosion"); 208 209 if (nbttagcompound2 == null) 210 { 211 return false; 212 } 213 else 214 { 215 nbttagcompound2.setIntArray("FadeColors", aint1); 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}