| 1 | package net.minecraft.item.crafting;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.entity.passive.EntitySheep;
|
| 6 | import net.minecraft.init.Items;
|
| 7 | import net.minecraft.inventory.InventoryCrafting;
|
| 8 | import net.minecraft.item.EnumDyeColor;
|
| 9 | import net.minecraft.item.ItemArmor;
|
| 10 | import net.minecraft.item.ItemStack;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public class RecipesArmorDyes implements IRecipe
|
| 14 | {
|
| 15 | /**
|
| 16 | * Used to check if a recipe matches current crafting inventory
|
| 17 | */
|
| 18 | public boolean matches(InventoryCrafting inv, World worldIn)
|
| 19 | {
|
| 20 | ItemStack itemstack = null;
|
| 21 | List<ItemStack> list = Lists.<ItemStack>newArrayList();
|
| 22 |
|
| 23 | for (int i = 0; i < inv.getSizeInventory(); ++i)
|
| 24 | {
|
| 25 | ItemStack itemstack1 = inv.getStackInSlot(i);
|
| 26 |
|
| 27 | if (itemstack1 != null)
|
| 28 | {
|
| 29 | if (itemstack1.getItem() instanceof ItemArmor)
|
| 30 | {
|
| 31 | ItemArmor itemarmor = (ItemArmor)itemstack1.getItem();
|
| 32 |
|
| 33 | if (itemarmor.getArmorMaterial() != ItemArmor.ArmorMaterial.LEATHER || itemstack != null)
|
| 34 | {
|
| 35 | return false;
|
| 36 | }
|
| 37 |
|
| 38 | itemstack = itemstack1;
|
| 39 | }
|
| 40 | else
|
| 41 | {
|
| 42 | if (itemstack1.getItem() != Items.dye)
|
| 43 | {
|
| 44 | return false;
|
| 45 | }
|
| 46 |
|
| 47 | list.add(itemstack1);
|
| 48 | }
|
| 49 | }
|
| 50 | }
|
| 51 |
|
| 52 | return itemstack != null && !list.isEmpty();
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * Returns an Item that is the result of this recipe
|
| 57 | */
|
| 58 | public ItemStack getCraftingResult(InventoryCrafting inv)
|
| 59 | {
|
| 60 | ItemStack itemstack = null;
|
| 61 | int[] aint = new int[3];
|
| 62 | int i = 0;
|
| 63 | int j = 0;
|
| 64 | ItemArmor itemarmor = null;
|
| 65 |
|
| 66 | for (int k = 0; k < inv.getSizeInventory(); ++k)
|
| 67 | {
|
| 68 | ItemStack itemstack1 = inv.getStackInSlot(k);
|
| 69 |
|
| 70 | if (itemstack1 != null)
|
| 71 | {
|
| 72 | if (itemstack1.getItem() instanceof ItemArmor)
|
| 73 | {
|
| 74 | itemarmor = (ItemArmor)itemstack1.getItem();
|
| 75 |
|
| 76 | if (itemarmor.getArmorMaterial() != ItemArmor.ArmorMaterial.LEATHER || itemstack != null)
|
| 77 | {
|
| 78 | return null;
|
| 79 | }
|
| 80 |
|
| 81 | itemstack = itemstack1.copy();
|
| 82 | itemstack.stackSize = 1;
|
| 83 |
|
| 84 | if (itemarmor.hasColor(itemstack1))
|
| 85 | {
|
| 86 | int l = itemarmor.getColor(itemstack);
|
| 87 | float f = (float)(l >> 16 & 255) / 255.0F;
|
| 88 | float f1 = (float)(l >> 8 & 255) / 255.0F;
|
| 89 | float f2 = (float)(l & 255) / 255.0F;
|
| 90 | i = (int)((float)i + Math.max(f, Math.max(f1, f2)) * 255.0F);
|
| 91 | aint[0] = (int)((float)aint[0] + f * 255.0F);
|
| 92 | aint[1] = (int)((float)aint[1] + f1 * 255.0F);
|
| 93 | aint[2] = (int)((float)aint[2] + f2 * 255.0F);
|
| 94 | ++j;
|
| 95 | }
|
| 96 | }
|
| 97 | else
|
| 98 | {
|
| 99 | if (itemstack1.getItem() != Items.dye)
|
| 100 | {
|
| 101 | return null;
|
| 102 | }
|
| 103 |
|
| 104 | float[] afloat = EntitySheep.getDyeRgb(EnumDyeColor.byDyeDamage(itemstack1.getMetadata()));
|
| 105 | int l1 = (int)(afloat[0] * 255.0F);
|
| 106 | int i2 = (int)(afloat[1] * 255.0F);
|
| 107 | int j2 = (int)(afloat[2] * 255.0F);
|
| 108 | i += Math.max(l1, Math.max(i2, j2));
|
| 109 | aint[0] += l1;
|
| 110 | aint[1] += i2;
|
| 111 | aint[2] += j2;
|
| 112 | ++j;
|
| 113 | }
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | if (itemarmor == null)
|
| 118 | {
|
| 119 | return null;
|
| 120 | }
|
| 121 | else
|
| 122 | {
|
| 123 | int i1 = aint[0] / j;
|
| 124 | int j1 = aint[1] / j;
|
| 125 | int k1 = aint[2] / j;
|
| 126 | float f3 = (float)i / (float)j;
|
| 127 | float f4 = (float)Math.max(i1, Math.max(j1, k1));
|
| 128 | i1 = (int)((float)i1 * f3 / f4);
|
| 129 | j1 = (int)((float)j1 * f3 / f4);
|
| 130 | k1 = (int)((float)k1 * f3 / f4);
|
| 131 | int lvt_12_3_ = (i1 << 8) + j1;
|
| 132 | lvt_12_3_ = (lvt_12_3_ << 8) + k1;
|
| 133 | itemarmor.setColor(itemstack, lvt_12_3_);
|
| 134 | return itemstack;
|
| 135 | }
|
| 136 | }
|
| 137 |
|
| 138 | /**
|
| 139 | * Returns the size of the recipe area
|
| 140 | */
|
| 141 | public int getRecipeSize()
|
| 142 | {
|
| 143 | return 10;
|
| 144 | }
|
| 145 |
|
| 146 | public ItemStack getRecipeOutput()
|
| 147 | {
|
| 148 | return null;
|
| 149 | }
|
| 150 |
|
| 151 | public ItemStack[] getRemainingItems(InventoryCrafting inv)
|
| 152 | {
|
| 153 | ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
|
| 154 |
|
| 155 | for (int i = 0; i < aitemstack.length; ++i)
|
| 156 | {
|
| 157 | ItemStack itemstack = inv.getStackInSlot(i);
|
| 158 |
|
| 159 | if (itemstack != null && itemstack.getItem().hasContainerItem())
|
| 160 | {
|
| 161 | aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem());
|
| 162 | }
|
| 163 | }
|
| 164 |
|
| 165 | return aitemstack;
|
| 166 | }
|
| 167 | }
|
| 168 |
|