environment.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local environment = {}
  2. function environment.get_heat(pos)
  3. if climate_mod.forced_enviroment.heat ~= nil then
  4. return climate_mod.forced_enviroment.heat
  5. end
  6. local base = climate_mod.settings.heat
  7. local biome = minetest.get_heat(pos)
  8. local height = climate_api.utility.rangelim((-pos.y + 10) / 15, -10, 10)
  9. local time = climate_api.utility.normalized_cycle(minetest.get_timeofday()) * 0.6 + 0.7
  10. local random = climate_mod.state:get_float("heat_random");
  11. return (base + biome + height) * time * random
  12. end
  13. function environment.get_humidity(pos)
  14. if climate_mod.forced_enviroment.humidity ~= nil then
  15. return climate_mod.forced_enviroment.humidity
  16. end
  17. local base = climate_mod.settings.humidity
  18. local biome = minetest.get_humidity(pos)
  19. local random = climate_mod.state:get_float("humidity_random");
  20. local random_base = climate_mod.state:get_float("humidity_base");
  21. return (base + biome * 0.7 + random_base * 0.3) * random
  22. end
  23. function environment.get_wind(pos)
  24. if climate_mod.forced_enviroment.wind ~= nil then
  25. return climate_mod.forced_enviroment.wind
  26. end
  27. local wind_x = climate_mod.state:get_float("wind_x")
  28. local wind_z = climate_mod.state:get_float("wind_z")
  29. local base_wind = vector.new({ x = wind_x, y = 0, z = wind_z })
  30. local height_modifier = climate_api.utility.sigmoid(pos.y, 2, 0.02, 1)
  31. return vector.multiply(base_wind, height_modifier)
  32. end
  33. function environment.get_weather_presets(player)
  34. local pname = player:get_player_name()
  35. local weathers = climate_mod.current_weather[pname]
  36. if type(weathers) == "nil" then weathers = {} end
  37. return weathers
  38. end
  39. function environment.get_effects(player)
  40. local pname = player:get_player_name()
  41. local effects = {}
  42. for effect, players in pairs(climate_mod.current_effects) do
  43. if type(players[pname]) ~= "nil" then
  44. table.insert(effects, effect)
  45. end
  46. end
  47. return effects
  48. end
  49. return environment