init.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. if not minetest.global_exists("give_initial_stuff") then give_initial_stuff = {} end
  2. give_initial_stuff.modpath = minetest.get_modpath("give_initial_stuff")
  3. give_initial_stuff.items = give_initial_stuff.items or {}
  4. -- Start items are hardcoded intentionally. The Outback (where new players
  5. -- start on first join) depends on this.
  6. --
  7. -- Purpose of items:
  8. -- 1) wood pick: signals that you're a noob.
  9. -- 2) mutton: signals that this isn't a vegan server.
  10. -- 3) torches: signals that you're expected to go mining where it's dark.
  11. -- 4) tinderbox: signals that you're gonna need to scavenge lights.
  12. -- 5) calendar: signals this server has seasons.
  13. -- 6) flint/steel: your purpose in life is to light trees on fire. Also, your trash. And your pet.
  14. -- 7) compass: signals an element of adventure/exploration.
  15. local stuff_string =
  16. "default:pick_wood,mobs:meat_mutton 10,torches:torch_floor 10," ..
  17. "tinderbox:tinderbox,clock:calendar,flint_and_steel:flint_and_steel,default:compass"
  18. -- This is also called when a Survival Challenge is started.
  19. function give_initial_stuff.give(player)
  20. local inv = player:get_inventory()
  21. for _, stack in ipairs(give_initial_stuff.items) do
  22. inv:add_item("main", stack)
  23. end
  24. end
  25. function give_initial_stuff.add(stack)
  26. give_initial_stuff.items[#give_initial_stuff.items + 1] = ItemStack(stack)
  27. end
  28. function give_initial_stuff.clear()
  29. give_initial_stuff.items = {}
  30. end
  31. function give_initial_stuff.add_from_csv(str)
  32. local items = str:split(",")
  33. for _, itemname in ipairs(items) do
  34. give_initial_stuff.add(itemname)
  35. end
  36. end
  37. function give_initial_stuff.set_list(list)
  38. give_initial_stuff.items = list
  39. end
  40. function give_initial_stuff.get_list()
  41. return give_initial_stuff.items
  42. end
  43. if not give_initial_stuff.registered then
  44. give_initial_stuff.add_from_csv(stuff_string)
  45. -- Initial stuff is always given to a new player regardless of server configuration.
  46. minetest.register_on_newplayer(function(...)
  47. give_initial_stuff.give(...)
  48. end)
  49. local c = "give_initial_stuff:core"
  50. local f = give_initial_stuff.modpath .. "/init.lua"
  51. reload.register_file(c, f, false)
  52. give_initial_stuff.registered = true
  53. end