Difference between revisions of "minetest.get craft result"

From Minetest Developer Wiki
Jump to navigation Jump to search
m (Add sort key)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
{{UnofficialLua}}
 
{{DISPLAYTITLE:minetest.get_craft_result}}
 
{{DISPLAYTITLE:minetest.get_craft_result}}
== Syntax ==
+
See [https://minetest.gitlab.io/minetest/minetest-namespace-reference/ minetest.get_craft_result] in the Lua API documentation.
<source>minetest.get_craft_result(input)</source>
 
  
== Description ==
+
== Example ==
<code>input</code> is a table describing the potential crafting inputs and context.  Its fields are:
+
(will only work if the mod is loaded after "default" registers crafting recipes)
 
 
* <code>method</code> — <source enclose="none">'normal'</source> or <source enclose="none">'cooking'</source> or <source enclose="none">'fuel'</source>.
 
* <code>width</code> — Width of the recipe.  A positive integer (e.g. 3).
 
* <code>items</code> — A table of input item stacks, for example: <source enclose="none">{ stack1, stack2, stack3, stack4, stack5, stack6, stack7, stack8, stack9 }</source>
 
 
 
Returns two output tables, <code>output</code> and <code>decremented_input</code>.  <code>output</code> has the following fields:
 
 
 
* <code>item</code> — An [[ItemStack]] (empty stack if the call is unsuccessful).
 
* <code>time</code> — A number (0 if the call is unsuccessful).
 
 
 
and <code>decremented_input</code> is like <code>input</code> with the recipe inputs removed from the <code>items</code> stacks.
 
  
== Example ==
 
 
<source>
 
<source>
 
output, decremented_input = minetest.get_craft_result({ method = "normal", width = 1, items = { ItemStack("default:coal_lump 2"), ItemStack("default:stick 2") }})
 
output, decremented_input = minetest.get_craft_result({ method = "normal", width = 1, items = { ItemStack("default:coal_lump 2"), ItemStack("default:stick 2") }})
Line 28: Line 16:
 
-- decremented_input.items[2]:to_table() = {wear = 0, name = "default:stick", count = 1, metadata = ""}
 
-- decremented_input.items[2]:to_table() = {wear = 0, name = "default:stick", count = 1, metadata = ""}
 
</source>
 
</source>
 
== 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_craft_recipe(...)]] <br>
 
[[minetest.get_all_craft_recipes|minetest.get_all_craft_recipes(...)]] <br>
 
[[minetest.register_craft|minetest.register_craft(...)]]
 
  
 
[[Category:Methods|g]]
 
[[Category:Methods|g]]

Latest revision as of 14:03, 25 October 2022

Mbox warning.png This page contains unofficial, low-quality Lua API documentation and is likely to be outdated or wrong. Do not rely on it!
For the official and up-to-date documentation, see Lua API Documentation.
Mbox warning.png This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information"
If you don't think that this page should be deleted, please explain why on the talk page.

See minetest.get_craft_result in the Lua API documentation.

Example

(will only work if the mod is loaded after "default" registers crafting recipes)

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 = ""}