init.lua 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. simplecrafting_lib = {}
  2. simplecrafting_lib.type = {}
  3. local modpath = minetest.get_modpath(minetest.get_current_modname())
  4. dofile(modpath .. "/util.lua")
  5. dofile(modpath .. "/register.lua")
  6. dofile(modpath .. "/craft.lua")
  7. dofile(modpath .. "/inventory.lua")
  8. dofile(modpath .. "/legacy.lua")
  9. dofile(modpath .. "/postprocessing.lua")
  10. dofile(modpath .. "/templates/guide.lua")
  11. dofile(modpath .. "/templates/table.lua")
  12. dofile(modpath .. "/templates/multifurnace.lua")
  13. dofile(modpath .. "/templates/autocraft.lua")
  14. dofile(modpath .. "/templates/craftingtool.lua")
  15. dofile(modpath .. "/templates/player.lua")
  16. if minetest.settings:get_bool("simplecrafting_lib_enable_developer_commands") then
  17. dofile(modpath .. "/saveload/saveload.lua")
  18. end
  19. if minetest.settings:get_bool("simplecrafting_lib_override_default_player_crafting") then
  20. simplecrafting_lib.register_recipe_import_filter(function(legacy_recipe)
  21. if legacy_recipe.input["simplecrafting_lib:heat"] then
  22. return nil, false
  23. elseif legacy_recipe.output and legacy_recipe.output:get_name() == "simplecrafting_lib:heat" then
  24. return nil, false
  25. else
  26. return "player", true
  27. end
  28. end)
  29. simplecrafting_lib.register_postprocessing_callback(function()
  30. -- Wait until all mods are loaded, in case default mod is loaded after simplecrafting_lib.
  31. if minetest.registered_craftitems["default:book_written"] == nil then
  32. -- If default:book_written doesn't exist, don't register these callbacks.
  33. return
  34. end
  35. simplecrafting_lib.register_pre_craft(function(craft_type, recipe, output_stack, source_item_list)
  36. -- screen for the recipe we care about. Note that you can't simply compare `recipe` to the
  37. -- registered recipe, since pre_craft may be called on a modified copy of the registered original
  38. if craft_type ~= "player" or recipe.output == nil or recipe.output:get_name() ~= "default:book_written" then
  39. return
  40. end
  41. -- find the first written book in the source inventory
  42. for k, source_item in ipairs(source_item_list) do
  43. if source_item:get_name() == "default:book_written" then
  44. -- the output book will have the same metadata as the source book
  45. local copymeta = source_item:get_meta():to_table()
  46. output_stack:get_meta():from_table(copymeta)
  47. return
  48. end
  49. end
  50. end)
  51. simplecrafting_lib.register_post_craft(function(craft_type, recipe, output_stack, source_inv, source_listname, destination_inv, destination_listname)
  52. -- screen for the recipes we care about
  53. if craft_type ~= "player" or recipe.output == nil or recipe.output:get_name() ~= "default:book_written" then
  54. return
  55. end
  56. -- add an additional copy of the book into the destination inventory
  57. destination_inv:add_item(destination_listname, output_stack)
  58. end)
  59. end)
  60. simplecrafting_lib.register_player_craft_type("player")
  61. simplecrafting_lib.guide.guide_def["player"] = {
  62. -- This matches the filtering done by the "craftguide" mod
  63. is_recipe_included = function(recipe, player_name)
  64. if minetest.get_item_group(recipe.output:get_name(), "not_in_creative_inventory") > 0 or
  65. minetest.get_item_group(recipe.output:get_name(), "not_in_craft_guide") > 0 then
  66. return false
  67. end
  68. return true
  69. end,
  70. }
  71. end
  72. if minetest.get_modpath("awards") then
  73. simplecrafting_lib.award_crafting = function(player, stack)
  74. -- The API changed at some point.
  75. if awards.players then
  76. awards.increment_item_counter(awards.players[player:get_player_name()], "craft", ItemStack(stack):get_name(), ItemStack(stack):get_count())
  77. elseif awards.notify_craft then
  78. awards.notify_craft(player, stack:get_name(), stack:get_count())
  79. end
  80. end
  81. end