| package ed.enderdeath.mod.AnvilDragon; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import com.google.common.collect.Lists; |
| |
| import net.minecraft.inventory.InventoryCrafting; |
| import net.minecraft.item.ItemStack; |
| import net.minecraft.item.crafting.IRecipe; |
| import net.minecraft.nbt.NBTTagCompound; |
| import net.minecraft.world.IBlockAccess; |
| import net.minecraft.world.World; |
| import net.minecraftforge.common.ForgeHooks; |
| import net.minecraftforge.oredict.OreDictionary; |
| |
| public class TutorielShapedRecipes implements IRecipe |
| |
| { |
| public final int recipeWidth; |
| |
| public final int recipeHeight; |
| |
| public final Object[] recipeItems; |
| |
| private final ItemStack recipeOutput; |
| private boolean copyIngredientNBT; |
| private ContainerDragonAnvil con; |
| |
| public TutorielShapedRecipes(int width, int height, Object[] items, ItemStack output) |
| { |
| this.recipeWidth = width; |
| this.recipeHeight = height; |
| this.recipeItems = items; |
| this.recipeOutput = output; |
| } |
| |
| public ItemStack getRecipeOutput() |
| { |
| return this.recipeOutput; |
| } |
| |
| public ItemStack[] getRemainingItems(InventoryCrafting inv) |
| { |
| ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; |
| for (int i = 0; i < aitemstack.length; ++i) |
| { |
| ItemStack itemstack = inv.getStackInSlot(i); |
| aitemstack* = recipeOutput.getItem().getContainerItem(recipeOutput); |
| } |
| return aitemstack; |
| } |
| |
| |
| |
| |
| |
| public boolean matches(InventoryCrafting inv, World worldIn) |
| { |
| for (int i = 0; i <= con.craftWidth - this.recipeWidth; ++i) |
| { |
| for (int j = 0; j <= con.craftHeigth - this.recipeHeight; ++j) |
| { |
| if (this.checkMatch(inv, i, j, true)) |
| { |
| return true; |
| } |
| if (this.checkMatch(inv, i, j, false)) |
| { |
| return true; |
| } |
| } |
| } |
| return false; |
| } |
| |
| |
| |
| |
| |
| private boolean checkMatch(InventoryCrafting inv, int regionX, int regionY, boolean mirror) |
| { |
| for (int x = 0 ; x < con.craftWidth ; ++x) |
| { |
| for (int y = 0 ; y < con.craftHeigth ; ++y) |
| { |
| int x1 = x - regionX; |
| int y1 = y - regionY; |
| Object patternStack = null; |
| if (x1 >= 0 && y1 >= 0 && x1 < this.recipeWidth && y1 < this.recipeHeight) |
| { |
| if (mirror) |
| patternStack = this.recipeItems[this.recipeWidth - x1 - 1 + y1 * this.recipeWidth]; |
| else |
| patternStack = this.recipeItems[x1 + y1 * this.recipeWidth]; |
| if(patternStack instanceof String) |
| { |
| List <itemstack>stacks = OreDictionary.getOres((String) patternStack); |
| boolean matches = false; |
| for(ItemStack stack : stacks) |
| { |
| if(areItemStacksEquals(stack, inv.getStackInRowAndColumn(x, y))) |
| { |
| matches = true; |
| } |
| } |
| if(!matches) |
| return false; |
| } |
| else if(!areItemStacksEquals((ItemStack) patternStack, inv.getStackInRowAndColumn(x, y))) |
| { |
| return false; |
| } |
| } |
| } |
| } |
| return true; |
| } |
| |
| |
| |
| |
| public static boolean areItemStacksEquals(ItemStack stack1, ItemStack stack2) |
| { |
| if(stack1 == null || stack2 == null) return stack1 == stack2; |
| return stack1.getItem() == stack2.getItem() && (stack1.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack1.getItemDamage() == stack2.getItemDamage()); |
| } |
| |
| |
| |
| |
| public ItemStack getCraftingResult(InventoryCrafting inv) |
| { |
| ItemStack itemstack = this.getRecipeOutput().copy(); |
| if (this.copyIngredientNBT) |
| { |
| for (int i = 0; i < inv.getSizeInventory(); ++i) |
| { |
| ItemStack itemstack1 = inv.getStackInSlot(i); |
| if (itemstack1 != null && itemstack1.hasTagCompound()) |
| { |
| itemstack.setTagCompound((NBTTagCompound)itemstack1.getTagCompound().copy()); |
| } |
| } |
| } |
| return itemstack; |
| } |
| |
| |
| |
| |
| public int getRecipeSize() |
| { |
| return this.recipeWidth * this.recipeHeight; |
| } |
| |
| |
| |
| |
| public TutorielShapedRecipes setCopyIngredientNBT() |
| { |
| this.copyIngredientNBT = true; |
| return this; |
| } |
| |
| } |
| |
| ```</itemstack> |