init.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. local stuff_string =
  7. "default:pick_wood,mobs:meat_mutton 10,torches:torch_floor 10," ..
  8. "tinderbox:tinderbox,clock:calendar,flint_and_steel:flint_and_steel"
  9. -- This is also called when a Survival Challenge is started.
  10. function give_initial_stuff.give(player)
  11. local inv = player:get_inventory()
  12. for _, stack in ipairs(give_initial_stuff.items) do
  13. inv:add_item("main", stack)
  14. end
  15. end
  16. function give_initial_stuff.add(stack)
  17. give_initial_stuff.items[#give_initial_stuff.items + 1] = ItemStack(stack)
  18. end
  19. function give_initial_stuff.clear()
  20. give_initial_stuff.items = {}
  21. end
  22. function give_initial_stuff.add_from_csv(str)
  23. local items = str:split(",")
  24. for _, itemname in ipairs(items) do
  25. give_initial_stuff.add(itemname)
  26. end
  27. end
  28. function give_initial_stuff.set_list(list)
  29. give_initial_stuff.items = list
  30. end
  31. function give_initial_stuff.get_list()
  32. return give_initial_stuff.items
  33. end
  34. if not give_initial_stuff.registered then
  35. give_initial_stuff.add_from_csv(stuff_string)
  36. -- Initial stuff is always given to a new player regardless of server configuration.
  37. minetest.register_on_newplayer(function(...)
  38. give_initial_stuff.give(...)
  39. end)
  40. local c = "give_initial_stuff:core"
  41. local f = give_initial_stuff.modpath .. "/init.lua"
  42. reload.register_file(c, f, false)
  43. give_initial_stuff.registered = true
  44. end