| 1 | package net.minecraft.item.crafting;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.init.Items;
|
| 6 | import net.minecraft.inventory.InventoryCrafting;
|
| 7 | import net.minecraft.item.ItemDye;
|
| 8 | import net.minecraft.item.ItemStack;
|
| 9 | import net.minecraft.nbt.NBTTagCompound;
|
| 10 | import net.minecraft.nbt.NBTTagList;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public class RecipeFireworks implements IRecipe
|
| 14 | {
|
| 15 | private ItemStack field_92102_a;
|
| 16 |
|
| 17 | /**
|
| 18 | * Used to check if a recipe matches current crafting inventory
|
| 19 | */
|
| 20 | public boolean matches(InventoryCrafting inv, World worldIn)
|
| 21 | {
|
| 22 | this.field_92102_a = null;
|
| 23 | int i = 0;
|
| 24 | int j = 0;
|
| 25 | int k = 0;
|
| 26 | int l = 0;
|
| 27 | int i1 = 0;
|
| 28 | int j1 = 0;
|
| 29 |
|
| 30 | for (int k1 = 0; k1 < inv.getSizeInventory(); ++k1)
|
| 31 | {
|
| 32 | ItemStack itemstack = inv.getStackInSlot(k1);
|
| 33 |
|
| 34 | if (itemstack != null)
|
| 35 | {
|
| 36 | if (itemstack.getItem() == Items.gunpowder)
|
| 37 | {
|
| 38 | ++j;
|
| 39 | }
|
| 40 | else if (itemstack.getItem() == Items.firework_charge)
|
| 41 | {
|
| 42 | ++l;
|
| 43 | }
|
| 44 | else if (itemstack.getItem() == Items.dye)
|
| 45 | {
|
| 46 | ++k;
|
| 47 | }
|
| 48 | else if (itemstack.getItem() == Items.paper)
|
| 49 | {
|
| 50 | ++i;
|
| 51 | }
|
| 52 | else if (itemstack.getItem() == Items.glowstone_dust)
|
| 53 | {
|
| 54 | ++i1;
|
| 55 | }
|
| 56 | else if (itemstack.getItem() == Items.diamond)
|
| 57 | {
|
| 58 | ++i1;
|
| 59 | }
|
| 60 | else if (itemstack.getItem() == Items.fire_charge)
|
| 61 | {
|
| 62 | ++j1;
|
| 63 | }
|
| 64 | else if (itemstack.getItem() == Items.feather)
|
| 65 | {
|
| 66 | ++j1;
|
| 67 | }
|
| 68 | else if (itemstack.getItem() == Items.gold_nugget)
|
| 69 | {
|
| 70 | ++j1;
|
| 71 | }
|
| 72 | else
|
| 73 | {
|
| 74 | if (itemstack.getItem() != Items.skull)
|
| 75 | {
|
| 76 | return false;
|
| 77 | }
|
| 78 |
|
| 79 | ++j1;
|
| 80 | }
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | i1 = i1 + k + j1;
|
| 85 |
|
| 86 | if (j <= 3 && i <= 1)
|
| 87 | {
|
| 88 | if (j >= 1 && i == 1 && i1 == 0)
|
| 89 | {
|
| 90 | this.field_92102_a = new ItemStack(Items.fireworks);
|
| 91 |
|
| 92 | if (l > 0)
|
| 93 | {
|
| 94 | NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
| 95 | NBTTagCompound nbttagcompound3 = new NBTTagCompound();
|
| 96 | NBTTagList nbttaglist = new NBTTagList();
|
| 97 |
|
| 98 | for (int k2 = 0; k2 < inv.getSizeInventory(); ++k2)
|
| 99 | {
|
| 100 | ItemStack itemstack3 = inv.getStackInSlot(k2);
|
| 101 |
|
| 102 | if (itemstack3 != null && itemstack3.getItem() == Items.firework_charge && itemstack3.hasTagCompound() && itemstack3.getTagCompound().hasKey("Explosion", 10))
|
| 103 | {
|
| 104 | nbttaglist.appendTag(itemstack3.getTagCompound().getCompoundTag("Explosion"));
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 | nbttagcompound3.setTag("Explosions", nbttaglist);
|
| 109 | nbttagcompound3.setByte("Flight", (byte)j);
|
| 110 | nbttagcompound1.setTag("Fireworks", nbttagcompound3);
|
| 111 | this.field_92102_a.setTagCompound(nbttagcompound1);
|
| 112 | }
|
| 113 |
|
| 114 | return true;
|
| 115 | }
|
| 116 | else if (j == 1 && i == 0 && l == 0 && k > 0 && j1 <= 1)
|
| 117 | {
|
| 118 | this.field_92102_a = new ItemStack(Items.firework_charge);
|
| 119 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 120 | NBTTagCompound nbttagcompound2 = new NBTTagCompound();
|
| 121 | byte b0 = 0;
|
| 122 | List<Integer> list = Lists.<Integer>newArrayList();
|
| 123 |
|
| 124 | for (int l1 = 0; l1 < inv.getSizeInventory(); ++l1)
|
| 125 | {
|
| 126 | ItemStack itemstack2 = inv.getStackInSlot(l1);
|
| 127 |
|
| 128 | if (itemstack2 != null)
|
| 129 | {
|
| 130 | if (itemstack2.getItem() == Items.dye)
|
| 131 | {
|
| 132 | list.add(Integer.valueOf(ItemDye.dyeColors[itemstack2.getMetadata() & 15]));
|
| 133 | }
|
| 134 | else if (itemstack2.getItem() == Items.glowstone_dust)
|
| 135 | {
|
| 136 | nbttagcompound2.setBoolean("Flicker", true);
|
| 137 | }
|
| 138 | else if (itemstack2.getItem() == Items.diamond)
|
| 139 | {
|
| 140 | nbttagcompound2.setBoolean("Trail", true);
|
| 141 | }
|
| 142 | else if (itemstack2.getItem() == Items.fire_charge)
|
| 143 | {
|
| 144 | b0 = 1;
|
| 145 | }
|
| 146 | else if (itemstack2.getItem() == Items.feather)
|
| 147 | {
|
| 148 | b0 = 4;
|
| 149 | }
|
| 150 | else if (itemstack2.getItem() == Items.gold_nugget)
|
| 151 | {
|
| 152 | b0 = 2;
|
| 153 | }
|
| 154 | else if (itemstack2.getItem() == Items.skull)
|
| 155 | {
|
| 156 | b0 = 3;
|
| 157 | }
|
| 158 | }
|
| 159 | }
|
| 160 |
|
| 161 | int[] aint1 = new int[list.size()];
|
| 162 |
|
| 163 | for (int l2 = 0; l2 < aint1.length; ++l2)
|
| 164 | {
|
| 165 | aint1[l2] = ((Integer)list.get(l2)).intValue();
|
| 166 | }
|
| 167 |
|
| 168 | nbttagcompound2.setIntArray("Colors", aint1);
|
| 169 | nbttagcompound2.setByte("Type", b0);
|
| 170 | nbttagcompound.setTag("Explosion", nbttagcompound2);
|
| 171 | this.field_92102_a.setTagCompound(nbttagcompound);
|
| 172 | return true;
|
| 173 | }
|
| 174 | else if (j == 0 && i == 0 && l == 1 && k > 0 && k == i1)
|
| 175 | {
|
| 176 | List<Integer> list1 = Lists.<Integer>newArrayList();
|
| 177 |
|
| 178 | for (int i2 = 0; i2 < inv.getSizeInventory(); ++i2)
|
| 179 | {
|
| 180 | ItemStack itemstack1 = inv.getStackInSlot(i2);
|
| 181 |
|
| 182 | if (itemstack1 != null)
|
| 183 | {
|
| 184 | if (itemstack1.getItem() == Items.dye)
|
| 185 | {
|
| 186 | list1.add(Integer.valueOf(ItemDye.dyeColors[itemstack1.getMetadata() & 15]));
|
| 187 | }
|
| 188 | else if (itemstack1.getItem() == Items.firework_charge)
|
| 189 | {
|
| 190 | this.field_92102_a = itemstack1.copy();
|
| 191 | this.field_92102_a.stackSize = 1;
|
| 192 | }
|
| 193 | }
|
| 194 | }
|
| 195 |
|
| 196 | int[] aint = new int[list1.size()];
|
| 197 |
|
| 198 | for (int j2 = 0; j2 < aint.length; ++j2)
|
| 199 | {
|
| 200 | aint[j2] = ((Integer)list1.get(j2)).intValue();
|
| 201 | }
|
| 202 |
|
| 203 | if (this.field_92102_a != null && this.field_92102_a.hasTagCompound())
|
| 204 | {
|
| 205 | NBTTagCompound nbttagcompound4 = this.field_92102_a.getTagCompound().getCompoundTag("Explosion");
|
| 206 |
|
| 207 | if (nbttagcompound4 == null)
|
| 208 | {
|
| 209 | return false;
|
| 210 | }
|
| 211 | else
|
| 212 | {
|
| 213 | nbttagcompound4.setIntArray("FadeColors", aint);
|
| 214 | return true;
|
| 215 | }
|
| 216 | }
|
| 217 | else
|
| 218 | {
|
| 219 | return false;
|
| 220 | }
|
| 221 | }
|
| 222 | else
|
| 223 | {
|
| 224 | return false;
|
| 225 | }
|
| 226 | }
|
| 227 | else
|
| 228 | {
|
| 229 | return false;
|
| 230 | }
|
| 231 | }
|
| 232 |
|
| 233 | /**
|
| 234 | * Returns an Item that is the result of this recipe
|
| 235 | */
|
| 236 | public ItemStack getCraftingResult(InventoryCrafting inv)
|
| 237 | {
|
| 238 | return this.field_92102_a.copy();
|
| 239 | }
|
| 240 |
|
| 241 | /**
|
| 242 | * Returns the size of the recipe area
|
| 243 | */
|
| 244 | public int getRecipeSize()
|
| 245 | {
|
| 246 | return 10;
|
| 247 | }
|
| 248 |
|
| 249 | public ItemStack getRecipeOutput()
|
| 250 | {
|
| 251 | return this.field_92102_a;
|
| 252 | }
|
| 253 |
|
| 254 | public ItemStack[] getRemainingItems(InventoryCrafting inv)
|
| 255 | {
|
| 256 | ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
|
| 257 |
|
| 258 | for (int i = 0; i < aitemstack.length; ++i)
|
| 259 | {
|
| 260 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 261 |
|
| 262 | if (itemstack != null && itemstack.getItem().hasContainerItem())
|
| 263 | {
|
| 264 | aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem());
|
| 265 | }
|
| 266 | }
|
| 267 |
|
| 268 | return aitemstack;
|
| 269 | }
|
| 270 | }
|
| 271 |
|