Java Code Examples for net.minecraft.item.crafting.IRecipe#getCraftingResult()
The following examples show how to use
net.minecraft.item.crafting.IRecipe#getCraftingResult() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModHandler.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public static Pair<IRecipe, ItemStack> getRecipeOutput(World world, ItemStack... recipe) { if (recipe == null || recipe.length == 0) return ImmutablePair.of(null, ItemStack.EMPTY); if (world == null) world = DummyWorld.INSTANCE; InventoryCrafting craftingGrid = new InventoryCrafting(new DummyContainer(), 3, 3); for (int i = 0; i < 9 && i < recipe.length; i++) { ItemStack recipeStack = recipe[i]; if (recipeStack != null && !recipeStack.isEmpty()) { craftingGrid.setInventorySlotContents(i, recipeStack); } } for (IRecipe tmpRecipe : CraftingManager.REGISTRY) { if (tmpRecipe.matches(craftingGrid, world)) { ItemStack itemStack = tmpRecipe.getCraftingResult(craftingGrid); return ImmutablePair.of(tmpRecipe, itemStack); } } return ImmutablePair.of(null, ItemStack.EMPTY); }
Example 2
Source File: CraftingManagerCS4.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
public static ItemStack findMatchingRecipe(Iterable<IRecipe> recipes, InventoryCrafting craftMatrix, World worldIn) { for (IRecipe irecipe : recipes) { if (irecipe.matches(craftMatrix, worldIn)) { return irecipe.getCraftingResult(craftMatrix); } } return ItemStack.EMPTY; }
Example 3
Source File: ComputerCraftUtils.java From OpenModsLib with MIT License | 5 votes |
private static void addTurtleForUpgrade(List<ItemStack> result, IRecipe recipe, ItemStack turtle, ItemStack left, ItemStack right) { final InventoryCrafting inv = new InventoryCrafting(DUMMY_CONTAINER, 3, 3); inv.setInventorySlotContents(0, left); inv.setInventorySlotContents(1, turtle); inv.setInventorySlotContents(2, right); final ItemStack upgradedTurtle = recipe.getCraftingResult(inv); if (upgradedTurtle != null) result.add(upgradedTurtle); }
Example 4
Source File: BWCoreStaticReplacementMethodes.java From bartworks with MIT License | 4 votes |
@SuppressWarnings("ALL") public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCrafting, World world) { int i = 0; ItemStack itemstack = null; ItemStack itemstack1 = null; int j; for (j = 0; j < inventoryCrafting.getSizeInventory(); ++j) { ItemStack itemstack2 = inventoryCrafting.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.getItemDamageForDisplay(); int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay(); 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 { IRecipe iPossibleRecipe = null; int index = 0; for (Iterator<IRecipe> it = RECENTLYUSEDRECIPES.iterator(); it.hasNext(); ++index) { IRecipe RECENTLYUSEDRECIPE = it.next(); if (RECENTLYUSEDRECIPE.matches(inventoryCrafting, world)) { iPossibleRecipe = RECENTLYUSEDRECIPE; break; } } if (iPossibleRecipe != null) { RECENTLYUSEDRECIPES.addPrioToNode(index); return iPossibleRecipe.getCraftingResult(inventoryCrafting); } ItemStack stack = null; HashSet<IRecipe> recipeSet = new NonNullWrappedHashSet<>(); List recipeList = CraftingManager.getInstance().getRecipeList(); for (int k = 0; k < recipeList.size(); k++) { recipeSet.add((IRecipe) recipeList.get(k)); } Object[] arr = recipeSet.parallelStream().filter(r -> r.matches(inventoryCrafting, world)).toArray(); if (arr.length == 0) return null; IRecipe recipe = (IRecipe) arr[0]; stack = recipe.getCraftingResult(inventoryCrafting); if (arr.length != 1) return stack; if (stack != null) RECENTLYUSEDRECIPES.addLast(recipe); return stack; } }