init.lua 932 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. if not minetest.global_exists("portal_cb") then portal_cb = {} end
  2. portal_cb.modpath = minetest.get_modpath("portal_cb")
  3. portal_cb.after_use_callbacks = portal_cb.after_use_callbacks or {}
  4. portal_cb.before_use_callbacks = portal_cb.before_use_callbacks or {}
  5. function portal_cb.call_after_use(params)
  6. for k, v in ipairs(portal_cb.after_use_callbacks) do
  7. v(params)
  8. end
  9. end
  10. function portal_cb.call_before_use(params)
  11. for k, v in ipairs(portal_cb.before_use_callbacks) do
  12. v(params)
  13. end
  14. end
  15. function portal_cb.register_after_use(func)
  16. portal_cb.after_use_callbacks[#portal_cb.after_use_callbacks+1] = func
  17. end
  18. function portal_cb.register_before_use(func)
  19. portal_cb.before_use_callbacks[#portal_cb.before_use_callbacks+1] = func
  20. end
  21. if not portal_cb.run_once then
  22. local c = "portal_cb:core"
  23. local f = portal_cb.modpath .. "/init.lua"
  24. reload.register_file(c, f, false)
  25. portal_cb.run_once = true
  26. end