/** Find recipes excluding one or more recipe types */ public static ItemStack findMatchingRecipeExcluding( InventoryCrafting inv, World world, Class... excluding) { int i = 0; ItemStack itemstack = null; ItemStack itemstack1 = null; int j; List recipes = CraftingManager.getInstance().getRecipeList(); for (j = 0; j < inv.getSizeInventory(); ++j) { ItemStack itemstack2 = inv.getStackInSlot(j); if (itemstack2 != null) { if (i == 0) { itemstack = itemstack2; } if (i == 1) { itemstack1 = itemstack2; } ++i; } } if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable()) { Item item = itemstack.getItem(); int j1 = item.getMaxDamage() - itemstack.getItemDamage(); // getItemDamageForDisplay int k = item.getMaxDamage() - itemstack1.getItemDamage(); int l = j1 + k + item.getMaxDamage() * 5 / 100; int i1 = item.getMaxDamage() - l; if (i1 < 0) { i1 = 0; } return new ItemStack(itemstack.getItem(), 1, i1); } else { for (j = 0; j < recipes.size(); ++j) { IRecipe irecipe = (IRecipe) recipes.get(j); // 1.1.1 Botania fix (try catch) try { if ((!Arrays.asList(excluding).contains(irecipe.getClass())) && irecipe.matches(inv, world)) { return irecipe.getCraftingResult(inv); } } catch (Exception e) { } } return null; } }
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World) { int var3 = 0; ItemStack var4 = null; ItemStack var5 = null; for (int var6 = 0; var6 < par1InventoryCrafting.getSizeInventory(); ++var6) { ItemStack var7 = par1InventoryCrafting.getStackInSlot(var6); if (var7 != null) { if (var3 == 0) { var4 = var7; } if (var3 == 1) { var5 = var7; } ++var3; } } if (var3 == 2 && var4.itemID == var5.itemID && var4.stackSize == 1 && var5.stackSize == 1 && Item.itemsList[var4.itemID].isRepairable()) { Item var13 = Item.itemsList[var4.itemID]; int var14 = var13.getMaxDamage() - var4.getItemDamageForDisplay(); int var8 = var13.getMaxDamage() - var5.getItemDamageForDisplay(); int var9 = var14 + var8 + var13.getMaxDamage() * 5 / 100; int var10 = var13.getMaxDamage() - var9; if (var10 < 0) { var10 = 0; } return new ItemStack(var4.itemID, 1, var10); } else { Iterator var11 = this.recipes.iterator(); IRecipe var12; do { if (!var11.hasNext()) { return null; } var12 = (IRecipe) var11.next(); } while (!var12.matches(par1InventoryCrafting, par2World)); return var12.getCraftingResult(par1InventoryCrafting); } }
public ItemStack getCraftingResult(TileSoulWorkBench soulworkbench) { InventoryCrafting InventoryCraftingSoulWorkBench = soulworkbench.getCraftingInventory(); Iterator var11 = this.recipes.iterator(); IRecipe var12; do { if (!var11.hasNext()) { // this.nSoulEnergyRequired = 0; return null; } var12 = (IRecipe) var11.next(); } while (!var12.matches(InventoryCraftingSoulWorkBench, null)); this.nSoulEnergyRequired = ((SoulWorkBenchShapedRecipes) var12).getCraftingResultSoulEnergy(); return var12.getCraftingResult(InventoryCraftingSoulWorkBench); }
@Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) { if (craftMatrix instanceof InventoryCrafting) { EntityPlayerMP fp; if (player instanceof EntityPlayerMP) fp = (EntityPlayerMP) player; else fp = BukkitContainer.MOD_PLAYER; InventoryCrafting inv = (InventoryCrafting) craftMatrix; Iterator<IRecipe> irec = (Iterator<IRecipe>) CraftingManager.getInstance().recipes.iterator(); IRecipe targ = null; while (irec.hasNext()) { IRecipe r = irec.next(); if (r.matches(inv, player.worldObj)) { targ = r; break; } } if (targ == null) return; Recipe recipe = new BukkitRecipe(targ); InventoryView what = new CraftInventoryView( CraftPlayerCache.getCraftPlayer(fp), new CraftInventoryCrafting(inv, player.inventory), inv.eventHandler); // Should be slot of crafting container, will only be trouble if ever have crafting table with // more than one slot CraftItemEvent ev = new CraftItemEvent(recipe, what, SlotType.CRAFTING, 0, false, false); Bukkit.getPluginManager().callEvent(ev); if (ev.isCancelled()) { // Believe it is too late to do this, this just clears the workbench which has already // happened // if (!(inv.eventHandler instanceof ContainerWorkbench)) return; // ContainerWorkbench cc = (ContainerWorkbench) inv.eventHandler; // InventoryCraftResult iv = (InventoryCraftResult) cc.craftResult; // iv.setInventorySlotContents(0, null); int itemsToRemove = item.stackSize > 0 ? item.stackSize : 1; // Is item in hand (single craft) if ((player.inventory.getItemStack() != null) && (player.inventory.getItemStack().getItem().itemID == item.getItem().itemID)) { itemsToRemove = itemsToRemove - player.inventory.getItemStack().stackSize; player.inventory.setItemStack(null); // Remove it ((EntityPlayerMP) player).updateHeldItem(); } // If item not removed from hand, or not all crafted were removed from hand if (itemsToRemove > 0) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) { if (player.inventory.getStackInSlot(i) != null && player.inventory.getStackInSlot(i).getItem().itemID == item.getItem().itemID) { int stackSize = ((InventoryPlayer) player.inventory).getStackInSlot(i).stackSize; if (stackSize < itemsToRemove) { ((InventoryPlayer) player.inventory).decrStackSize(i, stackSize); itemsToRemove = itemsToRemove - stackSize; } else { ((InventoryPlayer) player.inventory).decrStackSize(i, itemsToRemove); itemsToRemove = 0; } if (itemsToRemove == 0) break; } } } if (itemsToRemove == 0) // Assume we couldn't remove item, so dont give back ingredients { // Add ingredients back for (int i = 0; i < inv.getSizeInventory(); i++) { if (inv.getStackInSlot(i) != null && inv.getStackInSlot(i).stackSize != 0) { ItemStack putBack = inv.getStackInSlot(i).copy(); putBack.stackSize = 1; player.inventory.addItemStackToInventory(putBack); } } } } } }
private boolean hasIngredients() { return currentRecipe != null && currentRecipe.matches(internalInventoryCrafting, worldObj); }
@Override public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player) { EntityPlayerMP pmp = (EntityPlayerMP) player; Container con = pmp.openContainer; if (con instanceof IContainerCraftingPacket) { IContainerCraftingPacket cct = (IContainerCraftingPacket) con; IGridNode node = cct.getNetworkNode(); if (node != null) { IGrid grid = node.getGrid(); if (grid == null) { return; } IStorageGrid inv = grid.getCache(IStorageGrid.class); IEnergyGrid energy = grid.getCache(IEnergyGrid.class); ISecurityGrid security = grid.getCache(ISecurityGrid.class); IInventory craftMatrix = cct.getInventoryByName("crafting"); IInventory playerInventory = cct.getInventoryByName("player"); Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE; if (inv != null && this.recipe != null && security != null) { InventoryCrafting testInv = new InventoryCrafting(new ContainerNull(), 3, 3); for (int x = 0; x < 9; x++) { if (this.recipe[x] != null && this.recipe[x].length > 0) { testInv.setInventorySlotContents(x, this.recipe[x][0]); } } IRecipe r = Platform.findMatchingRecipe(testInv, pmp.worldObj); if (r != null && security.hasPermission(player, SecurityPermissions.EXTRACT)) { ItemStack is = r.getCraftingResult(testInv); if (is != null) { IMEMonitor<IAEItemStack> storage = inv.getItemInventory(); IItemList all = storage.getStorageList(); IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter(cct.getViewCells()); for (int x = 0; x < craftMatrix.getSizeInventory(); x++) { ItemStack patternItem = testInv.getStackInSlot(x); ItemStack currentItem = craftMatrix.getStackInSlot(x); if (currentItem != null) { testInv.setInventorySlotContents(x, currentItem); ItemStack newItemStack = r.matches(testInv, pmp.worldObj) ? r.getCraftingResult(testInv) : null; testInv.setInventorySlotContents(x, patternItem); if (newItemStack == null || !Platform.isSameItemPrecise(newItemStack, is)) { IAEItemStack in = AEItemStack.create(currentItem); if (in != null) { IAEItemStack out = realForFake == Actionable.SIMULATE ? null : Platform.poweredInsert(energy, storage, in, cct.getSource()); if (out != null) { craftMatrix.setInventorySlotContents(x, out.getItemStack()); } else { craftMatrix.setInventorySlotContents(x, null); } currentItem = craftMatrix.getStackInSlot(x); } } } // True if we need to fetch an item for the recipe if (patternItem != null && currentItem == null) { // Grab from network by recipe ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), storage, player.worldObj, r, is, testInv, patternItem, x, all, realForFake, filter); // If that doesn't get it, grab exact items from network (?) // TODO see if this code is necessary if (whichItem == null) { for (int y = 0; y < this.recipe[x].length; y++) { IAEItemStack request = AEItemStack.create(this.recipe[x][y]); if (request != null) { if (filter == null || filter.isListed(request)) { request.setStackSize(1); IAEItemStack out = Platform.poweredExtraction(energy, storage, request, cct.getSource()); if (out != null) { whichItem = out.getItemStack(); break; } } } } } // If that doesn't work, grab from the player's inventory if (whichItem == null && playerInventory != null) { whichItem = extractItemFromPlayerInventory(player, realForFake, patternItem); } craftMatrix.setInventorySlotContents(x, whichItem); } } con.onCraftMatrixChanged(craftMatrix); } } } } } }