local api = blockgame.crafting local stack_recipes = {} function api.register_stack_recipe (top_node, bottom_node, result, consumes_top) local consumes_top = consumes_top if consumes_top == nil then consumes_top = true end stack_recipes[top_node] = stack_recipes[top_node] or {} local def = { ["type"] = "stack_two_nodes", index_key = top_node, top_node = top_node, bottom_node = bottom_node, result = result, consumes_top = consumes_top, } table.insert(stack_recipes[top_node], def) table.insert(api.registered_recipes, def) end function api.handle_stack_recipe (recipe, pos, top_node) if top_node.name ~= recipe.top_node then return false end local down = vector.add(pos, vector.new(0, -1, 0)) local below = minetest.get_node(down) if below.name ~= recipe.bottom_node then return false end minetest.remove_node(pos) minetest.set_node(down, recipe.result) return true end function api.handle_placement (pos, new_node, placer, old_node, itemstack, pointed_thing) if stack_recipes[new_node.name] == nil then return false end for _, recipe in pairs(stack_recipes[new_node.name]) do local result = api.handle_stack_recipe(recipe, pos, new_node) if result then return not recipe.consumes_top end end return false end blockgame.register_on_placenode(function (...) return blockgame.crafting.handle_placement(...) end)