2
0

api.lua 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. spawn = {}
  2. -- provide empty default implementations
  3. function spawn.get_default_pos()
  4. return nil
  5. end
  6. function spawn.add_suitable_biome(biome)
  7. end
  8. -- Callback registration
  9. spawn.registered_on_spawn = {}
  10. function spawn.register_on_spawn(func)
  11. table.insert(spawn.registered_on_spawn, func)
  12. end
  13. -- Logic run on spawn
  14. local use_engine_spawn = minetest.settings:get("static_spawnpoint") or
  15. minetest.settings:get_bool("engine_spawn")
  16. local function on_spawn(player, is_new)
  17. -- Ask all callbacks first
  18. for _, cb in ipairs(spawn.registered_on_spawn) do
  19. if cb(player, is_new) then
  20. return true
  21. end
  22. end
  23. -- Fall back to default spawn
  24. if not use_engine_spawn then
  25. local pos = spawn.get_default_pos()
  26. if pos then
  27. player:set_pos(pos)
  28. return true
  29. end
  30. end
  31. return false
  32. end
  33. minetest.register_on_newplayer(function(player)
  34. on_spawn(player, true)
  35. end)
  36. minetest.register_on_respawnplayer(function(player)
  37. return on_spawn(player, false)
  38. end)