From 3c841e885f3352fb86afa0db61ace72fa04dfb6a Mon Sep 17 00:00:00 2001 From: Dirk Sohler Date: Sun, 13 May 2018 22:00:30 +0200 Subject: [PATCH 1/4] fix and make the snow plates ABM configurable --- weather/settingtypes.txt | 8 ++++++++ weather/snow.lua | 36 +++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 weather/settingtypes.txt diff --git a/weather/settingtypes.txt b/weather/settingtypes.txt new file mode 100644 index 0000000..8ededa2 --- /dev/null +++ b/weather/settingtypes.txt @@ -0,0 +1,8 @@ +# Fast computer ABM +# +# The “fast computer ABM” controls if snow covers will be placed +# on the ground when `weather:snow` is set. This needs a better +# computer and should not be used if the performance drops too +# much. It is advised not to enable this on servers and it is +# disbaled by default +weather_fast_pc (Snow covers for fast PCs) bool false diff --git a/weather/snow.lua b/weather/snow.lua index 5c867bb..99aedb8 100644 --- a/weather/snow.lua +++ b/weather/snow.lua @@ -26,23 +26,25 @@ minetest.register_node("weather:snow_cover", { drop = {} }) ---[[ Enable this section if you have a very fast PC -minetest.register_abm({ - nodenames = {"group:crumbly", "group:snappy", "group:cracky", "group:choppy"}, - neighbors = {"default:air"}, - interval = 10.0, - chance = 80, - action = function (pos, node, active_object_count, active_object_count_wider) - if weather == "snow" then - if minetest.registered_nodes[node.name].drawtype == "normal" - or minetest.registered_nodes[node.name].drawtype == "allfaces_optional" then - local np = vector.add(pos, {x=0, y=1, z=0}) - if minetest.env:get_node_light(np, 0.5) == 15 - and minetest.env:get_node(np).name == "air" then - minetest.env:add_node(np, {name="weather:snow_cover"}) +-- Snow cover ABM when weather_fast_pc setting is set to `true` +if minetest.is_yes(minetest.settings:get_bool('weather_fast_pc')) then + minetest.log('action', '[weather] Loaded fast computer ABM (snow covers when weather:snow is set)') + minetest.register_abm({ + nodenames = {"group:crumbly", "group:snappy", "group:cracky", "group:choppy"}, + neighbors = {"default:air"}, + interval = 10.0, + chance = 80, + action = function (pos, node, active_object_count, active_object_count_wider) + if weather.type == "weather:snow" then + if minetest.registered_nodes[node.name].drawtype == "normal" + or minetest.registered_nodes[node.name].drawtype == "allfaces_optional" then + local np = vector.add(pos, {x=0, y=1, z=0}) + if minetest.env:get_node_light(np, 0.5) == 15 + and minetest.env:get_node(np).name == "air" then + minetest.env:add_node(np, {name="weather:snow_cover"}) + end end end end - end -}) -]] + }) +end From c2c0fce93aecb699c93ca3f105358992a8bd7208 Mon Sep 17 00:00:00 2001 From: Dirk Sohler Date: Sun, 13 May 2018 22:13:10 +0200 Subject: [PATCH 2/4] fix Travis `nused argument` errors --- weather/snow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weather/snow.lua b/weather/snow.lua index 99aedb8..92a039e 100644 --- a/weather/snow.lua +++ b/weather/snow.lua @@ -34,7 +34,7 @@ if minetest.is_yes(minetest.settings:get_bool('weather_fast_pc')) then neighbors = {"default:air"}, interval = 10.0, chance = 80, - action = function (pos, node, active_object_count, active_object_count_wider) + action = function (pos, node) if weather.type == "weather:snow" then if minetest.registered_nodes[node.name].drawtype == "normal" or minetest.registered_nodes[node.name].drawtype == "allfaces_optional" then From 08e58b2393974e1882f0ae11da66b3d0f9e3eb4e Mon Sep 17 00:00:00 2001 From: theFox6 Date: Thu, 17 May 2018 16:33:50 +0200 Subject: [PATCH 3/4] rawset globals --- .luacheckrc | 6 +----- weather/api.lua | 6 +++--- weather/init.lua | 5 ++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 28e0a94..67908b7 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,11 +1,7 @@ -allow_defined_top = true - read_globals = { "minetest", "dump", "vector", "VoxelManip", "VoxelArea", table = { fields = { "copy" } }, "lightning", -} - -ignore = {"122"} \ No newline at end of file +} \ No newline at end of file diff --git a/weather/api.lua b/weather/api.lua index cbaca7d..65234eb 100644 --- a/weather/api.lua +++ b/weather/api.lua @@ -62,14 +62,14 @@ function weather_mod.register_downfall(id,def) end if minetest.get_modpath("lightning") then - lightning.auto = false + rawset(lightning,"auto",false) end function weather_mod.handle_lightning() if not minetest.get_modpath("lightning") then return end local current_downfall = weather_mod.registered_downfalls[weather.type] if not current_downfall then return end - lightning.auto = current_downfall.enable_lightning + rawset(lightning,"auto",current_downfall.enable_lightning) if current_downfall.enable_lightning and math.random(1,2) == 1 then local time = math.floor(math.random(lightning.interval_low/2,lightning.interval_low)) minetest.after(time, lightning.strike) @@ -92,7 +92,7 @@ minetest.register_globalstep(function() if math.random(1, 10000) == 1 then weather.type = "none" if minetest.get_modpath("lightning") then - lightning.auto = false + rawset(lightning,"auto",false) end end end diff --git a/weather/init.lua b/weather/init.lua index bfd61aa..e54bb14 100644 --- a/weather/init.lua +++ b/weather/init.lua @@ -5,9 +5,8 @@ assert(minetest.add_particlespawner, "I told you to run the latest GitHub!") -weather_mod={ - modpath=minetest.get_modpath("weather"), -} +rawset(_G,"weather_mod",false) +weather_mod.modpath=minetest.get_modpath("weather") weather = (function() local file_name = minetest.get_worldpath() .. "/weather" From 19182e8176f42a67ab404b99bd909953d40fce8d Mon Sep 17 00:00:00 2001 From: theFox6 Date: Thu, 17 May 2018 16:37:30 +0200 Subject: [PATCH 4/4] initialize weather global --- weather/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weather/init.lua b/weather/init.lua index e54bb14..e4875f1 100644 --- a/weather/init.lua +++ b/weather/init.lua @@ -5,7 +5,7 @@ assert(minetest.add_particlespawner, "I told you to run the latest GitHub!") -rawset(_G,"weather_mod",false) +rawset(_G,"weather_mod",{}) weather_mod.modpath=minetest.get_modpath("weather") weather = (function()