Skip to content

Commit

Permalink
Clean up craft replacements docs
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ouellette authored and sfan5 committed Dec 7, 2019
1 parent 103d9c5 commit 27ce6d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions doc/lua_api.txt
Expand Up @@ -4782,8 +4782,9 @@ Item handling
`{stack1, stack2, stack3, stack4, stack 5, stack 6, stack 7, stack 8, stack 9}`
* `output.item` = `ItemStack`, if unsuccessful: empty `ItemStack`
* `output.time` = a number, if unsuccessful: `0`
* `output.replacements` = list of `ItemStack`s that couldn't be placed in
`decremented_input.items`
* `output.replacements` = List of replacement `ItemStack`s that couldn't be
placed in `decremented_input.items`. Replacements can be placed in
`decremented_input` if the stack of the replaced item has a count of 1.
* `decremented_input` = like `input`
* `minetest.get_craft_recipe(output)`: returns input
* returns last registered recipe for output item (node)
Expand Down
17 changes: 13 additions & 4 deletions src/craftdef.h
Expand Up @@ -113,9 +113,6 @@ struct CraftOutput
Example: If ("bucket:bucket_water", "bucket:bucket_empty") is a
replacement pair, the crafting input slot that contained a water
bucket will contain an empty bucket after crafting.
Note: replacements only work correctly when stack_max of the item
to be replaced is 1. It is up to the mod writer to ensure this.
*/
struct CraftReplacements
{
Expand Down Expand Up @@ -410,10 +407,22 @@ class ICraftDefManager
ICraftDefManager() = default;
virtual ~ICraftDefManager() = default;

// The main crafting function
/**
* The main crafting function.
*
* @param input The input grid.
* @param output CraftOutput where the result is placed.
* @param output_replacements A vector of ItemStacks where replacements are
* placed if they cannot be placed in the input. Replacements can be placed
* in the input if the stack of the replaced item has a count of 1.
* @param decrementInput If true, consume or replace input items.
* @param gamedef
* @return true if a result was found, otherwise false.
*/
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
std::vector<ItemStack> &output_replacements,
bool decrementInput, IGameDef *gamedef) const=0;

virtual std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output,
IGameDef *gamedef, unsigned limit=0) const=0;

Expand Down
2 changes: 1 addition & 1 deletion src/inventorymanager.cpp
Expand Up @@ -861,7 +861,7 @@ void ICraftAction::apply(InventoryManager *mgr,
}

// Put the replacements in the inventory or drop them on the floor, if
// the invenotry is full
// the inventory is full
for (auto &output_replacement : output_replacements) {
if (list_main)
output_replacement = list_main->addItem(output_replacement);
Expand Down

0 comments on commit 27ce6d0

Please sign in to comment.