Disable weather in Nether and End and Void

This commit is contained in:
Wuzzy 2017-08-22 18:18:53 +02:00
parent 7ade843e29
commit fe31afc119
5 changed files with 41 additions and 19 deletions

@ -388,6 +388,28 @@ function mcl_util.layer_to_y(layer, mc_dimension)
end end
end end
-- Takes a position and returns true if this position can have weather
function mcl_util.has_weather(pos)
-- Weather in the Overworld and the high part of the void below
return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64
end
-- Takes a position (pos) and returns true if compasses are working here
function mcl_util.compass_works(pos)
-- It doesn't work in Nether and the End, but it works in the Overworld and in the high part of the void below
local _, dim = mcl_util.y_to_layer(pos.y)
if dim ~= "nether" or dim ~= "end" then
return false
elseif dim == "void" then
return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64
else
return true
end
end
-- Takes a position (pos) and returns true if clocks are working here
mcl_util.clock_works = mcl_util.compass_works
-- Returns a on_place function for plants -- Returns a on_place function for plants
-- * condition: function(pos, node) -- * condition: function(pos, node)
-- * A function which is called by the on_place function to check if the node can be placed -- * A function which is called by the on_place function to check if the node can be placed

@ -1,21 +1,21 @@
rain = { rain = {
-- max rain particles created at time -- max rain particles created at time
particles_count = 35, particles_count = 35,
-- flag to turn on/off extinguish fire for rain -- flag to turn on/off extinguish fire for rain
extinguish_fire = true, extinguish_fire = true,
-- flag useful when mixing weathers -- flag useful when mixing weathers
raining = false, raining = false,
-- keeping last timeofday value (rounded). -- keeping last timeofday value (rounded).
-- Defaulted to non-existing value for initial comparing. -- Defaulted to non-existing value for initial comparing.
sky_last_update = -1, sky_last_update = -1,
init_done = false, init_done = false,
} }
rain.sound_handler = function(player) rain.sound_handler = function(player)
return minetest.sound_play("weather_rain", { return minetest.sound_play("weather_rain", {
object = player, object = player,
max_hear_distance = 2, max_hear_distance = 2,
@ -77,7 +77,7 @@ rain.get_texture = function()
return texture_name; return texture_name;
end end
-- register player for rain weather. -- register player for rain weather.
-- basically needs for origin sky reference and rain sound controls. -- basically needs for origin sky reference and rain sound controls.
rain.add_player = function(player) rain.add_player = function(player)
if weather.players[player:get_player_name()] == nil then if weather.players[player:get_player_name()] == nil then
@ -99,7 +99,7 @@ rain.remove_player = function(player)
end end
-- adds and removes rain sound depending how much rain particles around player currently exist. -- adds and removes rain sound depending how much rain particles around player currently exist.
-- have few seconds delay before each check to avoid on/off sound too often -- have few seconds delay before each check to avoid on/off sound too often
-- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance. -- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance.
rain.update_sound = function(player) rain.update_sound = function(player)
local player_meta = weather.players[player:get_player_name()] local player_meta = weather.players[player:get_player_name()]
@ -107,16 +107,16 @@ rain.update_sound = function(player)
if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > os.time() then if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > os.time() then
return false return false
end end
if player_meta.sound_handler ~= nil then if player_meta.sound_handler ~= nil then
if rain.last_rp_count == 0 then if rain.last_rp_count == 0 then
minetest.sound_stop(player_meta.sound_handler) minetest.sound_stop(player_meta.sound_handler)
player_meta.sound_handler = nil player_meta.sound_handler = nil
end end
elseif rain.last_rp_count > 0 then elseif rain.last_rp_count > 0 then
player_meta.sound_handler = rain.sound_handler(player) player_meta.sound_handler = rain.sound_handler(player)
end end
player_meta.sound_updated = os.time() player_meta.sound_updated = os.time()
end end
end end
@ -131,7 +131,7 @@ rain.remove_sound = function(player)
end end
-- callback function for removing rain -- callback function for removing rain
rain.clear = function() rain.clear = function()
rain.raining = false rain.raining = false
rain.sky_last_update = -1 rain.sky_last_update = -1
rain.init_done = false rain.init_done = false
@ -143,10 +143,10 @@ rain.clear = function()
end end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if weather.state ~= "rain" then if weather.state ~= "rain" then
return false return false
end end
rain.make_weather() rain.make_weather()
end) end)
@ -158,7 +158,7 @@ rain.make_weather = function()
end end
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
if (weather.is_underwater(player)) then if (weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
return false return false
end end
rain.add_player(player) rain.add_player(player)

@ -73,7 +73,7 @@ minetest.register_globalstep(function(dtime)
end end
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
if (weather.is_underwater(player)) then if (weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
return false return false
end end
snow.add_rain_particles(player) snow.add_rain_particles(player)

@ -91,8 +91,8 @@ minetest.register_globalstep(function(dtime)
for s, stack in ipairs(player:get_inventory():get_list("main")) do for s, stack in ipairs(player:get_inventory():get_list("main")) do
local _, dim = mcl_util.y_to_layer(player:getpos().y) local _, dim = mcl_util.y_to_layer(player:getpos().y)
local frame local frame
-- Clocks do not work in the End, Nether or the Void -- Clocks do not work in certain zones
if dim == "end" or dim == "nether" or dim == "void" then if not mcl_util.clock_works(player:getpos()) then
frame = random_frame frame = random_frame
else else
frame = now frame = now

@ -31,8 +31,8 @@ minetest.register_globalstep(function(dtime)
local pos = player:getpos() local pos = player:getpos()
local _, dim = mcl_util.y_to_layer(pos.y) local _, dim = mcl_util.y_to_layer(pos.y)
local compass_image local compass_image
-- Compasses do not work in the End, Nether or the Void -- Compasses do not work in certain zones
if dim == "end" or dim == "nether" or dim == "void" then if not mcl_util.compass_works(player:getpos()) then
compass_image = random_frame compass_image = random_frame
else else
local spawn = {x=0,y=0,z=0} local spawn = {x=0,y=0,z=0}