This commit is contained in:
Elias Fleckenstein 2021-01-28 17:45:04 +01:00
commit 4fe944445b
14 changed files with 379 additions and 355 deletions

View file

@ -1,10 +1,10 @@
local modpath = minetest.get_modpath("mcl_weather"); local modpath = minetest.get_modpath("mcl_weather")
mcl_weather = {} mcl_weather = {}
-- If not located then embeded skycolor mod version will be loaded. -- If not located then embeded skycolor mod version will be loaded.
if minetest.get_modpath("skycolor") == nil then if minetest.get_modpath("skycolor") == nil then
dofile(modpath.."/skycolor.lua") dofile(modpath.."/skycolor.lua")
end end
dofile(modpath.."/weather_core.lua") dofile(modpath.."/weather_core.lua")
@ -13,5 +13,5 @@ dofile(modpath.."/rain.lua")
dofile(modpath.."/nether_dust.lua") dofile(modpath.."/nether_dust.lua")
if minetest.get_modpath("lightning") ~= nil then if minetest.get_modpath("lightning") ~= nil then
dofile(modpath.."/thunder.lua") dofile(modpath.."/thunder.lua")
end end

View file

@ -24,11 +24,8 @@ end
local timer = 0 local timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
timer = timer + dtime timer = timer + dtime
if timer >= 0.7 then if timer < 0.7 then return end
timer = 0 timer = 0
else
return
end
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
if not mcl_worlds.has_dust(player:get_pos()) then if not mcl_worlds.has_dust(player:get_pos()) then

View file

@ -2,198 +2,198 @@ local PARTICLES_COUNT_RAIN = 30
local PARTICLES_COUNT_THUNDER = 45 local PARTICLES_COUNT_THUNDER = 45
mcl_weather.rain = { mcl_weather.rain = {
-- max rain particles created at time -- max rain particles created at time
particles_count = PARTICLES_COUNT_RAIN, particles_count = PARTICLES_COUNT_RAIN,
-- 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,
} }
mcl_weather.rain.sound_handler = function(player) mcl_weather.rain.sound_handler = function(player)
return minetest.sound_play("weather_rain", { return minetest.sound_play("weather_rain", {
to_player = player:get_player_name(), to_player = player:get_player_name(),
loop = true, loop = true,
}) })
end end
-- set skybox based on time (uses skycolor api) -- set skybox based on time (uses skycolor api)
mcl_weather.rain.set_sky_box = function() mcl_weather.rain.set_sky_box = function()
if mcl_weather.state == "rain" then if mcl_weather.state == "rain" then
mcl_weather.skycolor.add_layer( mcl_weather.skycolor.add_layer(
"weather-pack-rain-sky", "weather-pack-rain-sky",
{{r=0, g=0, b=0}, {{r=0, g=0, b=0},
{r=85, g=86, b=98}, {r=85, g=86, b=98},
{r=135, g=135, b=151}, {r=135, g=135, b=151},
{r=85, g=86, b=98}, {r=85, g=86, b=98},
{r=0, g=0, b=0}}) {r=0, g=0, b=0}})
mcl_weather.skycolor.active = true mcl_weather.skycolor.active = true
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
player:set_clouds({color="#5D5D5FE8"}) player:set_clouds({color="#5D5D5FE8"})
end end
end end
end end
-- creating manually parctiles instead of particles spawner because of easier to control -- creating manually parctiles instead of particles spawner because of easier to control
-- spawn position. -- spawn position.
mcl_weather.rain.add_rain_particles = function(player) mcl_weather.rain.add_rain_particles = function(player)
mcl_weather.rain.last_rp_count = 0 mcl_weather.rain.last_rp_count = 0
for i=mcl_weather.rain.particles_count, 1,-1 do for i=mcl_weather.rain.particles_count, 1,-1 do
local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player) local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player)
if mcl_weather.is_outdoor({x=random_pos_x, y=random_pos_y, z=random_pos_z}) then if mcl_weather.is_outdoor({x=random_pos_x, y=random_pos_y, z=random_pos_z}) then
mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1 mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1
minetest.add_particle({ minetest.add_particle({
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z}, pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
velocity = {x=0, y=-10, z=0}, velocity = {x=0, y=-10, z=0},
acceleration = {x=0, y=-30, z=0}, acceleration = {x=0, y=-30, z=0},
expirationtime = 1.0, expirationtime = 1.0,
size = math.random(0.5, 3), size = math.random(0.5, 3),
collisiondetection = true, collisiondetection = true,
collision_removal = true, collision_removal = true,
vertical = true, vertical = true,
texture = mcl_weather.rain.get_texture(), texture = mcl_weather.rain.get_texture(),
playername = player:get_player_name() playername = player:get_player_name()
}) })
end end
end end
end end
-- Simple random texture getter -- Simple random texture getter
mcl_weather.rain.get_texture = function() mcl_weather.rain.get_texture = function()
local texture_name local texture_name
local random_number = math.random() local random_number = math.random()
if random_number > 0.33 then if random_number > 0.33 then
texture_name = "weather_pack_rain_raindrop_1.png" texture_name = "weather_pack_rain_raindrop_1.png"
elseif random_number > 0.66 then elseif random_number > 0.66 then
texture_name = "weather_pack_rain_raindrop_2.png" texture_name = "weather_pack_rain_raindrop_2.png"
else else
texture_name = "weather_pack_rain_raindrop_3.png" texture_name = "weather_pack_rain_raindrop_3.png"
end end
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.
mcl_weather.rain.add_player = function(player) mcl_weather.rain.add_player = function(player)
if mcl_weather.players[player:get_player_name()] == nil then if mcl_weather.players[player:get_player_name()] == nil then
local player_meta = {} local player_meta = {}
player_meta.origin_sky = {player:get_sky()} player_meta.origin_sky = {player:get_sky()}
mcl_weather.players[player:get_player_name()] = player_meta mcl_weather.players[player:get_player_name()] = player_meta
end end
end end
-- remove player from player list effected by rain. -- remove player from player list effected by rain.
-- be sure to remove sound before removing player otherwise soundhandler reference will be lost. -- be sure to remove sound before removing player otherwise soundhandler reference will be lost.
mcl_weather.rain.remove_player = function(player) mcl_weather.rain.remove_player = function(player)
local player_meta = mcl_weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil and player_meta.origin_sky ~= nil then if player_meta ~= nil and player_meta.origin_sky ~= nil then
player:set_clouds({color="#FFF0F0E5"}) player:set_clouds({color="#FFF0F0E5"})
mcl_weather.players[player:get_player_name()] = nil mcl_weather.players[player:get_player_name()] = nil
end end
end end
mcl_worlds.register_on_dimension_change(function(player, dimension) mcl_worlds.register_on_dimension_change(function(player, dimension)
if dimension ~= "overworld" and dimension ~= "void" then if dimension ~= "overworld" and dimension ~= "void" then
mcl_weather.rain.remove_sound(player) mcl_weather.rain.remove_sound(player)
mcl_weather.rain.remove_player(player) mcl_weather.rain.remove_player(player)
elseif dimension == "overworld" then elseif dimension == "overworld" then
mcl_weather.rain.update_sound(player) mcl_weather.rain.update_sound(player)
if mcl_weather.rain.raining then if mcl_weather.rain.raining then
mcl_weather.rain.add_rain_particles(player) mcl_weather.rain.add_rain_particles(player)
mcl_weather.rain.add_player(player) mcl_weather.rain.add_player(player)
end end
end end
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.
mcl_weather.rain.update_sound = function(player) mcl_weather.rain.update_sound = function(player)
local player_meta = mcl_weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil then if player_meta ~= nil then
if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then
return false return false
end end
if player_meta.sound_handler ~= nil then if player_meta.sound_handler ~= nil then
if mcl_weather.rain.last_rp_count == 0 then if mcl_weather.rain.last_rp_count == 0 then
minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0) minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0)
player_meta.sound_handler = nil player_meta.sound_handler = nil
end end
elseif mcl_weather.rain.last_rp_count > 0 then elseif mcl_weather.rain.last_rp_count > 0 then
player_meta.sound_handler = mcl_weather.rain.sound_handler(player) player_meta.sound_handler = mcl_weather.rain.sound_handler(player)
end end
player_meta.sound_updated = minetest.get_gametime() player_meta.sound_updated = minetest.get_gametime()
end end
end end
-- rain sound removed from player. -- rain sound removed from player.
mcl_weather.rain.remove_sound = function(player) mcl_weather.rain.remove_sound = function(player)
local player_meta = mcl_weather.players[player:get_player_name()] local player_meta = mcl_weather.players[player:get_player_name()]
if player_meta ~= nil and player_meta.sound_handler ~= nil then if player_meta ~= nil and player_meta.sound_handler ~= nil then
minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0) minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0)
player_meta.sound_handler = nil player_meta.sound_handler = nil
player_meta.sound_updated = nil player_meta.sound_updated = nil
end end
end end
-- callback function for removing rain -- callback function for removing rain
mcl_weather.rain.clear = function() mcl_weather.rain.clear = function()
mcl_weather.rain.raining = false mcl_weather.rain.raining = false
mcl_weather.rain.sky_last_update = -1 mcl_weather.rain.sky_last_update = -1
mcl_weather.rain.init_done = false mcl_weather.rain.init_done = false
mcl_weather.rain.set_particles_mode("rain") mcl_weather.rain.set_particles_mode("rain")
mcl_weather.skycolor.remove_layer("weather-pack-rain-sky") mcl_weather.skycolor.remove_layer("weather-pack-rain-sky")
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
mcl_weather.rain.remove_sound(player) mcl_weather.rain.remove_sound(player)
mcl_weather.rain.remove_player(player) mcl_weather.rain.remove_player(player)
end end
end end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if mcl_weather.state ~= "rain" then if mcl_weather.state ~= "rain" then
return false return false
end end
mcl_weather.rain.make_weather() mcl_weather.rain.make_weather()
end) end)
mcl_weather.rain.make_weather = function() mcl_weather.rain.make_weather = function()
if mcl_weather.rain.init_done == false then if mcl_weather.rain.init_done == false then
mcl_weather.rain.raining = true mcl_weather.rain.raining = true
mcl_weather.rain.set_sky_box() mcl_weather.rain.set_sky_box()
mcl_weather.rain.set_particles_mode(mcl_weather.mode) mcl_weather.rain.set_particles_mode(mcl_weather.mode)
mcl_weather.rain.init_done = true mcl_weather.rain.init_done = true
end end
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
if (mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos())) then if (mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos())) then
mcl_weather.rain.remove_sound(player) mcl_weather.rain.remove_sound(player)
return false return false
end end
mcl_weather.rain.add_player(player) mcl_weather.rain.add_player(player)
mcl_weather.rain.add_rain_particles(player) mcl_weather.rain.add_rain_particles(player)
mcl_weather.rain.update_sound(player) mcl_weather.rain.update_sound(player)
end end
end end
-- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops -- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops
mcl_weather.rain.set_particles_mode = function(mode) mcl_weather.rain.set_particles_mode = function(mode)
if mode == "thunder" then if mode == "thunder" then
mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER
else else
mcl_weather.rain.particles_count = PARTICLES_COUNT_RAIN mcl_weather.rain.particles_count = PARTICLES_COUNT_RAIN
end end
end end
if mcl_weather.allow_abm then if mcl_weather.allow_abm then
@ -266,16 +266,16 @@ if mcl_weather.allow_abm then
end end
if mcl_weather.reg_weathers.rain == nil then if mcl_weather.reg_weathers.rain == nil then
mcl_weather.reg_weathers.rain = { mcl_weather.reg_weathers.rain = {
clear = mcl_weather.rain.clear, clear = mcl_weather.rain.clear,
light_factor = 0.6, light_factor = 0.6,
-- 10min - 20min -- 10min - 20min
min_duration = 600, min_duration = 600,
max_duration = 1200, max_duration = 1200,
transitions = { transitions = {
[65] = "none", [65] = "none",
[70] = "snow", [70] = "snow",
[100] = "thunder", [100] = "thunder",
} }
} }
end end

View file

@ -81,17 +81,16 @@ end)
-- register snow weather -- register snow weather
if mcl_weather.reg_weathers.snow == nil then if mcl_weather.reg_weathers.snow == nil then
mcl_weather.reg_weathers.snow = { mcl_weather.reg_weathers.snow = {
clear = mcl_weather.snow.clear, clear = mcl_weather.snow.clear,
light_factor = 0.6, light_factor = 0.6,
-- 10min - 20min -- 10min - 20min
min_duration = 600, min_duration = 600,
max_duration = 1200, max_duration = 1200,
transitions = { transitions = {
[65] = "none", [65] = "none",
[80] = "rain", [80] = "rain",
[100] = "thunder", [100] = "thunder",
} }
} }
end end

View file

@ -6,8 +6,8 @@ mcl_weather.state = "none"
-- player list for saving player meta info -- player list for saving player meta info
mcl_weather.players = {} mcl_weather.players = {}
-- default weather recalculation interval -- default weather check interval for global step
mcl_weather.check_interval = 300 mcl_weather.check_interval = 5
-- weather min duration -- weather min duration
mcl_weather.min_duration = 600 mcl_weather.min_duration = 600
@ -25,14 +25,14 @@ mcl_weather.reg_weathers = {}
mcl_weather.allow_abm = true mcl_weather.allow_abm = true
mcl_weather.reg_weathers["none"] = { mcl_weather.reg_weathers["none"] = {
min_duration = mcl_weather.min_duration, min_duration = mcl_weather.min_duration,
max_duration = mcl_weather.max_duration, max_duration = mcl_weather.max_duration,
light_factor = nil, light_factor = nil,
transitions = { transitions = {
[50] = "rain", [50] = "rain",
[100] = "snow", [100] = "snow",
}, },
clear = function() end, clear = function() end,
} }
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
@ -45,211 +45,230 @@ end
minetest.register_on_shutdown(save_weather) minetest.register_on_shutdown(save_weather)
mcl_weather.get_rand_end_time = function(min_duration, max_duration) mcl_weather.get_rand_end_time = function(min_duration, max_duration)
local r local r
if min_duration ~= nil and max_duration ~= nil then if min_duration ~= nil and max_duration ~= nil then
r = math.random(min_duration, max_duration); r = math.random(min_duration, max_duration)
else else
r = math.random(mcl_weather.min_duration, mcl_weather.max_duration); r = math.random(mcl_weather.min_duration, mcl_weather.max_duration)
end end
return minetest.get_gametime() + r return minetest.get_gametime() + r
end end
mcl_weather.get_current_light_factor = function() mcl_weather.get_current_light_factor = function()
if mcl_weather.state == "none" then if mcl_weather.state == "none" then
return nil return nil
else else
return mcl_weather.reg_weathers[mcl_weather.state].light_factor return mcl_weather.reg_weathers[mcl_weather.state].light_factor
end end
end end
-- Returns true if pos is outdoor. -- Returns true if pos is outdoor.
-- Outdoor is defined as any node in the Overworld under open sky. -- Outdoor is defined as any node in the Overworld under open sky.
-- FIXME: Nodes below glass also count as “outdoor”, this should not be the case. -- FIXME: Nodes below glass also count as “outdoor”, this should not be the case.
mcl_weather.is_outdoor = function(pos) mcl_weather.is_outdoor = function(pos)
local cpos = {x=pos.x, y=pos.y+1, z=pos.z} local cpos = {x=pos.x, y=pos.y+1, z=pos.z}
local dim = mcl_worlds.pos_to_dimension(cpos) local dim = mcl_worlds.pos_to_dimension(cpos)
if minetest.get_node_light(cpos, 0.5) == 15 and dim == "overworld" then if minetest.get_node_light(cpos, 0.5) == 15 and dim == "overworld" then
return true return true
end end
return false return false
end end
-- checks if player is undewater. This is needed in order to -- checks if player is undewater. This is needed in order to
-- turn off weather particles generation. -- turn off weather particles generation.
mcl_weather.is_underwater = function(player) mcl_weather.is_underwater = function(player)
local ppos = player:get_pos() local ppos = player:get_pos()
local offset = player:get_eye_offset() local offset = player:get_eye_offset()
local player_eye_pos = {x = ppos.x + offset.x, local player_eye_pos = {x = ppos.x + offset.x,
y = ppos.y + offset.y + 1.5, y = ppos.y + offset.y + 1.5,
z = ppos.z + offset.z} z = ppos.z + offset.z}
local node_level = minetest.get_node_level(player_eye_pos) local node_level = minetest.get_node_level(player_eye_pos)
if node_level == 8 or node_level == 7 then if node_level == 8 or node_level == 7 then
return true return true
end end
return false return false
end end
-- trying to locate position for particles by player look direction for performance reason. -- trying to locate position for particles by player look direction for performance reason.
-- it is costly to generate many particles around player so goal is focus mainly on front view. -- it is costly to generate many particles around player so goal is focus mainly on front view.
mcl_weather.get_random_pos_by_player_look_dir = function(player) mcl_weather.get_random_pos_by_player_look_dir = function(player)
local look_dir = player:get_look_dir() local look_dir = player:get_look_dir()
local player_pos = player:get_pos() local player_pos = player:get_pos()
local random_pos_x = 0 local random_pos_x = 0
local random_pos_y = 0 local random_pos_y = 0
local random_pos_z = 0 local random_pos_z = 0
if look_dir.x > 0 then if look_dir.x > 0 then
if look_dir.z > 0 then if look_dir.z > 0 then
random_pos_x = math.random() + math.random(player_pos.x - 2.5, player_pos.x + 5) random_pos_x = math.random() + math.random(player_pos.x - 2.5, player_pos.x + 5)
random_pos_z = math.random() + math.random(player_pos.z - 2.5, player_pos.z + 5) random_pos_z = math.random() + math.random(player_pos.z - 2.5, player_pos.z + 5)
else else
random_pos_x = math.random() + math.random(player_pos.x - 2.5, player_pos.x + 5) random_pos_x = math.random() + math.random(player_pos.x - 2.5, player_pos.x + 5)
random_pos_z = math.random() + math.random(player_pos.z - 5, player_pos.z + 2.5) random_pos_z = math.random() + math.random(player_pos.z - 5, player_pos.z + 2.5)
end end
else else
if look_dir.z > 0 then if look_dir.z > 0 then
random_pos_x = math.random() + math.random(player_pos.x - 5, player_pos.x + 2.5) random_pos_x = math.random() + math.random(player_pos.x - 5, player_pos.x + 2.5)
random_pos_z = math.random() + math.random(player_pos.z - 2.5, player_pos.z + 5) random_pos_z = math.random() + math.random(player_pos.z - 2.5, player_pos.z + 5)
else else
random_pos_x = math.random() + math.random(player_pos.x - 5, player_pos.x + 2.5) random_pos_x = math.random() + math.random(player_pos.x - 5, player_pos.x + 2.5)
random_pos_z = math.random() + math.random(player_pos.z - 5, player_pos.z + 2.5) random_pos_z = math.random() + math.random(player_pos.z - 5, player_pos.z + 2.5)
end end
end end
random_pos_y = math.random() + math.random(player_pos.y + 10, player_pos.y + 15) random_pos_y = math.random() + math.random(player_pos.y + 10, player_pos.y + 15)
return random_pos_x, random_pos_y, random_pos_z return random_pos_x, random_pos_y, random_pos_z
end end
local t, wci = 0, mcl_weather.check_interval
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if mcl_weather.end_time == nil then t = t + dtime
mcl_weather.end_time = mcl_weather.get_rand_end_time() if t < wci then return end
end t = 0
-- recalculate weather
if mcl_weather.end_time <= minetest.get_gametime() then if mcl_weather.end_time == nil then
local changeWeather = minetest.settings:get_bool("mcl_doWeatherCycle") mcl_weather.end_time = mcl_weather.get_rand_end_time()
if changeWeather == nil then end
changeWeather = true -- recalculate weather
end if mcl_weather.end_time <= minetest.get_gametime() then
if changeWeather then local changeWeather = minetest.settings:get_bool("mcl_doWeatherCycle")
mcl_weather.set_random_weather(mcl_weather.state, mcl_weather.reg_weathers[mcl_weather.state]) if changeWeather == nil then
else changeWeather = true
mcl_weather.end_time = mcl_weather.get_rand_end_time() end
end if changeWeather then
end mcl_weather.set_random_weather(mcl_weather.state, mcl_weather.reg_weathers[mcl_weather.state])
else
mcl_weather.end_time = mcl_weather.get_rand_end_time()
end
end
end) end)
-- Sets random weather (which could be 'none' (no weather)). -- Sets random weather (which could be 'none' (no weather)).
mcl_weather.set_random_weather = function(weather_name, weather_meta) mcl_weather.set_random_weather = function(weather_name, weather_meta)
if (weather_meta ~= nil) then if weather_meta == nil then return end
local transitions = weather_meta.transitions local transitions = weather_meta.transitions
local random_roll = math.random(0,100) local random_roll = math.random(0,100)
local new_weather local new_weather
for v, weather in pairs(transitions) do for v, weather in pairs(transitions) do
if random_roll < v then if random_roll < v then
new_weather = weather new_weather = weather
break break
end end
end end
if new_weather then if new_weather then
mcl_weather.change_weather(new_weather) mcl_weather.change_weather(new_weather)
end end
end
end end
-- Change weather to new_weather. -- Change weather to new_weather.
-- * explicit_end_time is OPTIONAL. If specified, explicitly set the -- * explicit_end_time is OPTIONAL. If specified, explicitly set the
-- gametime (minetest.get_gametime) in which the weather ends. -- gametime (minetest.get_gametime) in which the weather ends.
mcl_weather.change_weather = function(new_weather, explicit_end_time) -- * changer is OPTIONAL, for logging purposes.
if (mcl_weather.reg_weathers ~= nil and mcl_weather.reg_weathers[new_weather] ~= nil) then mcl_weather.change_weather = function(new_weather, explicit_end_time, changer_name)
if (mcl_weather.state ~= nil and mcl_weather.reg_weathers[mcl_weather.state] ~= nil) then local changer_name = changer_name or debug.getinfo(2).name.."()"
mcl_weather.reg_weathers[mcl_weather.state].clear()
end if (mcl_weather.reg_weathers ~= nil and mcl_weather.reg_weathers[new_weather] ~= nil) then
mcl_weather.state = new_weather if (mcl_weather.state ~= nil and mcl_weather.reg_weathers[mcl_weather.state] ~= nil) then
local weather_meta = mcl_weather.reg_weathers[mcl_weather.state] mcl_weather.reg_weathers[mcl_weather.state].clear()
if explicit_end_time then end
mcl_weather.end_time = explicit_end_time
else local old_weather = mcl_weather.state
mcl_weather.end_time = mcl_weather.get_rand_end_time(weather_meta.min_duration, weather_meta.max_duration)
end mcl_weather.state = new_weather
mcl_weather.skycolor.update_sky_color()
save_weather() if old_weather == "none" then
return true old_weather = "clear"
end end
return false if new_weather == "none" then
new_weather = "clear"
end
minetest.log("action", "[mcl_weather] " .. changer_name .. " changed the weather from " .. old_weather .. " to " .. new_weather)
local weather_meta = mcl_weather.reg_weathers[mcl_weather.state]
if explicit_end_time then
mcl_weather.end_time = explicit_end_time
else
mcl_weather.end_time = mcl_weather.get_rand_end_time(weather_meta.min_duration, weather_meta.max_duration)
end
mcl_weather.skycolor.update_sky_color()
save_weather()
return true
end
return false
end end
mcl_weather.get_weather = function() mcl_weather.get_weather = function()
return mcl_weather.state return mcl_weather.state
end end
minetest.register_privilege("weather_manager", { minetest.register_privilege("weather_manager", {
description = S("Gives ability to control weather"), description = S("Gives ability to control weather"),
give_to_singleplayer = false give_to_singleplayer = false
}) })
-- Weather command definition. Set -- Weather command definition. Set
minetest.register_chatcommand("weather", { minetest.register_chatcommand("weather", {
params = "(clear | rain | snow | thunder) [<duration>]", params = "(clear | rain | snow | thunder) [<duration>]",
description = S("Changes the weather to the specified parameter."), description = S("Changes the weather to the specified parameter."),
privs = {weather_manager = true}, privs = {weather_manager = true},
func = function(name, param) func = function(name, param)
if (param == "") then if (param == "") then
return false, S("Error: No weather specified.") return false, S("Error: No weather specified.")
end end
local new_weather, end_time local new_weather, end_time
local parse1, parse2 = string.match(param, "(%w+) ?(%d*)") local parse1, parse2 = string.match(param, "(%w+) ?(%d*)")
if parse1 then if parse1 then
if parse1 == "clear" then if parse1 == "clear" then
new_weather = "none" new_weather = "none"
else else
new_weather = parse1 new_weather = parse1
end end
else else
return false, S("Error: Invalid parameters.") return false, S("Error: Invalid parameters.")
end end
if parse2 then if parse2 then
if type(tonumber(parse2)) == "number" then if type(tonumber(parse2)) == "number" then
local duration = tonumber(parse2) local duration = tonumber(parse2)
if duration < 1 then if duration < 1 then
return false, S("Error: Duration can't be less than 1 second.") return false, S("Error: Duration can't be less than 1 second.")
end end
end_time = minetest.get_gametime() + duration end_time = minetest.get_gametime() + duration
end end
end end
local success = mcl_weather.change_weather(new_weather, end_time) local success = mcl_weather.change_weather(new_weather, end_time, name)
if success then if success then
return true return true
else else
return false, S("Error: Invalid weather specified. Use “clear”, “rain”, “snow” or “thunder”.") return false, S("Error: Invalid weather specified. Use “clear”, “rain”, “snow” or “thunder”.")
end end
end end
}) })
minetest.register_chatcommand("toggledownfall", { minetest.register_chatcommand("toggledownfall", {
params = "", params = "",
description = S("Toggles between clear weather and weather with downfall (randomly rain, thunderstorm or snow)"), description = S("Toggles between clear weather and weather with downfall (randomly rain, thunderstorm or snow)"),
privs = {weather_manager = true}, privs = {weather_manager = true},
func = function(name, param) func = function(name, param)
-- Currently rain/thunder/snow: Set weather to clear -- Currently rain/thunder/snow: Set weather to clear
if mcl_weather.state ~= "none" then if mcl_weather.state ~= "none" then
return mcl_weather.change_weather("none") return mcl_weather.change_weather("none", nil, name)
-- Currently clear: Set weather randomly to rain/thunder/snow -- Currently clear: Set weather randomly to rain/thunder/snow
else else
local new = { "rain", "thunder", "snow" } local new = { "rain", "thunder", "snow" }
local r = math.random(1, #new) local r = math.random(1, #new)
return mcl_weather.change_weather(new[r]) return mcl_weather.change_weather(new[r], nil, name)
end end
end end
}) })
-- Configuration setting which allows user to disable ABM for weathers (if they use it). -- Configuration setting which allows user to disable ABM for weathers (if they use it).
-- Weather mods expected to be use this flag before registering ABM. -- Weather mods expected to be use this flag before registering ABM.
local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm") local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm")
if weather_allow_abm ~= nil and weather_allow_abm == false then if weather_allow_abm ~= nil and weather_allow_abm == false then
mcl_weather.allow_abm = false mcl_weather.allow_abm = false
end end

View file

@ -54,12 +54,13 @@ schem_path = settlements.modpath.."/schematics/"
-- --
schematic_table = { schematic_table = {
{name = "large_house", mts = schem_path.."large_house.mts", hwidth = 11, hdepth = 12, hheight = 9, hsize = 14, max_num = 0.08, rplc = "n"}, {name = "large_house", mts = schem_path.."large_house.mts", hwidth = 11, hdepth = 12, hheight = 9, hsize = 14, max_num = 0.08, rplc = "n"},
{name = "blacksmith", mts = schem_path.."blacksmith.mts", hwidth = 7, hdepth = 7, hheight = 13, hsize = 13, max_num = 0.050, rplc = "n"}, {name = "blacksmith", mts = schem_path.."blacksmith.mts", hwidth = 7, hdepth = 7, hheight = 13, hsize = 13, max_num = 0.055, rplc = "n"},
{name = "butcher", mts = schem_path.."butcher.mts", hwidth = 11, hdepth = 8, hheight = 10, hsize = 14, max_num = 0.03, rplc = "n"},
{name = "church", mts = schem_path.."church.mts", hwidth = 13, hdepth = 13, hheight = 14, hsize = 15, max_num = 0.04, rplc = "n"}, {name = "church", mts = schem_path.."church.mts", hwidth = 13, hdepth = 13, hheight = 14, hsize = 15, max_num = 0.04, rplc = "n"},
{name = "farm", mts = schem_path.."farm.mts", hwidth = 7, hdepth = 7, hheight = 13, hsize = 13, max_num = 0.1, rplc = "n"}, {name = "farm", mts = schem_path.."farm.mts", hwidth = 7, hdepth = 7, hheight = 13, hsize = 13, max_num = 0.1, rplc = "n"},
{name = "lamp", mts = schem_path.."lamp.mts", hwidth = 3, hdepth = 3, hheight = 13, hsize = 10, max_num = 0.1, rplc = "n"}, {name = "lamp", mts = schem_path.."lamp.mts", hwidth = 3, hdepth = 3, hheight = 13, hsize = 10, max_num = 0.1, rplc = "n"},
{name = "library", mts = schem_path.."library.mts", hwidth = 12, hdepth = 12, hheight = 8, hsize = 13, max_num = 0.04, rplc = "n"}, {name = "library", mts = schem_path.."library.mts", hwidth = 12, hdepth = 12, hheight = 8, hsize = 13, max_num = 0.04, rplc = "n"},
{name = "medium_house", mts = schem_path.."medium_house.mts", hwidth = 8, hdepth = 12, hheight = 8, hsize = 14, max_num = 0.09, rplc = "n"}, {name = "medium_house", mts = schem_path.."medium_house.mts", hwidth = 8, hdepth = 12, hheight = 8, hsize = 14, max_num = 0.08, rplc = "n"},
{name = "small_house", mts = schem_path.."small_house.mts", hwidth = 9, hdepth = 7, hheight = 8, hsize = 13, max_num = 0.7, rplc = "n"}, {name = "small_house", mts = schem_path.."small_house.mts", hwidth = 9, hdepth = 7, hheight = 8, hsize = 13, max_num = 0.7, rplc = "n"},
{name = "tavern", mts = schem_path.."tavern.mts", hwidth = 11, hdepth = 10, hheight = 10, hsize = 13, max_num = 0.050, rplc = "n"}, {name = "tavern", mts = schem_path.."tavern.mts", hwidth = 11, hdepth = 10, hheight = 10, hsize = 13, max_num = 0.050, rplc = "n"},
{name = "well", mts = schem_path.."well.mts", hwidth = 6, hdepth = 8, hheight = 6, hsize = 10, max_num = 0.045, rplc = "n"}, {name = "well", mts = schem_path.."well.mts", hwidth = 6, hdepth = 8, hheight = 6, hsize = 10, max_num = 0.045, rplc = "n"},

View file

@ -1,3 +1,4 @@
mcl_core mcl_core
mcl_loot
mcl_farming? mcl_farming?
mobs_mc? mobs_mc?

View file

@ -162,7 +162,7 @@ minetest.register_craftitem("mcl_villages:tool", {
-- build ssettlement -- build ssettlement
-- --
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local pr = PseudoRandom(math.rand(0,32767)) local pr = PseudoRandom(math.random(0,32767))
-- enable debug routines -- enable debug routines
local center_surface = pointed_thing.under local center_surface = pointed_thing.under
if center_surface then if center_surface then
@ -213,10 +213,10 @@ minetest.register_craftitem("mcl_villages:tool", {
-- --
if settlements.lvm == true then if settlements.lvm == true then
vm:set_data(data) vm:set_data(data)
settlements.place_schematics_lvm(pr) settlements.place_schematics_lvm(settlement_info, pr)
vm:write_to_map(true) vm:write_to_map(true)
else else
settlements.place_schematics() settlements.place_schematics(settlement_info, pr)
end end
-- --

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

View file

@ -1,3 +1,5 @@
mcl_villages = {}
local c_dirt_with_grass = minetest.get_content_id("mcl_core:dirt_with_grass") local c_dirt_with_grass = minetest.get_content_id("mcl_core:dirt_with_grass")
local c_dirt_with_snow = minetest.get_content_id("mcl_core:dirt_with_grass_snow") local c_dirt_with_snow = minetest.get_content_id("mcl_core:dirt_with_grass_snow")
--local c_dirt_with_dry_grass = minetest.get_content_id("mcl_core:dirt_with_dry_grass") --local c_dirt_with_dry_grass = minetest.get_content_id("mcl_core:dirt_with_dry_grass")
@ -235,33 +237,38 @@ function settlements.fill_chest(pos, pr)
end end
-- fill chest -- fill chest
local inv = minetest.get_inventory( {type="node", pos=chestpos} ) local inv = minetest.get_inventory( {type="node", pos=chestpos} )
-- always function mcl_villages.get_treasures(pr)
inv:add_item("main", "mcl_core:apple "..pr:next(1,3)) local loottable = {
-- low value items {
if pr:next(0,1) < 1 then stacks_min = 3,
inv:add_item("main", "mcl_farming:bread "..pr:next(0,3)) stacks_max = 8,
inv:add_item("main", "mcl_core:iron_ingot "..pr:next(0,3)) items = {
inv:add_item("main", "mcl_farming:melon_item "..pr:next(0,3)) { itemstring = "mcl_core:diamond", weight = 3, amount_min = 1, amount_max = 3 },
inv:add_item("main", "mcl_farming:carrot_item "..pr:next(0,3)) { itemstring = "mcl_core:iron_ingot", weight = 10, amount_min = 1, amount_max = 5 },
--[[ { itemstring = "mcl_core:gold_ingot", weight = 5, amount_min = 1, amount_max = 3 },
-- additional fillings when farmin mod enabled { itemstring = "mcl_farming:bread", weight = 15, amount_min = 1, amount_max = 3 },
if minetest.get_modpath("farming") ~= nil and farming.mod == "redo" then { itemstring = "mcl_core:apple", weight = 15, amount_min = 1, amount_max = 3 },
if pr:next(0,1) < 1 then { itemstring = "mcl_tools:pick_iron", weight = 5 },
inv:add_item("main", "mcl_farming:melon_item "..pr:next(0,3)) { itemstring = "mcl_tools:sword_iron", weight = 5 },
inv:add_item("main", "mcl_farming:carrot_item "..pr:next(0,3)) { itemstring = "mcl_armor:chestplate_iron", weight = 5 },
inv:add_item("main", "farming:corn "..pr:next(0,3)) { itemstring = "mcl_armor:helmet_iron", weight = 5 },
end { itemstring = "mcl_armor:leggings_iron", weight = 5 },
end { itemstring = "mcl_armor:boots_iron", weight = 5 },
--]] { itemstring = "mcl_core:obsidian", weight = 5, amount_min = 3, amount_max = 7 },
end { itemstring = "mcl_core:sapling", weight = 5, amount_min = 3, amount_max = 7 },
-- medium value items { itemstring = "mcl_mobitems:saddle", weight = 3 },
if pr:next(0,3) < 1 then { itemstring = "mobs_mc:iron_horse_armor", weight = 1 },
inv:add_item("main", "mcl_tools:pick_iron "..pr:next(0,1)) { itemstring = "mobs_mc:gold_horse_armor", weight = 1 },
inv:add_item("main", "mcl_tools:pick_stone "..pr:next(0,1)) { itemstring = "mobs_mc:diamond_horse_armor", weight = 1 },
inv:add_item("main", "mcl_fire:flint_and_steel "..pr:next(0,1)) }
inv:add_item("main", "mcl_buckets:bucket_empty "..pr:next(0,1)) },
inv:add_item("main", "mcl_tools:sword_iron "..pr:next(0,1)) }
end local items = mcl_loot.get_multi_loot(loottable, pr)
return items
end
local items = mcl_villages.get_treasures(pr)
mcl_loot.fill_inventory(inv, "main", items)
end end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------