minetest.get_craft_result

From Minetest Developer Wiki
Revision as of 11:42, 28 September 2014 by MaxPower (talk | contribs) (→‎See Also)
Jump to navigation Jump to search

Syntax

minetest.get_craft_result(input)

Description

input is a table describing the potential crafting inputs and context. Its fields are:

  • method'normal' or 'cooking' or 'fuel'.
  • width — Width of the recipe. A positive integer (e.g. 3).
  • items — A table of input item stacks, for example: { stack1, stack2, stack3, stack4, stack5, stack6, stack7, stack8, stack9 }

Returns two output tables, output and decremented_input. output has the following fields:

  • item — An ItemStack (empty stack if the call is unsuccessful).
  • time — A number (0 if the call is unsuccessful).

and decremented_input is like input with the recipe inputs removed from the items stacks.

Example

output, decremented_input = minetest.get_craft_result({ method = "normal", width = 1, items = { ItemStack("default:coal_lump 2"), ItemStack("default:stick 2") }})
-- output.item:to_table() = {wear = 0, name = "default:torch", count = 4, metadata = ""}
-- output.time = 0
-- decremented_input.method = "normal"
-- decremented_input.width = 1
-- #decremented_input.items = 2
-- decremented_input.items[1]:to_table() = {wear = 0, name = "default:coal_lump", count = 1, metadata = ""}
-- decremented_input.items[2]:to_table() = {wear = 0, name = "default:stick", count = 1, metadata = ""}

Notes

The example will not work properly if it is called before the recipe(s) have been registered by minetest. To get around this you will need to create a depends.txt with "default" in it. If you get a output of nil for output.item:to_table() this is what is happening.

See Also

minetest.get_craft_recipe(...)
minetest.get_all_craft_recipes(...)
minetest.register_craft(...)