gaterealm.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. -- Localize for performance.
  2. local vector_distance = vector.distance
  3. local vector_round = vector.round
  4. local nodes = {
  5. --[[
  6. -- Replace torches with real lanterns in front of the gate.
  7. {pos={x=-9167, y=4103, z=5779}, node={name="xdecor:lantern", param2=1}},
  8. {pos={x=-9167, y=4103, z=5785}, node={name="xdecor:lantern", param2=1}},
  9. -- Add a furnace to the miner's hut.
  10. {pos={x=-9177, y=4176, z=5745}, node={name="redstone_furnace:inactive", param2=3}},
  11. -- Graveyard protector.
  12. {pos={x=-9266, y=4170, z=5724}, node={name="protector:protect3", param2=0}},
  13. -- Farm protectors.
  14. {pos={x=-9082, y=4179, z=5720}, node={name="protector:protect3", param2=0}},
  15. {pos={x=-9139, y=4168, z=5795}, node={name="protector:protect3", param2=0}},
  16. {pos={x=-9199, y=4169, z=5836}, node={name="protector:protect3", param2=0}},
  17. -- Protector in the miner's hut.
  18. {pos={x=-9176, y=4175, z=5745}, node={name="protector:protect3", param2=0}},
  19. -- Spawn protector.
  20. {pos={x=-9223, y=4168, z=5861}, node={name="protector:protect3", param2=0}},
  21. -- Extra signs at spawn.
  22. {pos={x=-9221, y=4169, z=5861}, node={name="signs:sign_wall_wood", param2=2}},
  23. {pos={x=-9221, y=4169, z=5860}, node={name="signs:sign_wall_wood", param2=2}},
  24. -- Extra pillar between Oerkki spawn point and the gate.
  25. {pos={x=-9169, y=4104, z=5782}, node={name="pillars:rackstone_cobble_top", param2=3}},
  26. {pos={x=-9169, y=4103, z=5782}, node={name="walls:rackstone_cobble_noconnect", param2=0}},
  27. {pos={x=-9169, y=4102, z=5782}, node={name="walls:rackstone_cobble_noconnect", param2=0}},
  28. {pos={x=-9169, y=4101, z=5782}, node={name="walls:rackstone_cobble_noconnect", param2=0}},
  29. {pos={x=-9169, y=4100, z=5782}, node={name="pillars:rackstone_cobble_bottom", param2=3}},
  30. --]]
  31. }
  32. local function rebuild_nodes()
  33. for k, v in ipairs(nodes) do
  34. minetest.set_node(v.pos, v.node)
  35. end
  36. end
  37. local metadata = {
  38. --[[
  39. -- Gate room, protection on floor.
  40. {pos={x=-9174, y=4099, z=5782}, meta={fields={
  41. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  42. owner = "MustTest",
  43. placedate = "2020/02/12 UTC",
  44. rename = "MustTest",
  45. }}},
  46. -- Gate room, protection on ceiling.
  47. {pos={x=-9174, y=4106, z=5782}, meta={fields={
  48. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  49. owner = "MustTest",
  50. placedate = "2020/02/12 UTC",
  51. rename = "MustTest",
  52. }}},
  53. -- Gate protection, left side.
  54. {pos={x=-9165, y=4103, z=5785}, meta={fields={
  55. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  56. owner = "MustTest",
  57. placedate = "2020/02/12 UTC",
  58. rename = "MustTest",
  59. }}},
  60. -- Gate protection, right side.
  61. {pos={x=-9165, y=4103, z=5779}, meta={fields={
  62. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  63. owner = "MustTest",
  64. placedate = "2020/02/12 UTC",
  65. rename = "MustTest",
  66. }}},
  67. -- Poem, left side.
  68. {pos={x=-9172, y=4100, z=5783}, meta={fields={
  69. infotext = "Make your choice, adventurous Stranger,\nStrike the Gate and bide the Danger!",
  70. author = "MustTest",
  71. text = "Make your choice, adventurous Stranger,%nStrike the Gate and bide the Danger!"
  72. }}},
  73. -- Poem, right side.
  74. {pos={x=-9172, y=4100, z=5781}, meta={fields={
  75. infotext = "Or else wonder, till it drives you mad,\nWhat would have followed, if you had.",
  76. author = "MustTest",
  77. text = "Or else wonder, till it drives you mad,%nWhat would have followed, if you had."
  78. }}},
  79. -- Door on the miner's hut.
  80. {pos={x=-9174, y=4175, z=5744}, meta={fields={
  81. state = "1",
  82. }}},
  83. -- Door on the calico stash (safe from Indians!).
  84. {pos={x=-9090, y=4182, z=5869}, meta={fields={
  85. state = "0",
  86. }}},
  87. -- The gateway portal itself.
  88. {pos={x=-9164, y=4101, z=5780}, meta={fields={
  89. obsidian_gateway_success_ew = "yes",
  90. obsidian_gateway_return_gate_ew = "0",
  91. obsidian_gateway_owner_ew = "MustTest",
  92. obsidian_gateway_destination_ew = get_exit_location(),
  93. }}},
  94. -- Gravesite sign, left.
  95. {pos={x=-9265, y=4172, z=5724}, meta={fields={
  96. infotext = "Henry D. Miner\nApril 13, 1821 - October 3, 1890\n\"An ardent Abolitionist, a true Republican, and a determined teetotaler.\"",
  97. author = "MustTest",
  98. text = "Henry D. Miner%nApril 13, 1821 - October 3, 1890%n\"An ardent Abolitionist, a true Republican, and a determined teetotaler.\""
  99. }}},
  100. -- Gravesite sign, right.
  101. {pos={x=-9267, y=4172, z=5724}, meta={fields={
  102. infotext = "Martha Ann Lee Miner\nNovember 2, 1829 - February 19, 1897",
  103. author = "MustTest",
  104. text = "Martha Ann Lee Miner%nNovember 2, 1829 - February 19, 1897"
  105. }}},
  106. -- Spawn sign, left.
  107. {pos={x=-9221, y=4170, z=5861}, meta={fields={
  108. infotext = "Use /spawn to get back here.",
  109. author = "MustTest",
  110. text = "Use /spawn to get back here."
  111. }}},
  112. -- Spawn sign, right.
  113. {pos={x=-9221, y=4170, z=5860}, meta={fields={
  114. infotext = "Use /info to get help.",
  115. author = "MustTest",
  116. text = "Use /info to get help."
  117. }}},
  118. -- Spawn sign, bottom left.
  119. {pos={x=-9221, y=4169, z=5861}, meta={fields={
  120. infotext = "See \"http://arklegacy.duckdns.org\" for important info.",
  121. author = "MustTest",
  122. text = "See \"http://arklegacy.duckdns.org\" for important info."
  123. }}},
  124. -- Spawn sign, bottom right.
  125. {pos={x=-9221, y=4169, z=5860}, meta={fields={
  126. infotext = "Take care, don't rush!",
  127. author = "MustTest",
  128. text = "Take care, don't rush!"
  129. }}},
  130. -- Graveyard protector.
  131. {pos={x=-9266, y=4170, z=5724}, meta={fields={
  132. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  133. owner = "MustTest",
  134. placedate = "2020/02/12 UTC",
  135. rename = "MustTest",
  136. }}},
  137. -- Farm protectors.
  138. {pos={x=-9082, y=4179, z=5720}, meta={fields={
  139. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  140. owner = "MustTest",
  141. placedate = "2020/02/12 UTC",
  142. rename = "MustTest",
  143. }}},
  144. {pos={x=-9139, y=4168, z=5795}, meta={fields={
  145. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  146. owner = "MustTest",
  147. placedate = "2020/02/12 UTC",
  148. rename = "MustTest",
  149. }}},
  150. {pos={x=-9199, y=4169, z=5836}, meta={fields={
  151. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  152. owner = "MustTest",
  153. placedate = "2020/02/12 UTC",
  154. rename = "MustTest",
  155. }}},
  156. -- Protector in the miner's hut.
  157. {pos={x=-9176, y=4175, z=5745}, meta={fields={
  158. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  159. owner = "MustTest",
  160. placedate = "2020/02/12 UTC",
  161. rename = "MustTest",
  162. }}},
  163. -- Spawn protector.
  164. {pos={x=-9223, y=4168, z=5861}, meta={fields={
  165. infotext = "Protection (Owned by <MustTest>!)\nPlaced on 2020/02/12 UTC",
  166. owner = "MustTest",
  167. placedate = "2020/02/12 UTC",
  168. rename = "MustTest",
  169. }}},
  170. --]]
  171. }
  172. local function rebuild_metadata()
  173. for k, v in ipairs(metadata) do
  174. local meta = minetest.get_meta(v.pos)
  175. meta:from_table(v.meta)
  176. end
  177. end
  178. local timers = {
  179. --[[
  180. -- First farm.
  181. {x=-9139, y=4172, z=5796},
  182. {x=-9140, y=4172, z=5796},
  183. -- Hilltop farm.
  184. {x=-9083, y=4183, z=5721},
  185. {x=-9082, y=4183, z=5721},
  186. {x=-9081, y=4183, z=5721},
  187. {x=-9083, y=4183, z=5719},
  188. {x=-9082, y=4183, z=5719},
  189. {x=-9081, y=4183, z=5719},
  190. --]]
  191. }
  192. local function restart_timers()
  193. for k, v in ipairs(timers) do
  194. local timer = minetest.get_node_timer(v)
  195. timer:start(1)
  196. end
  197. end
  198. local function callback(blockpos, action, calls_remaining, param)
  199. -- We don't do anything until the last callback.
  200. if calls_remaining ~= 0 then
  201. return
  202. end
  203. -- Check if there was an error on the LAST call.
  204. -- Note: this will usually fail if the area to emerge intersects the map edge.
  205. -- But usually we don't try to do that, here.
  206. if action == core.EMERGE_CANCELLED or action == core.EMERGE_ERRORED then
  207. return
  208. end
  209. -- Locate all nodes with metadata.
  210. local minp = table.copy(rc.get_realm_data("midfeld").minp)
  211. local maxp = table.copy(rc.get_realm_data("midfeld").maxp)
  212. local pos_metas = minetest.find_nodes_with_meta(minp, maxp)
  213. -- Locate all bones and load their meta into memory.
  214. local bones = {}
  215. for k, v in ipairs(pos_metas) do
  216. local node = minetest.get_node(v)
  217. if node.name == "bones:bones" then
  218. local meta = minetest.get_meta(v)
  219. local data = {}
  220. data.pos = v
  221. data.meta = meta:to_table()
  222. data.node = node
  223. bones[#bones + 1] = data
  224. end
  225. end
  226. -- Place schematic. This overwrites all nodes, but not necessarily their meta.
  227. local schematic = rc.modpath .. "/midfeld.mts"
  228. local pos = {x=-12381, y=4050+400, z=5575}
  229. local replacements = {
  230. --["default:stone_with_tin"] = "moreores:mineral_tin",
  231. }
  232. minetest.place_schematic(pos, schematic, "0", replacements, true, "")
  233. -- Erase all stale metadata.
  234. for k, v in ipairs(pos_metas) do
  235. local meta = minetest.get_meta(v)
  236. meta:from_table(nil)
  237. end
  238. teleports.delete_blocks_from_area(minp, maxp)
  239. city_block.delete_blocks_from_area(minp, maxp)
  240. -- Restore all bones.
  241. for k, v in ipairs(bones) do
  242. local np = vector.add(v.pos, {x=0, y=0, z=0})
  243. minetest.set_node(np, v.node)
  244. minetest.get_meta(np):from_table(v.meta)
  245. minetest.get_node_timer(np):start(10)
  246. end
  247. -- Finally, rebuild the core metadata and node structure.
  248. rebuild_nodes()
  249. rebuild_metadata()
  250. restart_timers()
  251. end
  252. -- This API may be called to completely reset the Outback realm.
  253. -- It will restore the realm's map and metadata.
  254. function serveressentials.rebuild_gaterealm()
  255. local p1 = table.copy(rc.get_realm_data("midfeld").minp)
  256. local p2 = table.copy(rc.get_realm_data("midfeld").maxp)
  257. minetest.emerge_area(p1, p2, callback, {})
  258. end