Add initial 'weather' mod to vary cloud density, thickness, velocity
authorParamat <paramat@users.noreply.github.com>
Mon, 14 Oct 2019 23:38:41 +0000 (00:38 +0100)
committerGitHub <noreply@github.com>
Mon, 14 Oct 2019 23:38:41 +0000 (00:38 +0100)
mods/weather/README.txt [new file with mode: 0644]
mods/weather/init.lua [new file with mode: 0644]
mods/weather/license.txt [new file with mode: 0644]
mods/weather/mod.conf [new file with mode: 0644]
settingtypes.txt

diff --git a/mods/weather/README.txt b/mods/weather/README.txt
new file mode 100644 (file)
index 0000000..6733460
--- /dev/null
@@ -0,0 +1,4 @@
+Minetest Game mod: weather
+==========================
+See license.txt for license information.
+Source code by paramat (MIT).
diff --git a/mods/weather/init.lua b/mods/weather/init.lua
new file mode 100644 (file)
index 0000000..2653ece
--- /dev/null
@@ -0,0 +1,116 @@
+-- Disable by mapgen or setting
+
+local mg_name = minetest.get_mapgen_setting("mg_name")
+if mg_name == "v6" or mg_name == "singlenode" or
+               minetest.settings:get_bool("enable_weather") == false then
+       return
+end
+
+
+-- Parameters
+
+local TSCALE = 600 -- Time scale of noise variation in seconds
+local CYCLE = 8 -- Time period of cyclic clouds update in seconds
+
+local np_density = {
+       offset = 0.5,
+       scale = 0.5,
+       spread = {x = TSCALE, y = TSCALE, z = TSCALE},
+       seed = 813,
+       octaves = 1,
+       persist = 0,
+       lacunarity = 2,
+}
+
+local np_thickness = {
+       offset = 0.5,
+       scale = 0.5,
+       spread = {x = TSCALE, y = TSCALE, z = TSCALE},
+       seed = 96,
+       octaves = 1,
+       persist = 0,
+       lacunarity = 2,
+}
+
+local np_speedx = {
+       offset = 0,
+       scale = 1,
+       spread = {x = TSCALE, y = TSCALE, z = TSCALE},
+       seed = 911923,
+       octaves = 1,
+       persist = 0,
+       lacunarity = 2,
+}
+
+local np_speedz = {
+       offset = 0,
+       scale = 1,
+       spread = {x = TSCALE, y = TSCALE, z = TSCALE},
+       seed = 5728,
+       octaves = 1,
+       persist = 0,
+       lacunarity = 2,
+}
+
+-- End parameters
+
+
+-- Initialise noise objects to nil
+
+local nobj_density = nil
+local nobj_thickness = nil
+local nobj_speedx = nil
+local nobj_speedz = nil
+
+
+-- Update clouds function
+
+local function rangelim(value, lower, upper)
+       return math.min(math.max(value, lower), upper)
+end
+
+local os_time_0 = os.time()
+local t_offset = math.random(0, 300000)
+
+local function update_clouds()
+       -- Time in seconds.
+       -- Add random time offset to avoid identical behaviour each server session.
+       local time = os.difftime(os.time(), os_time_0) - t_offset
+
+       nobj_density = nobj_density or minetest.get_perlin(np_density)
+       nobj_thickness = nobj_thickness or minetest.get_perlin(np_thickness)
+       nobj_speedx = nobj_speedx or minetest.get_perlin(np_speedx)
+       nobj_speedz = nobj_speedz or minetest.get_perlin(np_speedz)
+
+       local n_density = nobj_density:get2d({x = time, y = 0})
+       local n_thickness = nobj_thickness:get2d({x = time, y = 0})
+       local n_speedx = nobj_speedx:get2d({x = time, y = 0})
+       local n_speedz = nobj_speedz:get2d({x = time, y = 0})
+
+       for _, player in ipairs(minetest.get_connected_players()) do
+               local humid = minetest.get_humidity(player:get_pos())
+               player:set_clouds({
+                       density = rangelim(humid / 100, 0.25, 1.0) * n_density,
+                       thickness = math.max(math.floor(
+                               rangelim(32 * humid / 100, 8, 32) * n_thickness
+                               ), 1),
+                       speed = {x = n_speedx * 4, z = n_speedz * 4},
+               })
+       end
+end
+
+
+local function cyclic_update()
+       update_clouds()
+       minetest.after(CYCLE, cyclic_update)
+end
+
+
+minetest.after(0, cyclic_update)
+
+
+-- Update on player join to instantly alter clouds from the default
+
+minetest.register_on_joinplayer(function(player)
+       update_clouds()
+end)
diff --git a/mods/weather/license.txt b/mods/weather/license.txt
new file mode 100644 (file)
index 0000000..33baa06
--- /dev/null
@@ -0,0 +1,24 @@
+License of source code
+----------------------
+
+The MIT License (MIT)
+Copyright (C) 2019 paramat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this
+software and associated documentation files (the "Software"), to deal in the Software
+without restriction, including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software, and to permit
+persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+For more details:
+https://opensource.org/licenses/MIT
diff --git a/mods/weather/mod.conf b/mods/weather/mod.conf
new file mode 100644 (file)
index 0000000..436ce67
--- /dev/null
@@ -0,0 +1,2 @@
+name = weather
+description = Minetest Game mod: weather
index a0d5fead9ef886a854e7a35a27ae6c5cd5cc2df6..793125f9406057c71de3b5bf281066ff17ca0e5a 100644 (file)
@@ -71,3 +71,7 @@ engine_spawn (Use engine spawn search) bool false
 #    Whether river water source nodes create flowing sounds.
 #    Helps rivers create more sound, especially on level sections.
 river_source_sounds (River source node sounds) bool false
+
+#    Enable cloud variation.
+#    Non-functional in V6 or Singlenode mapgens.
+enable_weather (Enable weather) bool true