Adds snow biomes to Minetest.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
6.1KB

  1. --[[
  2. --==============================
  3. --==========================================================
  4. LazyJ's Fork of Splizard's "Snow Biomes" Mod
  5. by LazyJ
  6. version: Umpteen-hundred and 7/5ths something or another.
  7. 2014_04_12
  8. ~~~
  9. "Snow Biomes" Mod
  10. By Splizard
  11. Download:
  12. http//forum.minetest.net/viewtopic.php?id=2290
  13. http://github.com/Splizard/minetest-mod-snow/
  14. --==========================================================
  15. --==============================
  16. Snow Biomes
  17. This program is free software; you can redistribute it and/or modify
  18. it under the terms of the GNU General Public License as published by
  19. the Free Software Foundation; either version 2 of the License, or
  20. (at your option) any later version.
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. GNU General Public License for more details.
  25. You should have received a copy of the GNU General Public License
  26. along with this program; if not, write to the Free Software
  27. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  28. MA 02110-1301, USA.
  29. ]]--
  30. -- Original Lua Files
  31. --dofile(modpath.."/util.lua")
  32. --dofile(modpath.."/mapgen.lua")
  33. --dofile(modpath.."/sled.lua")
  34. -- "falling_snow.lua" disabled since weather functions minetest.get_heat(pos) and minetest.get_humidity(pos)
  35. -- have been removed from Minetest.
  36. -- Until something else can be figured out, use paramat's "Snowdrift" mod instead.
  37. -- dofile(modpath.."/falling_snow.lua")
  38. local load_time_start = minetest.get_us_time()
  39. -- Original init.lua File Broken into Smaller Files
  40. local srcpath = minetest.get_modpath("snow").."/src/"
  41. dofile(srcpath.."abms.lua")
  42. dofile(srcpath.."aliases.lua")
  43. dofile(srcpath.."crafting.lua")
  44. -- The formspec menu didn't work when util.lua was the very first "dofile" so I moved
  45. -- it and all the other original "dofiles", in order, to the bottom of the list. ~ LazyJ
  46. -- Minetest would crash if the mapgen was called upon before the rest of other snow lua files so
  47. -- I put it lower on the list and that seems to do the trick. ~ LazyJ
  48. dofile(srcpath.."util.lua")
  49. dofile(srcpath.."snowball.lua")
  50. -- To get Xmas tree saplings, the "christmas_content", true or false, in "util.lua" has to be determined first.
  51. -- That means "nodes.lua", where the saplings are controlled, has to come after "util.lua". ~ LazyJ
  52. dofile(srcpath.."nodes.lua")
  53. dofile(srcpath.."stairs.lua")
  54. dofile(srcpath.."mapgen.lua")
  55. dofile(srcpath.."sled.lua")
  56. dofile(srcpath.."falling_snow.lua")
  57. local is_uneven
  58. --This function places snow checking at the same time for snow level and increasing as needed.
  59. --This also takes into account sourrounding snow and makes snow even.
  60. function snow.place(pos, disablesound)
  61. local node = minetest.get_node_or_nil(pos)
  62. --Oops, maybe there is no node?
  63. if not node
  64. or not minetest.registered_nodes[node.name] then
  65. return
  66. end
  67. if node.name == "default:snow" then
  68. local level = minetest.get_node_level(pos)
  69. if level < 63 then
  70. if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0
  71. and not is_uneven(pos) then
  72. if not disablesound then
  73. minetest.sound_play("default_snow_footstep", {pos=pos})
  74. end
  75. minetest.add_node_level(pos, 7)
  76. end
  77. elseif level == 63 then
  78. local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
  79. if p
  80. and minetest.get_node_light(p, 0.5) == 15 then
  81. if not disablesound then
  82. minetest.sound_play("default_grass_footstep", {pos=pos})
  83. end
  84. minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
  85. else
  86. if not disablesound then
  87. minetest.sound_play("default_snow_footstep", {pos=pos})
  88. end
  89. minetest.add_node(pos, {name="default:snowblock"})
  90. end
  91. end
  92. elseif node.name ~= "default:ice"
  93. and minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name ~= "air" then
  94. local data = minetest.registered_nodes[node.name]
  95. local drawtype = data.drawtype
  96. if drawtype == "normal"
  97. or drawtype == "allfaces_optional" then
  98. pos.y = pos.y+1
  99. local sound = data.sounds
  100. if sound and not disablesound then
  101. sound = sound.footstep
  102. if sound then
  103. minetest.sound_play(sound.name, {pos=pos, gain=sound.gain})
  104. end
  105. end
  106. minetest.place_node(pos, {name="default:snow"})
  107. elseif drawtype == "plantlike" then
  108. pos.y = pos.y - 1
  109. if minetest.get_node(pos).name == "default:dirt_with_grass" then
  110. minetest.sound_play("default_grass_footstep", {pos=pos})
  111. minetest.add_node(pos, {name="default:dirt_with_snow"})
  112. end
  113. end
  114. end
  115. end
  116. -- Checks if the snow level is even at any given pos.
  117. -- Smooth Snow
  118. local function uneven(pos)
  119. local num = minetest.get_node_level(pos)
  120. local get_node = minetest.get_node
  121. local add_node = minetest.add_node
  122. local foundx
  123. local foundz
  124. for z = -1,1 do
  125. for x = -1,1 do
  126. local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
  127. local node = get_node(p)
  128. p.y = p.y-1
  129. local bnode = get_node(p)
  130. if node
  131. and minetest.registered_nodes[node.name]
  132. and minetest.registered_nodes[node.name].drawtype == "plantlike"
  133. and bnode.name == "default:dirt_with_grass" then
  134. add_node(p, {name="default:dirt_with_snow"})
  135. return true
  136. end
  137. p.y = p.y+1
  138. if not (x == 0 and z == 0)
  139. and node.name == "default:snow"
  140. and minetest.get_node_level(p) < num then
  141. foundx = x
  142. foundz = z
  143. elseif node.name == "air"
  144. and bnode.name ~= "air"
  145. and bnode.name ~= "default:snow" then
  146. p.y = p.y-1
  147. snow.place(p)
  148. return true
  149. end
  150. end
  151. end
  152. if foundx then
  153. local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
  154. if not is_uneven(p) then
  155. minetest.add_node_level(p, 7)
  156. end
  157. return true
  158. end
  159. end
  160. if snow.smooth_snow then
  161. is_uneven = uneven
  162. else
  163. is_uneven = function() end
  164. end
  165. snow.register_on_configuring(function(name, v)
  166. if name == "smooth_snow" then
  167. if v then
  168. is_uneven = uneven
  169. else
  170. is_uneven = function() end
  171. end
  172. end
  173. end)
  174. local time = (minetest.get_us_time() - load_time_start) / 1000000
  175. local msg = "[snow] loaded after ca. " .. time .. " seconds."
  176. if time > 0.01 then
  177. print(msg)
  178. else
  179. minetest.log("action", msg)
  180. end