outback.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. -- Hardcoded positions of the outback gates, indexed by the name of the realm
  2. -- they're supposed to lead to.
  3. serveressentials.outback_gates = {
  4. overworld = {pos={x=-9186, y=4501, z=5830}, dir="ew"},
  5. stoneworld = {pos={x=-9162, y=4501, z=5823}, dir="ew"},
  6. channelwood = {pos={x=-9186, y=4501, z=5823}, dir="ew"},
  7. jarkati = {pos={x=-9168, y=4501, z=5820}, dir="ns"},
  8. naraxen = {pos={x=-9183, y=4501, z=5836}, dir="ns"},
  9. ariba = {pos={x=-9168, y=4501, z=5836}, dir="ns"},
  10. }
  11. function serveressentials.get_gate(realm)
  12. local data = serveressentials.outback_gates[realm]
  13. if data then
  14. return data
  15. end
  16. -- Use the overworld gate as fallback.
  17. return serveressentials.outback_gates["overworld"]
  18. end
  19. -- Shall return a list of the names of realms the Outback links to.
  20. function serveressentials.get_realm_names()
  21. local t = {}
  22. for k, v in pairs(serveressentials.outback_gates) do
  23. t[#t + 1] = k
  24. end
  25. return t
  26. end
  27. local WEBADDR = minetest.settings:get("server_address")
  28. -- Localize for performance.
  29. local vector_distance = vector.distance
  30. local vector_round = vector.round
  31. -- Called by the protector mod to determine if a protector can be placed here,
  32. -- with respect to the Outback gateway's current exit location.
  33. local PROTECTOR_DISTANCE_FROM_EXIT = 50
  34. function serveressentials.protector_can_place(pos, realm)
  35. local p2 = minetest.string_to_pos(serveressentials.get_exit_location(realm))
  36. if vector_distance(pos, p2) > PROTECTOR_DISTANCE_FROM_EXIT then
  37. return true
  38. end
  39. return false
  40. end
  41. function serveressentials.get_exit_location(realm)
  42. local meta = serveressentials.modstorage
  43. local s = meta:get_string("outback_exit_location_" .. realm)
  44. -- Backward compatibility.
  45. if realm == "overworld" then
  46. if s == "" then
  47. s = meta:get_string("outback_exit_location")
  48. end
  49. end
  50. if s ~= "" then
  51. local p = minetest.string_to_pos(s)
  52. if p then
  53. return s
  54. end
  55. end
  56. -- Any realm, not 'overworld', that hasn't been initialized yet.
  57. -- Find a new spawn location.
  58. if s == "" then
  59. randspawn.find_new_spawn(false, realm)
  60. end
  61. -- Fallback.
  62. -- If we weren't initialized (s == ""), the exit location should be updated
  63. -- momentarilly as a result of the 'find_new_spawn' call.
  64. return "(0,-7,0)"
  65. end
  66. function serveressentials.get_current_exit_location(realm)
  67. local gate = serveressentials.get_gate(realm)
  68. local m2 = minetest.get_meta(gate.pos)
  69. local s2 = m2:get_string("obsidian_gateway_destination_" .. gate.dir)
  70. return s2
  71. end
  72. function serveressentials.update_exit_location(pos, realm)
  73. pos = vector_round(pos)
  74. -- Update the location stored in mod-storage.
  75. local meta = serveressentials.modstorage
  76. local s = minetest.pos_to_string(pos)
  77. meta:set_string("outback_exit_location_" .. realm, s)
  78. -- Also need to update the gate itself, right away.
  79. local gate = serveressentials.get_gate(realm)
  80. local m2 = minetest.get_meta(gate.pos)
  81. m2:set_string("obsidian_gateway_destination_" .. gate.dir, s)
  82. -- Make sure there's a return gate entity, in lieu of an actual gate.
  83. obsidian_gateway.create_portal_entity(vector.offset(pos, 0, 7, 0), {
  84. target = obsidian_gateway.get_gate_player_spawn_pos(gate.pos, gate.dir),
  85. })
  86. end
  87. local nodes = {
  88. -- Add a chair to the miner's hut.
  89. {pos={x=-9177, y=4576, z=5745}, node={name="xdecor:chair", param2=3}},
  90. -- Graveyard protector.
  91. {pos={x=-9266, y=4570, z=5724}, node={name="protector:protect3", param2=0}},
  92. -- Farm protectors.
  93. {pos={x=-9082, y=4579, z=5720}, node={name="protector:protect3", param2=0}},
  94. {pos={x=-9139, y=4568, z=5795}, node={name="protector:protect3", param2=0}},
  95. {pos={x=-9199, y=4569, z=5836}, node={name="protector:protect3", param2=0}},
  96. -- Protector in the miner's hut.
  97. {pos={x=-9176, y=4575, z=5745}, node={name="protector:protect3", param2=0}},
  98. -- Spawn protectors.
  99. {pos={x=-9223, y=4567, z=5861}, node={name="protector:protect", param2=0}},
  100. {pos={x=-9228, y=4572, z=5851}, node={name="protector:protect", param2=0}},
  101. {pos={x=-9227, y=4572, z=5861}, node={name="protector:protect", param2=0}},
  102. -- Bridge protectors.
  103. {pos={x=-9227, y=4572, z=5833}, node={name="protector:protect", param2=0}},
  104. {pos={x=-9228, y=4572, z=5841}, node={name="protector:protect", param2=0}},
  105. -- Extra signs at spawn.
  106. {pos={x=-9221, y=4569, z=5861}, node={name="signs:sign_wall_brass", param2=2}},
  107. {pos={x=-9221, y=4569, z=5860}, node={name="signs:sign_wall_brass", param2=2}},
  108. {pos={x=-9221, y=4570, z=5861}, node={name="signs:sign_wall_brass", param2=2}},
  109. {pos={x=-9221, y=4570, z=5860}, node={name="signs:sign_wall_brass", param2=2}},
  110. -- Extra pillar between Oerkki spawn point and the gate.
  111. --[[
  112. {pos={x=-9169, y=4504, z=5782}, node={name="pillars:rackstone_cobble_top", param2=3}},
  113. {pos={x=-9169, y=4503, z=5782}, node={name="walls:rackstone_cobble_noconnect", param2=0}},
  114. {pos={x=-9169, y=4502, z=5782}, node={name="walls:rackstone_cobble_noconnect", param2=0}},
  115. {pos={x=-9169, y=4501, z=5782}, node={name="walls:rackstone_cobble_noconnect", param2=0}},
  116. {pos={x=-9169, y=4500, z=5782}, node={name="pillars:rackstone_cobble_bottom", param2=3}},
  117. --]]
  118. -- Beacon protectors.
  119. {pos={x=-9176, y=4591, z=5745}, node={name="protector:protect", param2=0}},
  120. {pos={x=-9176, y=4585, z=5745}, node={name="protector:protect", param2=0}},
  121. -- Signs in miner's hut.
  122. {pos={x=-9177, y=4577, z=5744}, node={name="signs:sign_wall_wood", param2=3}},
  123. {pos={x=-9177, y=4576, z=5744}, node={name="signs:sign_wall_wood", param2=3}},
  124. {pos={x=-9177, y=4577, z=5745}, node={name="signs:sign_wall_wood", param2=3}},
  125. {pos={x=-9175, y=4577, z=5746}, node={name="signs:sign_wall_wood", param2=4}},
  126. {pos={x=-9175, y=4576, z=5746}, node={name="signs:sign_wall_wood", param2=4}},
  127. -- Sign in the "fake gate" in the Oerkki guardroom.
  128. {pos={x=-9164, y=4503, z=5782}, node={name="signs:sign_wall_wood", param2=2}},
  129. }
  130. local function rebuild_nodes()
  131. for k, v in ipairs(nodes) do
  132. minetest.set_node(v.pos, v.node)
  133. end
  134. end
  135. local OWNERNAME = minetest.settings:get("name") or "singleplayer"
  136. local metadata = {
  137. --[[
  138. -- Gate room, protection on floor.
  139. {pos={x=-9174, y=4099, z=5782}, meta={fields={
  140. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  141. owner = OWNERNAME,
  142. placedate = "2020/02/12 UTC",
  143. rename = OWNERNAME,
  144. }}},
  145. -- Gate room, protection on ceiling.
  146. {pos={x=-9174, y=4106, z=5782}, meta={fields={
  147. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  148. owner = OWNERNAME,
  149. placedate = "2020/02/12 UTC",
  150. rename = OWNERNAME,
  151. }}},
  152. -- Gate protection, left side.
  153. {pos={x=-9165, y=4103, z=5785}, meta={fields={
  154. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  155. owner = OWNERNAME,
  156. placedate = "2020/02/12 UTC",
  157. rename = OWNERNAME,
  158. }}},
  159. -- Gate protection, right side.
  160. {pos={x=-9165, y=4103, z=5779}, meta={fields={
  161. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  162. owner = OWNERNAME,
  163. placedate = "2020/02/12 UTC",
  164. rename = OWNERNAME,
  165. }}},
  166. -- Poem, left side.
  167. {pos={x=-9172, y=4100, z=5783}, meta={fields={
  168. infotext = "Make your choice, adventurous Stranger,\nStrike the Gate and bide the Danger!",
  169. author = OWNERNAME,
  170. text = "Make your choice, adventurous Stranger,%nStrike the Gate and bide the Danger!"
  171. }}},
  172. -- Poem, right side.
  173. {pos={x=-9172, y=4100, z=5781}, meta={fields={
  174. infotext = "Or else wonder, till it drives you mad,\nWhat would have followed, if you had.",
  175. author = OWNERNAME,
  176. text = "Or else wonder, till it drives you mad,%nWhat would have followed, if you had."
  177. }}},
  178. --]]
  179. -- Door on the miner's hut.
  180. {pos={x=-9174, y=4575, z=5744}, meta={fields={
  181. state = "1",
  182. }}},
  183. -- Door on the calico stash (safe from Indians!).
  184. {pos={x=-9090, y=4582, z=5869}, meta={fields={
  185. state = "0",
  186. }}},
  187. -- Gate meta now added dynamically. No more hardcoding.
  188. --[[
  189. -- Door portal to Overworld.
  190. {pos=serveressentials.get_gate("overworld").pos,
  191. is_gate=true,
  192. meta={fields={
  193. obsidian_gateway_success_ew = "yes",
  194. obsidian_gateway_return_gate_ew = "0",
  195. obsidian_gateway_owner_ew = OWNERNAME,
  196. obsidian_gateway_destination_ew = serveressentials.get_exit_location("overworld"),
  197. }}},
  198. -- Portal to Dead Seabed.
  199. {pos=serveressentials.get_gate("stoneworld").pos,
  200. is_gate=true,
  201. meta={fields={
  202. obsidian_gateway_success_ew = "yes",
  203. obsidian_gateway_return_gate_ew = "0",
  204. obsidian_gateway_owner_ew = OWNERNAME,
  205. obsidian_gateway_destination_ew = serveressentials.get_exit_location("stoneworld"),
  206. }}},
  207. --]]
  208. -- Gravesite sign, left.
  209. {pos={x=-9265, y=4572, z=5724}, meta={fields={
  210. infotext = "Henry D. Miner\nApril 13, 1821 - October 3, 1890\n\"An ardent Abolitionist, a true Republican, and a determined teetotaler.\"",
  211. author = OWNERNAME,
  212. text = "Henry D. Miner%nApril 13, 1821 - October 3, 1890%n\"An ardent Abolitionist, a true Republican, and a determined teetotaler.\""
  213. }}},
  214. -- Gravesite sign, right.
  215. {pos={x=-9267, y=4572, z=5724}, meta={fields={
  216. infotext = "Martha Ann Lee Miner\nNovember 2, 1829 - February 19, 1897",
  217. author = OWNERNAME,
  218. text = "Martha Ann Lee Miner%nNovember 2, 1829 - February 19, 1897"
  219. }}},
  220. -- Spawn sign, left.
  221. {pos={x=-9221, y=4570, z=5861}, meta={fields={
  222. infotext = "Use /spawn to get back here.",
  223. author = OWNERNAME,
  224. text = "Use /spawn to get back here."
  225. }}},
  226. -- Spawn sign, right.
  227. {pos={x=-9221, y=4570, z=5860}, meta={fields={
  228. infotext = "Use /info to get help.",
  229. author = OWNERNAME,
  230. text = "Use /info to get help."
  231. }}},
  232. -- Spawn sign, bottom left.
  233. {pos={x=-9221, y=4569, z=5861}, meta={fields={
  234. infotext = "See \"http://" .. WEBADDR .. "\" for important info.",
  235. author = OWNERNAME,
  236. text = "See \"http://" .. WEBADDR .. "\" for important info."
  237. }}},
  238. -- Spawn sign, bottom right.
  239. {pos={x=-9221, y=4569, z=5860}, meta={fields={
  240. infotext = "Take care, don't rush!",
  241. author = OWNERNAME,
  242. text = "Take care, don't rush!"
  243. }}},
  244. -- Sign in the "fake gate" in the Oerkki guardroom.
  245. {pos={x=-9164, y=4503, z=5782}, meta={fields={
  246. infotext = "This is not the portal you are looking for.",
  247. author = OWNERNAME,
  248. text = "This is not the portal you are looking for."
  249. }}},
  250. -- More signs.
  251. {pos={x=-9174, y=4502, z=5772}, meta={fields={
  252. infotext = "The Guardroom",
  253. author = OWNERNAME,
  254. text = "The Guardroom"
  255. }}},
  256. {pos={x=-9174, y=4502, z=5792}, meta={fields={
  257. infotext = "The Guardroom",
  258. author = OWNERNAME,
  259. text = "The Guardroom"
  260. }}},
  261. -- Graveyard protector.
  262. {pos={x=-9266, y=4570, z=5724}, meta={fields={
  263. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  264. owner = OWNERNAME,
  265. placedate = "2020/02/12 UTC",
  266. rename = OWNERNAME,
  267. }}},
  268. -- Farm protectors.
  269. {pos={x=-9082, y=4579, z=5720}, meta={fields={
  270. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  271. owner = OWNERNAME,
  272. placedate = "2020/02/12 UTC",
  273. rename = OWNERNAME,
  274. }}},
  275. {pos={x=-9139, y=4568, z=5795}, meta={fields={
  276. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  277. owner = OWNERNAME,
  278. placedate = "2020/02/12 UTC",
  279. rename = OWNERNAME,
  280. }}},
  281. {pos={x=-9199, y=4569, z=5836}, meta={fields={
  282. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  283. owner = OWNERNAME,
  284. placedate = "2020/02/12 UTC",
  285. rename = OWNERNAME,
  286. }}},
  287. -- Protector in the miner's hut.
  288. {pos={x=-9176, y=4575, z=5745}, meta={fields={
  289. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  290. owner = OWNERNAME,
  291. placedate = "2020/02/12 UTC",
  292. rename = OWNERNAME,
  293. }}},
  294. -- Spawn cave protectors.
  295. {pos={x=-9223, y=4567, z=5861}, meta={fields={
  296. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  297. owner = OWNERNAME,
  298. placedate = "2020/02/12 UTC",
  299. rename = OWNERNAME,
  300. }}},
  301. {pos={x=-9228, y=4572, z=5851}, meta={fields={
  302. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  303. owner = OWNERNAME,
  304. placedate = "2020/02/12 UTC",
  305. rename = OWNERNAME,
  306. }}},
  307. {pos={x=-9227, y=4572, z=5861}, meta={fields={
  308. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  309. owner = OWNERNAME,
  310. placedate = "2020/02/12 UTC",
  311. rename = OWNERNAME,
  312. }}},
  313. -- Bridge protectors.
  314. {pos={x=-9227, y=4572, z=5833}, meta={fields={
  315. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  316. owner = OWNERNAME,
  317. placedate = "2020/02/12 UTC",
  318. rename = OWNERNAME,
  319. }}},
  320. {pos={x=-9228, y=4572, z=5841}, meta={fields={
  321. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  322. owner = OWNERNAME,
  323. placedate = "2020/02/12 UTC",
  324. rename = OWNERNAME,
  325. }}},
  326. -- Beacon protectors (over miners' hut).
  327. {pos={x=-9176, y=4585, z=5745}, meta={fields={
  328. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2024/05/26 UTC",
  329. owner = OWNERNAME,
  330. placedate = "2024/05/26 UTC",
  331. rename = OWNERNAME,
  332. }}},
  333. {pos={x=-9176, y=4591, z=5745}, meta={fields={
  334. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2024/05/26 UTC",
  335. owner = OWNERNAME,
  336. placedate = "2024/05/26 UTC",
  337. rename = OWNERNAME,
  338. }}},
  339. -- Signs in miner's hut.
  340. {pos={x=-9177, y=4577, z=5744}, meta={fields={
  341. infotext = "Find the Dimensional Gate at the bottom of this rope.\nThe gate is guarded.\nPrepare for combat!",
  342. author = OWNERNAME,
  343. text = "Find the Dimensional Gate at the bottom of this rope.%nThe gate is guarded.%nPrepare for combat!"
  344. }}},
  345. {pos={x=-9177, y=4577, z=5745}, meta={fields={
  346. infotext = "If you skipped reading /info, be sure to read it now.\nIf the rope doesn't go all the way, punch the end to fix.",
  347. author = OWNERNAME,
  348. text = "If you skipped reading /info, be sure to read it now.%nIf the rope doesn't go all the way, punch the end to fix."
  349. }}},
  350. {pos={x=-9177, y=4576, z=5744}, meta={fields={
  351. infotext = "There is NO WAY BACK BUT DEATH.",
  352. author = OWNERNAME,
  353. text = "There is NO WAY BACK BUT DEATH."
  354. }}},
  355. {pos={x=-9175, y=4577, z=5746}, meta={fields={
  356. infotext = "I hope, for your sake, you brought a bed and mutton.\nIf you didn't bring a bed, you'll wish you had ...\nAnd you'll find yourself standing in morde poo.",
  357. author = OWNERNAME,
  358. text = "I hope, for your sake, you brought a bed and mutton.%nIf you didn't bring a bed, you'll wish you had ...%nAnd you'll find yourself standing in morde poo."
  359. }}},
  360. {pos={x=-9175, y=4576, z=5746}, meta={fields={
  361. infotext = "Fortune favors the bold. Death finds the stupid.\nUsing a gate at night is stupid.\nDon't be that guy.",
  362. author = OWNERNAME,
  363. text = "Fortune favors the bold. Death finds the stupid.%nUsing a gate at night is stupid.%nDon't be that guy."
  364. }}},
  365. -- Table sign in the 2024 Outback Gateroom.
  366. {pos={x=-9174, y=4501, z=5828}, meta={fields={
  367. infotext = "Make your choice, adventurous Stranger,\nStrike a Door and bide the Danger!\nOr else wonder, till it drives you mad,\nWhat would have followed, if you had.\n---- C.S. Lewis (modified)",
  368. author = OWNERNAME,
  369. text = "Make your choice, adventurous Stranger,%nStrike a Door and bide the Danger!%nOr else wonder, till it drives you mad,%nWhat would have followed, if you had.%n---- C.S. Lewis (modified)"
  370. }}},
  371. }
  372. -- Dynamically add metadata for gates based on the gate list.
  373. local function get_gate_meta()
  374. local metaout = {}
  375. for realmname, v in pairs(serveressentials.outback_gates) do
  376. --print(dump(serveressentials.get_exit_location(realmname)))
  377. table.insert(metaout, {
  378. pos = v.pos,
  379. is_gate = true,
  380. meta = {
  381. fields = {
  382. ["obsidian_gateway_success_" .. v.dir] = "yes",
  383. ["obsidian_gateway_return_gate_" .. v.dir] = "0",
  384. ["obsidian_gateway_owner_" .. v.dir] = OWNERNAME,
  385. ["obsidian_gateway_destination_" .. v.dir] = serveressentials.get_exit_location(realmname),
  386. }
  387. }
  388. })
  389. end
  390. return metaout
  391. end
  392. local function rebuild_metadata(metain)
  393. -- For getting rid of the fence blocks in opened gates.
  394. -- Needed else portal liquid won't spawn.
  395. local function erase(targets)
  396. for i = 1, #targets, 1 do
  397. if minetest.get_node(targets[i]).name == "default:fence_wood" then
  398. minetest.set_node(targets[i], {name="air"})
  399. end
  400. end
  401. end
  402. for k, v in ipairs(metain) do
  403. local meta = minetest.get_meta(v.pos)
  404. meta:from_table(v.meta)
  405. if v.is_gate then
  406. if v.meta.fields.obsidian_gateway_destination_ew then
  407. erase(obsidian_gateway.door_positions(v.pos, false))
  408. obsidian_gateway.spawn_liquid(v.pos, false, false, true)
  409. elseif v.meta.fields.obsidian_gateway_destination_ns then
  410. erase(obsidian_gateway.door_positions(v.pos, true))
  411. obsidian_gateway.spawn_liquid(v.pos, true, false, true)
  412. end
  413. end
  414. end
  415. end
  416. local timers = {
  417. -- First farm.
  418. {x=-9139, y=4172, z=5796},
  419. {x=-9140, y=4172, z=5796},
  420. -- Hilltop farm.
  421. {x=-9083, y=4183, z=5721},
  422. {x=-9082, y=4183, z=5721},
  423. {x=-9081, y=4183, z=5721},
  424. {x=-9083, y=4183, z=5719},
  425. {x=-9082, y=4183, z=5719},
  426. {x=-9081, y=4183, z=5719},
  427. }
  428. local function restart_timers()
  429. for k, v in ipairs(timers) do
  430. local timer = minetest.get_node_timer(vector.add(v, {x=0, y=400, z=0}))
  431. timer:start(1)
  432. end
  433. end
  434. -- Find outback surface under sunlight.
  435. local function find_ground(pos)
  436. local n1 = minetest.get_node(pos)
  437. local p2 = vector.offset(pos, 0, -1, 0)
  438. local n2 = minetest.get_node(p2)
  439. local count = 0
  440. while n2.name == "air" and count < 32 do
  441. pos = p2
  442. n1 = minetest.get_node(pos)
  443. p2 = vector.offset(pos, 0, -1, 0)
  444. n2 = minetest.get_node(p2)
  445. count = count + 1
  446. end
  447. if n2.name == "rackstone:cobble" and n1.name == "air" then
  448. if (minetest.get_node_light(pos, 0.5)) or 0 == 15 then
  449. return pos
  450. end
  451. end
  452. end
  453. local function place_random_farms(minp, maxp)
  454. for count = 1, 50 do
  455. local p = {
  456. x = math.random(minp.x + 10, maxp.x - 10),
  457. y = maxp.y,
  458. z = math.random(minp.z + 10, maxp.z - 10),
  459. }
  460. local g = find_ground(p)
  461. if g then
  462. -- Check corners.
  463. local c1 = find_ground(vector.offset(g, -2, 16, -2))
  464. local c2 = find_ground(vector.offset(g, 2, 16, -2))
  465. local c3 = find_ground(vector.offset(g, -2, 16, 2))
  466. local c4 = find_ground(vector.offset(g, 2, 16, 2))
  467. local b1, b2, b3, b4 = false, false, false, false
  468. -- Make sure ground is mostly flat.
  469. if c1 and math.abs(c1.y - g.y) < 2 then b1 = true end
  470. if c2 and math.abs(c2.y - g.y) < 2 then b2 = true end
  471. if c3 and math.abs(c3.y - g.y) < 2 then b3 = true end
  472. if c4 and math.abs(c4.y - g.y) < 2 then b4 = true end
  473. -- Can't be protected. This relies on protectors and protector meta being
  474. -- set *before* we place the farms!
  475. if minetest.test_protection(c1, "") then b1 = false end
  476. if minetest.test_protection(c2, "") then b2 = false end
  477. if minetest.test_protection(c3, "") then b3 = false end
  478. if minetest.test_protection(c4, "") then b4 = false end
  479. if b1 and b2 and b3 and b4 then
  480. local schematic = rc.modpath .. "/outback_small_farm.mts"
  481. local d = vector.offset(g, -2, -2, -2)
  482. minetest.place_schematic(d, schematic, "random", {}, true, "")
  483. end
  484. end
  485. end
  486. end
  487. local OUTBACK_SCHEMS = {
  488. {
  489. schem = rc.modpath .. "/outback_apron.mts",
  490. pos = {x=-9314, y=4141+400, z=5642},
  491. },
  492. {
  493. schem = rc.modpath .. "/outback_map.mts",
  494. pos = {x=-9274, y=4000+400, z=5682},
  495. },
  496. {
  497. schem = rc.modpath .. "/outback_beacon.mts",
  498. pos = {x=-9180, y=4580, z=5741},
  499. },
  500. {
  501. schem = rc.modpath .. "/outback_spawn_cave.mts",
  502. pos = {x=-9233, y=4568, z=5851},
  503. },
  504. {
  505. schem = rc.modpath .. "/outback_bridge.mts",
  506. pos = {x=-9232, y=4570, z=5828},
  507. },
  508. {
  509. schem = rc.modpath .. "/outback_hill_blackstone.mts",
  510. pos = {x=-9195, y=4576, z=5743},
  511. },
  512. {
  513. schem = rc.modpath .. "/outback_blackstone_deposit_1.mts",
  514. pos = {x=-9242, y=4565, z=5844},
  515. },
  516. {
  517. schem = rc.modpath .. "/outback_blackstone_deposit_2.mts",
  518. pos = {x=-9217, y=4560, z=5873},
  519. },
  520. {
  521. schem = rc.modpath .. "/outback_blackstone_deposit_3.mts",
  522. pos = {x=-9088, y=4588, z=5870},
  523. },
  524. {
  525. schem = rc.modpath .. "/outback_blackstone_deposit_4.mts",
  526. pos = {x=-9258, y=4566, z=5706},
  527. },
  528. }
  529. local GATEROOM_SCHEMS = {
  530. {
  531. schem = rc.modpath .. "/outback_gateroom_2024.mts",
  532. pos1 = {x=-9188, y=4498, z=5818},
  533. pos2 = {x=-9160, y=4513, z=5838},
  534. protectors = true,
  535. },
  536. }
  537. local GUARDROOM_SCHEMS = {
  538. {
  539. schem = rc.modpath .. "/outback_guardroom_2024.mts",
  540. pos1 = {x=-9183, y=4498, z=5775},
  541. pos2 = {x=-9159, y=4507, z=5789},
  542. protectors = true,
  543. },
  544. {
  545. schem = rc.modpath .. "/outback_guardroom_floor.mts",
  546. pos1 = {x=-9178, y=4499, z=5777},
  547. pos2 = {x=-9168, y=4499, z=5787},
  548. protectors = false,
  549. },
  550. {
  551. schem = rc.modpath .. "/outback_guardroom_lights.mts",
  552. pos1 = {x=-9178, y=4500, z=5779},
  553. pos2 = {x=-9170, y=4505, z=5785},
  554. protectors = false,
  555. },
  556. {
  557. schem = rc.modpath .. "/outback_doorwall_01.mts",
  558. pos1 = {x=-9176, y=4500, z=5772},
  559. pos2 = {x=-9172, y=4502, z=5774},
  560. protectors = false,
  561. },
  562. {
  563. schem = rc.modpath .. "/outback_doorwall_02.mts",
  564. pos1 = {x=-9176, y=4500, z=5790},
  565. pos2 = {x=-9172, y=4502, z=5792},
  566. protectors = false,
  567. },
  568. }
  569. local function place_schematics(schems)
  570. local replacements = {}
  571. if minetest.registered_nodes["basictrees:acacia_branch"] then
  572. replacements = {
  573. ["stairs:slope_acacia_trunk_outer"] = "basictrees:acacia_branch",
  574. }
  575. end
  576. -- Place all schematics.
  577. for k, v in ipairs(schems) do
  578. minetest.place_schematic(v.pos or v.pos1, v.schem, "0", replacements, true, "")
  579. if v.protectors then
  580. local positions = minetest.find_nodes_in_area(v.pos1, v.pos2, "group:protector")
  581. for k, v in ipairs(positions) do
  582. local meta = minetest.get_meta(v)
  583. meta:from_table({fields={
  584. infotext = "Protection (Owned by <" .. OWNERNAME .. ">!)\nPlaced on 2020/02/12 UTC",
  585. owner = OWNERNAME,
  586. placedate = "2024/06/04 UTC",
  587. rename = OWNERNAME,
  588. }})
  589. end
  590. end
  591. end
  592. end
  593. serveressentials.place_schematics = place_schematics
  594. serveressentials.OUTBACK_SCHEMS = OUTBACK_SCHEMS
  595. serveressentials.GATEROOM_SCHEMS = GATEROOM_SCHEMS
  596. serveressentials.GUARDROOM_SCHEMS = GUARDROOM_SCHEMS
  597. local function callback(blockpos, action, calls_remaining, param)
  598. -- We don't do anything until the last callback.
  599. if calls_remaining ~= 0 then
  600. return
  601. end
  602. -- Check if there was an error on the LAST call.
  603. -- Note: this will usually fail if the area to emerge intersects the map edge.
  604. -- But usually we don't try to do that, here.
  605. if action == core.EMERGE_CANCELLED or action == core.EMERGE_ERRORED then
  606. return
  607. end
  608. -- Locate all nodes with metadata.
  609. local minp = table.copy(rc.get_realm_data("abyss").minp)
  610. local maxp = table.copy(rc.get_realm_data("abyss").maxp)
  611. local pos_metas = minetest.find_nodes_with_meta(minp, maxp)
  612. -- Locate all bones and load their meta into memory.
  613. local bones = {}
  614. for k, v in ipairs(pos_metas) do
  615. local node = minetest.get_node(v)
  616. if node.name == "bones:bones" then
  617. local meta = minetest.get_meta(v)
  618. local data = {}
  619. data.pos = v
  620. data.meta = meta:to_table()
  621. data.node = node
  622. bones[#bones + 1] = data
  623. end
  624. end
  625. -- Erase all stale metadata.
  626. for k, v in ipairs(pos_metas) do
  627. local meta = minetest.get_meta(v)
  628. meta:from_table(nil)
  629. end
  630. -- Place schematic. This overwrites all nodes, but not necessarily their meta.
  631. place_schematics(OUTBACK_SCHEMS)
  632. place_schematics(GATEROOM_SCHEMS)
  633. place_schematics(GUARDROOM_SCHEMS)
  634. -- Erase the rope.
  635. for k = 4500, 4577, 1 do
  636. local p = {x=-9177, y=k, z=5746}
  637. minetest.set_node(p, {name="air"})
  638. end
  639. -- Rebuild the rope, with self-constructing nodes.
  640. do
  641. local p = {x=-9177, y=4577, z=5746}
  642. local n = minetest.get_node(p)
  643. if n.name == "air" then
  644. minetest.add_node(p, {name="vines:rope_bottom"})
  645. local meta = minetest.get_meta(p)
  646. meta:set_int("length_remaining", 80)
  647. meta:mark_as_private("length_remaining")
  648. end
  649. end
  650. teleports.delete_blocks_from_area(minp, maxp)
  651. city_block.delete_blocks_from_area(minp, maxp)
  652. beds.delete_public_spawns_from_area(minp, maxp)
  653. -- Restore all bones.
  654. for k, v in ipairs(bones) do
  655. local np = vector.add(v.pos, {x=0, y=0, z=0})
  656. minetest.set_node(np, v.node)
  657. minetest.get_meta(np):from_table(v.meta)
  658. minetest.get_node_timer(np):start(10)
  659. end
  660. -- Finally, rebuild the core metadata and node structure.
  661. rebuild_nodes()
  662. rebuild_metadata(metadata)
  663. rebuild_metadata(get_gate_meta())
  664. restart_timers()
  665. place_random_farms(minp, maxp)
  666. end
  667. -- This API may be called to completely reset the Outback realm.
  668. -- It will restore the realm's map and metadata.
  669. function serveressentials.rebuild_outback()
  670. local p1 = table.copy(rc.get_realm_data("abyss").minp)
  671. local p2 = table.copy(rc.get_realm_data("abyss").maxp)
  672. minetest.emerge_area(p1, p2, callback, {})
  673. end