mirror of
https://github.com/minetest/minetest_game.git
synced 2025-06-29 13:20:25 +02:00
Move duplicate recipe from books to default.register_craft_metadata_copy()
This allows mods to easily implement the same behaviour, e.g. for letters.
This commit is contained in:
@ -581,6 +581,40 @@ minetest.register_abm({
|
||||
end
|
||||
})
|
||||
|
||||
--
|
||||
-- Register a craft to copy the metadata of items
|
||||
--
|
||||
|
||||
function default.register_craft_metadata_copy(ingredient, result)
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = result,
|
||||
recipe = {ingredient, result}
|
||||
})
|
||||
|
||||
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
|
||||
if itemstack:get_name() ~= result then
|
||||
return
|
||||
end
|
||||
|
||||
local original
|
||||
local index
|
||||
for i = 1, #old_craft_grid do
|
||||
if old_craft_grid[i]:get_name() == result then
|
||||
original = old_craft_grid[i]
|
||||
index = i
|
||||
end
|
||||
end
|
||||
if not original then
|
||||
return
|
||||
end
|
||||
local copymeta = original:get_meta():to_table()
|
||||
itemstack:get_meta():from_table(copymeta)
|
||||
-- put the book with metadata back in the craft grid
|
||||
craft_inv:set_stack("craft", index, original)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- NOTICE: This method is not an official part of the API yet.
|
||||
|
Reference in New Issue
Block a user