| 1 | package net.minecraft.item.crafting;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.inventory.InventoryCrafting;
|
| 6 | import net.minecraft.item.Item;
|
| 7 | import net.minecraft.item.ItemStack;
|
| 8 | import net.minecraft.world.World;
|
| 9 |
|
| 10 | public class RecipeRepairItem 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 | List<ItemStack> list = Lists.<ItemStack>newArrayList();
|
| 18 |
|
| 19 | for (int i = 0; i < inv.getSizeInventory(); ++i)
|
| 20 | {
|
| 21 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 22 |
|
| 23 | if (itemstack != null)
|
| 24 | {
|
| 25 | list.add(itemstack);
|
| 26 |
|
| 27 | if (list.size() > 1)
|
| 28 | {
|
| 29 | ItemStack itemstack1 = (ItemStack)list.get(0);
|
| 30 |
|
| 31 | if (itemstack.getItem() != itemstack1.getItem() || itemstack1.stackSize != 1 || itemstack.stackSize != 1 || !itemstack1.getItem().isDamageable())
|
| 32 | {
|
| 33 | return false;
|
| 34 | }
|
| 35 | }
|
| 36 | }
|
| 37 | }
|
| 38 |
|
| 39 | return list.size() == 2;
|
| 40 | }
|
| 41 |
|
| 42 | /**
|
| 43 | * Returns an Item that is the result of this recipe
|
| 44 | */
|
| 45 | public ItemStack getCraftingResult(InventoryCrafting inv)
|
| 46 | {
|
| 47 | List<ItemStack> list = Lists.<ItemStack>newArrayList();
|
| 48 |
|
| 49 | for (int i = 0; i < inv.getSizeInventory(); ++i)
|
| 50 | {
|
| 51 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 52 |
|
| 53 | if (itemstack != null)
|
| 54 | {
|
| 55 | list.add(itemstack);
|
| 56 |
|
| 57 | if (list.size() > 1)
|
| 58 | {
|
| 59 | ItemStack itemstack1 = (ItemStack)list.get(0);
|
| 60 |
|
| 61 | if (itemstack.getItem() != itemstack1.getItem() || itemstack1.stackSize != 1 || itemstack.stackSize != 1 || !itemstack1.getItem().isDamageable())
|
| 62 | {
|
| 63 | return null;
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | if (list.size() == 2)
|
| 70 | {
|
| 71 | ItemStack itemstack2 = (ItemStack)list.get(0);
|
| 72 | ItemStack itemstack3 = (ItemStack)list.get(1);
|
| 73 |
|
| 74 | if (itemstack2.getItem() == itemstack3.getItem() && itemstack2.stackSize == 1 && itemstack3.stackSize == 1 && itemstack2.getItem().isDamageable())
|
| 75 | {
|
| 76 | Item item = itemstack2.getItem();
|
| 77 | int j = item.getMaxDamage() - itemstack2.getItemDamage();
|
| 78 | int k = item.getMaxDamage() - itemstack3.getItemDamage();
|
| 79 | int l = j + k + item.getMaxDamage() * 5 / 100;
|
| 80 | int i1 = item.getMaxDamage() - l;
|
| 81 |
|
| 82 | if (i1 < 0)
|
| 83 | {
|
| 84 | i1 = 0;
|
| 85 | }
|
| 86 |
|
| 87 | return new ItemStack(itemstack2.getItem(), 1, i1);
|
| 88 | }
|
| 89 | }
|
| 90 |
|
| 91 | return null;
|
| 92 | }
|
| 93 |
|
| 94 | /**
|
| 95 | * Returns the size of the recipe area
|
| 96 | */
|
| 97 | public int getRecipeSize()
|
| 98 | {
|
| 99 | return 4;
|
| 100 | }
|
| 101 |
|
| 102 | public ItemStack getRecipeOutput()
|
| 103 | {
|
| 104 | return null;
|
| 105 | }
|
| 106 |
|
| 107 | public ItemStack[] getRemainingItems(InventoryCrafting inv)
|
| 108 | {
|
| 109 | ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
|
| 110 |
|
| 111 | for (int i = 0; i < aitemstack.length; ++i)
|
| 112 | {
|
| 113 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 114 |
|
| 115 | if (itemstack != null && itemstack.getItem().hasContainerItem())
|
| 116 | {
|
| 117 | aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem());
|
| 118 | }
|
| 119 | }
|
| 120 |
|
| 121 | return aitemstack;
|
| 122 | }
|
| 123 | }
|
| 124 |
|