| 1 | package net.minecraft.item.crafting;
|
| 2 |
|
| 3 | import net.minecraft.init.Items;
|
| 4 | import net.minecraft.inventory.InventoryCrafting;
|
| 5 | import net.minecraft.item.ItemEditableBook;
|
| 6 | import net.minecraft.item.ItemStack;
|
| 7 | import net.minecraft.nbt.NBTTagCompound;
|
| 8 | import net.minecraft.world.World;
|
| 9 |
|
| 10 | public class RecipeBookCloning implements IRecipe
|
| 11 | {
|
| 12 | /**
|
| 13 | * Used to check if a recipe matches current crafting inventory
|
| 14 | */
|
| 15 | public boolean matches(InventoryCrafting inv, World worldIn)
|
| 16 | {
|
| 17 | int i = 0;
|
| 18 | ItemStack itemstack = null;
|
| 19 |
|
| 20 | for (int j = 0; j < inv.getSizeInventory(); ++j)
|
| 21 | {
|
| 22 | ItemStack itemstack1 = inv.getStackInSlot(j);
|
| 23 |
|
| 24 | if (itemstack1 != null)
|
| 25 | {
|
| 26 | if (itemstack1.getItem() == Items.written_book)
|
| 27 | {
|
| 28 | if (itemstack != null)
|
| 29 | {
|
| 30 | return false;
|
| 31 | }
|
| 32 |
|
| 33 | itemstack = itemstack1;
|
| 34 | }
|
| 35 | else
|
| 36 | {
|
| 37 | if (itemstack1.getItem() != Items.writable_book)
|
| 38 | {
|
| 39 | return false;
|
| 40 | }
|
| 41 |
|
| 42 | ++i;
|
| 43 | }
|
| 44 | }
|
| 45 | }
|
| 46 |
|
| 47 | return itemstack != null && i > 0;
|
| 48 | }
|
| 49 |
|
| 50 | /**
|
| 51 | * Returns an Item that is the result of this recipe
|
| 52 | */
|
| 53 | public ItemStack getCraftingResult(InventoryCrafting inv)
|
| 54 | {
|
| 55 | int i = 0;
|
| 56 | ItemStack itemstack = null;
|
| 57 |
|
| 58 | for (int j = 0; j < inv.getSizeInventory(); ++j)
|
| 59 | {
|
| 60 | ItemStack itemstack1 = inv.getStackInSlot(j);
|
| 61 |
|
| 62 | if (itemstack1 != null)
|
| 63 | {
|
| 64 | if (itemstack1.getItem() == Items.written_book)
|
| 65 | {
|
| 66 | if (itemstack != null)
|
| 67 | {
|
| 68 | return null;
|
| 69 | }
|
| 70 |
|
| 71 | itemstack = itemstack1;
|
| 72 | }
|
| 73 | else
|
| 74 | {
|
| 75 | if (itemstack1.getItem() != Items.writable_book)
|
| 76 | {
|
| 77 | return null;
|
| 78 | }
|
| 79 |
|
| 80 | ++i;
|
| 81 | }
|
| 82 | }
|
| 83 | }
|
| 84 |
|
| 85 | if (itemstack != null && i >= 1 && ItemEditableBook.getGeneration(itemstack) < 2)
|
| 86 | {
|
| 87 | ItemStack itemstack2 = new ItemStack(Items.written_book, i);
|
| 88 | itemstack2.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
|
| 89 | itemstack2.getTagCompound().setInteger("generation", ItemEditableBook.getGeneration(itemstack) + 1);
|
| 90 |
|
| 91 | if (itemstack.hasDisplayName())
|
| 92 | {
|
| 93 | itemstack2.setStackDisplayName(itemstack.getDisplayName());
|
| 94 | }
|
| 95 |
|
| 96 | return itemstack2;
|
| 97 | }
|
| 98 | else
|
| 99 | {
|
| 100 | return null;
|
| 101 | }
|
| 102 | }
|
| 103 |
|
| 104 | /**
|
| 105 | * Returns the size of the recipe area
|
| 106 | */
|
| 107 | public int getRecipeSize()
|
| 108 | {
|
| 109 | return 9;
|
| 110 | }
|
| 111 |
|
| 112 | public ItemStack getRecipeOutput()
|
| 113 | {
|
| 114 | return null;
|
| 115 | }
|
| 116 |
|
| 117 | public ItemStack[] getRemainingItems(InventoryCrafting inv)
|
| 118 | {
|
| 119 | ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
|
| 120 |
|
| 121 | for (int i = 0; i < aitemstack.length; ++i)
|
| 122 | {
|
| 123 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 124 |
|
| 125 | if (itemstack != null && itemstack.getItem() instanceof ItemEditableBook)
|
| 126 | {
|
| 127 | aitemstack[i] = itemstack;
|
| 128 | break;
|
| 129 | }
|
| 130 | }
|
| 131 |
|
| 132 | return aitemstack;
|
| 133 | }
|
| 134 | }
|
| 135 |
|