Advertisement
Guest User

Untitled

a guest
May 23rd, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. mapgen = {}
  2.  
  3. function mapgen:apollo_gen(area, data, pos)--minetest.register_on_generated(function(minp, maxp, seed)
  4.  
  5. --local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  6. --local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
  7. --local data = vm:get_data()
  8.  
  9. --local y1 = maxp.y
  10. --local y0 = minp.y
  11.  
  12. local px = pos.x
  13. local py = pos.y
  14. local pz = pos.z
  15. --fire up the voxel manipulator
  16. local vm = minetest.get_voxel_manip()
  17. local p1 = {x=px-16,y=py-16,z=pz-16}
  18. local p2 = {x=px+16,y=py+16,z=pz+16}
  19.  
  20. pmin, pmax = vm:read_from_map(p1,p2)
  21. local area = VoxelArea:new{MinEdge=pmin, MaxEdge=pmax}
  22. local data = vm:get_data()
  23.  
  24. print("generating APOLLO MODULE")
  25. --moontest node content_ids
  26. local c_dust = minetest.get_content_id("moontest:dust")
  27. local c_bas = minetest.get_content_id("moontest:basalt")
  28. local c_hl = minetest.get_content_id("moontest:hlsource")
  29. local c_msto = minetest.get_content_id("moontest:stone")
  30. local c_vac = minetest.get_content_id("moontest:vacuum")
  31. local c_mair = minetest.get_content_id("moontest:air")
  32. local c_ashield = minetest.get_content_id("moontest:air_shield")
  33. --default node content_ids
  34. local c_sto = minetest.get_content_id("default:stone")
  35. local c_wood = minetest.get_content_id("default:wood")
  36. local c_glass = minetest.get_content_id("default:glass")
  37. local c_sblock = minetest.get_content_id("default:steelblock")
  38. local c_gblock = minetest.get_content_id("default:goldblock")
  39. local c_cblock = minetest.get_content_id("default:copperblock")
  40. --mesecons node content_ids
  41. local c_mesecon = minetest.get_content_id("mesecons:wire_00000000_off")
  42. local c_lamp = minetest.get_content_id("mesecons_lamp:lamp_off")
  43. local c_power = minetest.get_content_id("mesecons_powerplant:power_plant")
  44. --air
  45. local c_air = minetest.get_content_id("air")
  46.  
  47. local yasurf = 0 -- y of above surface node at center of moon
  48. local stable = true -- is ground solid or liquid?
  49. for y = py + 16, py - 10, -1 do
  50. local vi = area:index(px, y, pz)
  51. local c_node = data[vi]
  52. if y == py+16 and c_node ~= c_vac and c_node ~= c_air then -- if top node solid
  53. break
  54. elseif c_node == c_hl then
  55. yasurf = y + 1
  56. stable = false
  57. break
  58. elseif c_node == c_dust or c_node == c_msto or c_node == c_bas then --if first surface node
  59. yasurf = y + 1 --set the position of the surface
  60. break
  61. end
  62. end
  63. yasurf = py
  64. --clear out an area for the apollo module
  65. for x = pmin.x, pmax.x do--px - 13, px + 13 do
  66. for z = pmin.z, pmax.z do--pz - 13, pz + 13 do
  67. for y = yasurf, yasurf + 16 do
  68. local vi = area:index(x, y, z)
  69. data[vi] = c_vac
  70. end
  71. end
  72. end
  73. --add a layer ground beneath of it
  74. for x = px - 15, px + 15 do
  75. for z = pz - 15, pz + 15 do
  76. for y = yasurf - 10, yasurf do
  77. local vi = area:index(x, y, z)
  78. data[vi] = c_msto
  79. end
  80. end
  81. end
  82. --create the module
  83. --start with gold base
  84. for y = yasurf + 4, yasurf + 6 do
  85. for x = px-4, px+4 do
  86. for z = pz - 4, pz + 4 do
  87. local vi = area:index(x, y, z)
  88. data[vi] = c_gblock
  89. end
  90. end
  91. for x = px - 2, px + 2 do
  92. local vi = area:index(x, y, pz + 5)
  93. data[vi] = c_gblock
  94. local vi = area:index(x, y, pz - 5)
  95. data[vi] = c_gblock
  96. end
  97. for z = pz - 2, pz + 2 do
  98. local vi = area:index(px + 5, y, z)
  99. data[vi] = c_gblock
  100. local vi = area:index(px - 5, y, z)
  101. data[vi] = c_gblock
  102. end
  103. end
  104. --create air
  105. for y = yasurf + 7, yasurf + 13 do
  106. for x = px - 3, px + 3 do
  107. for z = pz - 3, pz + 3 do
  108. local vi = area:index(x,y,z)
  109. data[vi] = c_mair
  110. end
  111. end
  112. end
  113. --create cabin
  114. for y = yasurf + 9, yasurf + 10 do
  115. for x = px - 2, px + 2 do
  116. z = pz - 5
  117. local vi = area:index(x,y,z)
  118. data[vi] = c_sblock
  119. z =pz + 5
  120. local vi = area:index(x,y,z)
  121. data[vi] = c_sblock
  122. end
  123. for z = pz - 2, pz + 2 do
  124. x = px - 5
  125. local vi = area:index(x,y,z)
  126. data[vi] = c_sblock
  127. x = px + 5
  128. local vi = area:index(x,y,z)
  129. data[vi] = c_sblock
  130. end
  131. end
  132. for y = yasurf + 8, yasurf + 11 do
  133. for x = px - 3, px + 3 do
  134. z = pz - 4
  135. local vi = area:index(x,y,z)
  136. data[vi] = c_sblock
  137. z =pz + 4
  138. local vi = area:index(x,y,z)
  139. data[vi] = c_sblock
  140. end
  141. for z = pz - 3, pz + 3 do
  142. x = px - 4
  143. local vi = area:index(x,y,z)
  144. data[vi] = c_sblock
  145. x = px + 4
  146. local vi = area:index(x,y,z)
  147. data[vi] = c_sblock
  148. end
  149. end
  150.  
  151. --write the voxel manipulator data back to world
  152. vm:set_data(data)
  153. vm:write_to_map(data)
  154. vm:update_map()
  155. end
  156.  
  157. minetest.register_on_newplayer(function(player)
  158. pos = player:getpos()
  159. mapgen:apollo_gen(area, data, pos)
  160. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement