From bd6d4666abe20247437ede28f73955d413fe5e22 Mon Sep 17 00:00:00 2001 From: Novatux Date: Sat, 26 Oct 2013 11:25:28 +0200 Subject: Add a callback: minetest.register_on_craft(itemstack, player, old_craft_grid, craft_inv) and minetest.register_craft_predict(itemstack, player, old_craft_grid, craft_inv) --- builtin/misc_register.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'builtin/misc_register.lua') diff --git a/builtin/misc_register.lua b/builtin/misc_register.lua index f1d816124..aa8399f16 100644 --- a/builtin/misc_register.lua +++ b/builtin/misc_register.lua @@ -230,6 +230,20 @@ function minetest.register_biome(biome) register_biome_raw(biome) end +function minetest.on_craft(itemstack, player, old_craft_list, craft_inv) + for _, func in ipairs(minetest.registered_on_crafts) do + itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack + end + return itemstack +end + +function minetest.craft_predict(itemstack, player, old_craft_list, craft_inv) + for _, func in ipairs(minetest.registered_craft_predicts) do + itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack + end + return itemstack +end + -- Alias the forbidden item names to "" so they can't be -- created via itemstrings (e.g. /give) local name @@ -327,4 +341,6 @@ minetest.registered_on_joinplayers, minetest.register_on_joinplayer = make_regis minetest.registered_on_leaveplayers, minetest.register_on_leaveplayer = make_registration() minetest.registered_on_player_receive_fields, minetest.register_on_player_receive_fields = make_registration_reverse() minetest.registered_on_cheats, minetest.register_on_cheat = make_registration() +minetest.registered_on_crafts, minetest.register_on_craft = make_registration() +minetest.registered_craft_predicts, minetest.register_craft_predict = make_registration() -- cgit v1.2.3