| 1 | package net.minecraft.item.crafting;
|
| 2 |
|
| 3 | import net.minecraft.init.Blocks;
|
| 4 | import net.minecraft.init.Items;
|
| 5 | import net.minecraft.inventory.InventoryCrafting;
|
| 6 | import net.minecraft.item.EnumDyeColor;
|
| 7 | import net.minecraft.item.ItemStack;
|
| 8 | import net.minecraft.nbt.NBTTagCompound;
|
| 9 | import net.minecraft.nbt.NBTTagList;
|
| 10 | import net.minecraft.tileentity.TileEntityBanner;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public class RecipesBanners
|
| 14 | {
|
| 15 | /**
|
| 16 | * Adds the banner recipes to the CraftingManager.
|
| 17 | */
|
| 18 | void addRecipes(CraftingManager p_179534_1_)
|
| 19 | {
|
| 20 | for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
|
| 21 | {
|
| 22 | p_179534_1_.addRecipe(new ItemStack(Items.banner, 1, enumdyecolor.getDyeDamage()), new Object[] {"###", "###", " | ", '#', new ItemStack(Blocks.wool, 1, enumdyecolor.getMetadata()), '|', Items.stick});
|
| 23 | }
|
| 24 |
|
| 25 | p_179534_1_.addRecipe(new RecipesBanners.RecipeDuplicatePattern());
|
| 26 | p_179534_1_.addRecipe(new RecipesBanners.RecipeAddPattern());
|
| 27 | }
|
| 28 |
|
| 29 | static class RecipeAddPattern implements IRecipe
|
| 30 | {
|
| 31 | private RecipeAddPattern()
|
| 32 | {
|
| 33 | }
|
| 34 |
|
| 35 | public boolean matches(InventoryCrafting inv, World worldIn)
|
| 36 | {
|
| 37 | boolean flag = false;
|
| 38 |
|
| 39 | for (int i = 0; i < inv.getSizeInventory(); ++i)
|
| 40 | {
|
| 41 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 42 |
|
| 43 | if (itemstack != null && itemstack.getItem() == Items.banner)
|
| 44 | {
|
| 45 | if (flag)
|
| 46 | {
|
| 47 | return false;
|
| 48 | }
|
| 49 |
|
| 50 | if (TileEntityBanner.getPatterns(itemstack) >= 6)
|
| 51 | {
|
| 52 | return false;
|
| 53 | }
|
| 54 |
|
| 55 | flag = true;
|
| 56 | }
|
| 57 | }
|
| 58 |
|
| 59 | if (!flag)
|
| 60 | {
|
| 61 | return false;
|
| 62 | }
|
| 63 | else
|
| 64 | {
|
| 65 | return this.func_179533_c(inv) != null;
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | public ItemStack getCraftingResult(InventoryCrafting inv)
|
| 70 | {
|
| 71 | ItemStack itemstack = null;
|
| 72 |
|
| 73 | for (int i = 0; i < inv.getSizeInventory(); ++i)
|
| 74 | {
|
| 75 | ItemStack itemstack1 = inv.getStackInSlot(i);
|
| 76 |
|
| 77 | if (itemstack1 != null && itemstack1.getItem() == Items.banner)
|
| 78 | {
|
| 79 | itemstack = itemstack1.copy();
|
| 80 | itemstack.stackSize = 1;
|
| 81 | break;
|
| 82 | }
|
| 83 | }
|
| 84 |
|
| 85 | TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern = this.func_179533_c(inv);
|
| 86 |
|
| 87 | if (tileentitybanner$enumbannerpattern != null)
|
| 88 | {
|
| 89 | int k = 0;
|
| 90 |
|
| 91 | for (int j = 0; j < inv.getSizeInventory(); ++j)
|
| 92 | {
|
| 93 | ItemStack itemstack2 = inv.getStackInSlot(j);
|
| 94 |
|
| 95 | if (itemstack2 != null && itemstack2.getItem() == Items.dye)
|
| 96 | {
|
| 97 | k = itemstack2.getMetadata();
|
| 98 | break;
|
| 99 | }
|
| 100 | }
|
| 101 |
|
| 102 | NBTTagCompound nbttagcompound1 = itemstack.getSubCompound("BlockEntityTag", true);
|
| 103 | NBTTagList nbttaglist = null;
|
| 104 |
|
| 105 | if (nbttagcompound1.hasKey("Patterns", 9))
|
| 106 | {
|
| 107 | nbttaglist = nbttagcompound1.getTagList("Patterns", 10);
|
| 108 | }
|
| 109 | else
|
| 110 | {
|
| 111 | nbttaglist = new NBTTagList();
|
| 112 | nbttagcompound1.setTag("Patterns", nbttaglist);
|
| 113 | }
|
| 114 |
|
| 115 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 116 | nbttagcompound.setString("Pattern", tileentitybanner$enumbannerpattern.getPatternID());
|
| 117 | nbttagcompound.setInteger("Color", k);
|
| 118 | nbttaglist.appendTag(nbttagcompound);
|
| 119 | }
|
| 120 |
|
| 121 | return itemstack;
|
| 122 | }
|
| 123 |
|
| 124 | public int getRecipeSize()
|
| 125 | {
|
| 126 | return 10;
|
| 127 | }
|
| 128 |
|
| 129 | public ItemStack getRecipeOutput()
|
| 130 | {
|
| 131 | return null;
|
| 132 | }
|
| 133 |
|
| 134 | public ItemStack[] getRemainingItems(InventoryCrafting inv)
|
| 135 | {
|
| 136 | ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
|
| 137 |
|
| 138 | for (int i = 0; i < aitemstack.length; ++i)
|
| 139 | {
|
| 140 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 141 |
|
| 142 | if (itemstack != null && itemstack.getItem().hasContainerItem())
|
| 143 | {
|
| 144 | aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem());
|
| 145 | }
|
| 146 | }
|
| 147 |
|
| 148 | return aitemstack;
|
| 149 | }
|
| 150 |
|
| 151 | private TileEntityBanner.EnumBannerPattern func_179533_c(InventoryCrafting p_179533_1_)
|
| 152 | {
|
| 153 | for (TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern : TileEntityBanner.EnumBannerPattern.values())
|
| 154 | {
|
| 155 | if (tileentitybanner$enumbannerpattern.hasValidCrafting())
|
| 156 | {
|
| 157 | boolean flag = true;
|
| 158 |
|
| 159 | if (tileentitybanner$enumbannerpattern.hasCraftingStack())
|
| 160 | {
|
| 161 | boolean flag1 = false;
|
| 162 | boolean flag2 = false;
|
| 163 |
|
| 164 | for (int i = 0; i < p_179533_1_.getSizeInventory() && flag; ++i)
|
| 165 | {
|
| 166 | ItemStack itemstack = p_179533_1_.getStackInSlot(i);
|
| 167 |
|
| 168 | if (itemstack != null && itemstack.getItem() != Items.banner)
|
| 169 | {
|
| 170 | if (itemstack.getItem() == Items.dye)
|
| 171 | {
|
| 172 | if (flag2)
|
| 173 | {
|
| 174 | flag = false;
|
| 175 | break;
|
| 176 | }
|
| 177 |
|
| 178 | flag2 = true;
|
| 179 | }
|
| 180 | else
|
| 181 | {
|
| 182 | if (flag1 || !itemstack.isItemEqual(tileentitybanner$enumbannerpattern.getCraftingStack()))
|
| 183 | {
|
| 184 | flag = false;
|
| 185 | break;
|
| 186 | }
|
| 187 |
|
| 188 | flag1 = true;
|
| 189 | }
|
| 190 | }
|
| 191 | }
|
| 192 |
|
| 193 | if (!flag1)
|
| 194 | {
|
| 195 | flag = false;
|
| 196 | }
|
| 197 | }
|
| 198 | else if (p_179533_1_.getSizeInventory() == tileentitybanner$enumbannerpattern.getCraftingLayers().length * tileentitybanner$enumbannerpattern.getCraftingLayers()[0].length())
|
| 199 | {
|
| 200 | int j = -1;
|
| 201 |
|
| 202 | for (int k = 0; k < p_179533_1_.getSizeInventory() && flag; ++k)
|
| 203 | {
|
| 204 | int l = k / 3;
|
| 205 | int i1 = k % 3;
|
| 206 | ItemStack itemstack1 = p_179533_1_.getStackInSlot(k);
|
| 207 |
|
| 208 | if (itemstack1 != null && itemstack1.getItem() != Items.banner)
|
| 209 | {
|
| 210 | if (itemstack1.getItem() != Items.dye)
|
| 211 | {
|
| 212 | flag = false;
|
| 213 | break;
|
| 214 | }
|
| 215 |
|
| 216 | if (j != -1 && j != itemstack1.getMetadata())
|
| 217 | {
|
| 218 | flag = false;
|
| 219 | break;
|
| 220 | }
|
| 221 |
|
| 222 | if (tileentitybanner$enumbannerpattern.getCraftingLayers()[l].charAt(i1) == 32)
|
| 223 | {
|
| 224 | flag = false;
|
| 225 | break;
|
| 226 | }
|
| 227 |
|
| 228 | j = itemstack1.getMetadata();
|
| 229 | }
|
| 230 | else if (tileentitybanner$enumbannerpattern.getCraftingLayers()[l].charAt(i1) != 32)
|
| 231 | {
|
| 232 | flag = false;
|
| 233 | break;
|
| 234 | }
|
| 235 | }
|
| 236 | }
|
| 237 | else
|
| 238 | {
|
| 239 | flag = false;
|
| 240 | }
|
| 241 |
|
| 242 | if (flag)
|
| 243 | {
|
| 244 | return tileentitybanner$enumbannerpattern;
|
| 245 | }
|
| 246 | }
|
| 247 | }
|
| 248 |
|
| 249 | return null;
|
| 250 | }
|
| 251 | }
|
| 252 |
|
| 253 | static class RecipeDuplicatePattern implements IRecipe
|
| 254 | {
|
| 255 | private RecipeDuplicatePattern()
|
| 256 | {
|
| 257 | }
|
| 258 |
|
| 259 | public boolean matches(InventoryCrafting inv, World worldIn)
|
| 260 | {
|
| 261 | ItemStack itemstack = null;
|
| 262 | ItemStack itemstack1 = null;
|
| 263 |
|
| 264 | for (int i = 0; i < inv.getSizeInventory(); ++i)
|
| 265 | {
|
| 266 | ItemStack itemstack2 = inv.getStackInSlot(i);
|
| 267 |
|
| 268 | if (itemstack2 != null)
|
| 269 | {
|
| 270 | if (itemstack2.getItem() != Items.banner)
|
| 271 | {
|
| 272 | return false;
|
| 273 | }
|
| 274 |
|
| 275 | if (itemstack != null && itemstack1 != null)
|
| 276 | {
|
| 277 | return false;
|
| 278 | }
|
| 279 |
|
| 280 | int j = TileEntityBanner.getBaseColor(itemstack2);
|
| 281 | boolean flag = TileEntityBanner.getPatterns(itemstack2) > 0;
|
| 282 |
|
| 283 | if (itemstack != null)
|
| 284 | {
|
| 285 | if (flag)
|
| 286 | {
|
| 287 | return false;
|
| 288 | }
|
| 289 |
|
| 290 | if (j != TileEntityBanner.getBaseColor(itemstack))
|
| 291 | {
|
| 292 | return false;
|
| 293 | }
|
| 294 |
|
| 295 | itemstack1 = itemstack2;
|
| 296 | }
|
| 297 | else if (itemstack1 != null)
|
| 298 | {
|
| 299 | if (!flag)
|
| 300 | {
|
| 301 | return false;
|
| 302 | }
|
| 303 |
|
| 304 | if (j != TileEntityBanner.getBaseColor(itemstack1))
|
| 305 | {
|
| 306 | return false;
|
| 307 | }
|
| 308 |
|
| 309 | itemstack = itemstack2;
|
| 310 | }
|
| 311 | else if (flag)
|
| 312 | {
|
| 313 | itemstack = itemstack2;
|
| 314 | }
|
| 315 | else
|
| 316 | {
|
| 317 | itemstack1 = itemstack2;
|
| 318 | }
|
| 319 | }
|
| 320 | }
|
| 321 |
|
| 322 | return itemstack != null && itemstack1 != null;
|
| 323 | }
|
| 324 |
|
| 325 | public ItemStack getCraftingResult(InventoryCrafting inv)
|
| 326 | {
|
| 327 | for (int i = 0; i < inv.getSizeInventory(); ++i)
|
| 328 | {
|
| 329 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 330 |
|
| 331 | if (itemstack != null && TileEntityBanner.getPatterns(itemstack) > 0)
|
| 332 | {
|
| 333 | ItemStack itemstack1 = itemstack.copy();
|
| 334 | itemstack1.stackSize = 1;
|
| 335 | return itemstack1;
|
| 336 | }
|
| 337 | }
|
| 338 |
|
| 339 | return null;
|
| 340 | }
|
| 341 |
|
| 342 | public int getRecipeSize()
|
| 343 | {
|
| 344 | return 2;
|
| 345 | }
|
| 346 |
|
| 347 | public ItemStack getRecipeOutput()
|
| 348 | {
|
| 349 | return null;
|
| 350 | }
|
| 351 |
|
| 352 | public ItemStack[] getRemainingItems(InventoryCrafting inv)
|
| 353 | {
|
| 354 | ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
|
| 355 |
|
| 356 | for (int i = 0; i < aitemstack.length; ++i)
|
| 357 | {
|
| 358 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 359 |
|
| 360 | if (itemstack != null)
|
| 361 | {
|
| 362 | if (itemstack.getItem().hasContainerItem())
|
| 363 | {
|
| 364 | aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem());
|
| 365 | }
|
| 366 | else if (itemstack.hasTagCompound() && TileEntityBanner.getPatterns(itemstack) > 0)
|
| 367 | {
|
| 368 | aitemstack[i] = itemstack.copy();
|
| 369 | aitemstack[i].stackSize = 1;
|
| 370 | }
|
| 371 | }
|
| 372 | }
|
| 373 |
|
| 374 | return aitemstack;
|
| 375 | }
|
| 376 | }
|
| 377 | }
|
| 378 |
|