skybox.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. --Heights for skyboxes
  2. local space_low = 5000
  3. local space_high = 5999
  4. local redsky_low = 6000
  5. local redsky_high = 6999
  6. local player_list = {} -- Holds name of skybox showing for each player
  7. local timer = 0
  8. minetest.register_globalstep(function(dtime)
  9. timer = timer + dtime
  10. if timer < 2 then
  11. return
  12. end
  13. timer = 0
  14. for _, player in pairs(minetest.get_connected_players()) do
  15. local name = player:get_player_name()
  16. local pos = player:get_pos()
  17. local current = player_list[name] or ""
  18. -- Earth
  19. if pos.y < space_low and current ~= "earth" then
  20. local sl = {}
  21. sl.name = "plain_with_clouds_sky"
  22. sl.sky_data = {
  23. sky_color = {
  24. day_sky = "#8cbafa",
  25. day_horizon = "#9bc1f0",
  26. dawn_sky = "#b4bafa",
  27. dawn_horizon = "#d8bae1",
  28. night_sky = "#006aff",
  29. night_horizon = "#4090ff",
  30. indoors = "#646464",
  31. fog_sun_tint = "#E0901F",
  32. fog_moon_tint = "#6E9A65"
  33. },
  34. clouds = true
  35. }
  36. sl.clouds_data = {
  37. gradient_colors = {
  38. { r = 34, g = 204, b = 170 },
  39. { r = 105, g = 208, b = 37 },
  40. { r = 170, g = 204, b = 34 },
  41. { r = 208, g = 195, b = 16 },
  42. { r = 204, g = 187, b = 51 },
  43. { r = 254, g = 174, b = 45 },
  44. { r = 255, g = 68, b = 34 },
  45. { r = 255, g = 102, b = 68 },
  46. { r = 255, g = 153, b = 51 },
  47. { r = 254, g = 174, b = 45 },
  48. { r = 59, g = 12, b = 189 }
  49. },
  50. speed = { x = 2, z = -2 }
  51. }
  52. sl.sun_data = {
  53. visible = true,
  54. sunrise_visible = true
  55. }
  56. skylayer.add_layer(name, sl)
  57. player_list[name] = "earth"
  58. if otherworlds.settings.gravity.enable then
  59. player:set_physics_override({gravity = 1})
  60. end
  61. -- Outerspace
  62. elseif pos.y > space_low and pos.y < space_high and current ~= "space" then
  63. local sl = {}
  64. sl.name = "other_worlds:spaceskybox"
  65. sl.moon_data = {
  66. visible = false,
  67. scale = 0.8
  68. }
  69. sl.sun_data = {
  70. visible = false,
  71. scale = 0.8,
  72. sunrise_visible = false
  73. }
  74. sl.stars_data = {
  75. visible = false,
  76. count = 0,
  77. }
  78. sl.sky_data = {
  79. type = "skybox",
  80. textures = {
  81. "sky_pos_z.png",
  82. "sky_neg_z.png^[transformR180",
  83. "sky_neg_y.png^[transformR270",
  84. "sky_pos_y.png^[transformR270",
  85. "sky_pos_x.png^[transformR270",
  86. "sky_neg_x.png^[transformR90",
  87. },
  88. sky_color = {
  89. day_sky = "#000000",
  90. day_horizon = "#000000",
  91. dawn_sky = "#000000",
  92. dawn_horizon = "#000000",
  93. night_sky = "#000000",
  94. night_horizon = "#000000",
  95. indoors = "#000000",
  96. fog_sun_tint = "#000000",
  97. fog_moon_tint = "#000000"
  98. }
  99. }
  100. skylayer.add_layer(name, sl)
  101. player_list[name] = "space"
  102. if otherworlds.settings.gravity.enable then
  103. player:set_physics_override({gravity = 0.4})
  104. end
  105. -- Redsky
  106. elseif pos.y > redsky_low and pos.y < redsky_high and current ~= "redsky" then
  107. local sl = {}
  108. sl.name = "other_worlds:redskybox"
  109. sl.moon_data = {
  110. visible = false,
  111. scale = 0.8
  112. }
  113. sl.sun_data = {
  114. visible = false,
  115. scale = 0.8,
  116. sunrise_visible = false
  117. }
  118. sl.stars_data = {
  119. visible = false,
  120. count = 0,
  121. }
  122. sl.sky_data = {
  123. type = "skybox",
  124. textures = {
  125. "sky_pos_z.png^[colorize:#99000050",
  126. "sky_neg_z.png^[transformR180^[colorize:#99000050",
  127. "sky_neg_y.png^[transformR270^[colorize:#99000050",
  128. "sky_pos_y.png^[transformR270^[colorize:#99000050",
  129. "sky_pos_x.png^[transformR270^[colorize:#99000050",
  130. "sky_neg_x.png^[transformR90^[colorize:#99000050",
  131. },
  132. sky_color = {
  133. day_sky = "#000000",
  134. day_horizon = "#000000",
  135. dawn_sky = "#000000",
  136. dawn_horizon = "#000000",
  137. night_sky = "#000000",
  138. night_horizon = "#000000",
  139. indoors = "#000000",
  140. fog_sun_tint = "#000000",
  141. fog_moon_tint = "#000000"
  142. }
  143. }
  144. skylayer.add_layer(name, sl)
  145. player_list[name] = "redsky"
  146. if otherworlds.settings.gravity.enable then
  147. player:set_physics_override({gravity = 0.2})
  148. end
  149. -- Everything else (blackness)
  150. elseif pos.y > redsky_high and current ~= "blackness" then
  151. player:set_sky(000000, "plain", {})
  152. player:set_clouds({density = 0})
  153. player_list[name] = "blackness"
  154. if otherworlds.settings.gravity.enable then
  155. player:set_physics_override({gravity = 0.1})
  156. end
  157. end
  158. end
  159. end)
  160. minetest.register_on_leaveplayer(function(player)
  161. local name = player:get_player_name()
  162. player_list[name] = nil
  163. if otherworlds.settings.gravity.enable then
  164. player:set_physics_override({gravity = 1})
  165. end
  166. end)