init.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local mode = core.settings:get("helper_mode")
  2. if mode == "devtest" then
  3. -- Provide feedback to script by creating files in world path
  4. core.after(0, function()
  5. io.close(io.open(core.get_worldpath() .. "/startup", "w"))
  6. end)
  7. local function callback(test_ok)
  8. if not test_ok then
  9. io.close(io.open(core.get_worldpath() .. "/test_failure", "w"))
  10. end
  11. io.close(io.open(core.get_worldpath() .. "/done", "w"))
  12. core.request_shutdown("", false, 2)
  13. end
  14. -- If tests are enabled exit when they're done, otherwise exit on player join
  15. if core.settings:get_bool("devtest_unittests_autostart") and core.global_exists("unittests") then
  16. unittests.on_finished = callback
  17. else
  18. core.register_on_joinplayer(function() callback(true) end)
  19. end
  20. elseif mode == "mapgen" then
  21. -- Stress-test mapgen by constantly generating new area
  22. local csize = tonumber(core.settings:get("chunksize")) * core.MAP_BLOCKSIZE
  23. local MINP, MAXP = vector.new(0, -csize, 0), vector.new(csize*3, csize*2, csize)
  24. local DIR = "x"
  25. local pstart = vector.new(0, 0, 0)
  26. local next_, callback
  27. next_ = function(arg)
  28. print("emerging " .. core.pos_to_string(pstart))
  29. core.emerge_area(
  30. vector.add(pstart, MINP), vector.add(pstart, MAXP),
  31. callback, arg
  32. )
  33. end
  34. local trig = {}
  35. callback = function(blockpos, action, calls_rem, n)
  36. if action == core.EMERGE_CANCELLED or action == core.EMERGE_ERRORED then
  37. return
  38. end
  39. if calls_rem <= 20 and not trig[n] then
  40. trig[n] = true
  41. pstart[DIR] = pstart[DIR] + (MAXP[DIR] - MINP[DIR])
  42. next_(n + 1)
  43. end
  44. end
  45. core.after(0, next_, 1)
  46. end