Compare commits
5 Commits
9bb9a6cecb
...
fa9e15628d
Author | SHA1 | Date |
---|---|---|
Arturas Norkus | fa9e15628d | |
Artūras | d9c26aba55 | |
Arturas Norkus | 2a8c2d0566 | |
Elon Satoshi | 0efa6f9e44 | |
Arturas Norkus | c6987629e5 |
|
@ -4,8 +4,8 @@ Weather mod for Minetest (http://minetest.net/)
|
|||
|
||||
Feedback and Improvements
|
||||
-----------------------
|
||||
* See newest version at https://github.com/xeranas/weather_pack
|
||||
* Register bugs at https://github.com/xeranas/weather_pack/issues
|
||||
* See newest version at https://gitlab.com/zombiebot/weather_pack
|
||||
* Register bugs at https://gitlab.com/zombiebot/weather_pack/issues
|
||||
* Questions / Discussion at https://forum.minetest.net/viewtopic.php?p=215869
|
||||
|
||||
Weathers included
|
||||
|
|
6
init.lua
6
init.lua
|
@ -11,6 +11,12 @@ if minetest.get_modpath("happy_weather_api") == nil then
|
|||
dofile(modpath.."/commands.lua")
|
||||
end
|
||||
|
||||
legacy_MT_version = false
|
||||
if minetest.get_humidity == nil then
|
||||
minetest.log("warning", "MOD [weather_pack]: Old Minetest version detected, some mod features will not work.")
|
||||
legacy_MT_version = true
|
||||
end
|
||||
|
||||
-- Happy Weather utilities
|
||||
dofile(modpath.."/utils.lua")
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ happy_weather = {}
|
|||
-- Local variables which helps organize active and deactive weahers
|
||||
local registered_weathers = {}
|
||||
local active_weathers = {}
|
||||
local meta_plawpos = {} -- meta about Player Last Active Weaher Position
|
||||
|
||||
------------------------------------
|
||||
-- Local helper / utility methods --
|
||||
|
@ -79,6 +80,44 @@ local is_player_affected = function(affected_players, player_name)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
local remove_meta_plawpos = function(weather_code, player_name)
|
||||
if #meta_plawpos == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for k, meta_ in ipairs(meta_plawpos) do
|
||||
if (meta_.name == player_name and meta_.code == weather_code) then
|
||||
table.remove(meta_plawpos, k)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local add_meta_plawpos = function(weather_code, player)
|
||||
local meta = {}
|
||||
meta.code = weather_code
|
||||
meta.pos = player:getpos()
|
||||
meta.name = player:get_player_name()
|
||||
|
||||
remove_meta_plawpos(weather_code, player:get_player_name())
|
||||
table.insert(meta_plawpos, meta)
|
||||
end
|
||||
|
||||
local get_meta_plawpos = function(weather_code, player_name)
|
||||
if #meta_plawpos == 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
for k, meta_ in ipairs(meta_plawpos) do
|
||||
if (meta_.name == player_name and meta_.code == weather_code) then
|
||||
return meta_.pos
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
---------------------------
|
||||
-- Weather API functions --
|
||||
---------------------------
|
||||
|
@ -179,7 +218,7 @@ local weather_remove_player = function(weather_obj, player)
|
|||
weather_obj.remove_player(player)
|
||||
end
|
||||
|
||||
-- Weather remove_player method nil-safe wrapper
|
||||
-- Weather in_area method nil-safe wrapper
|
||||
local weather_in_area = function(weather_obj, position)
|
||||
if weather_obj.in_area == nil then
|
||||
return true
|
||||
|
@ -224,14 +263,36 @@ local prepare_starting = function(weather_obj)
|
|||
add_active_weather(weather_obj)
|
||||
end
|
||||
|
||||
local MAX_DISTANCE_FROM_WEATHER = 35
|
||||
|
||||
-- This function aims to remove weather flickering effect when player walks on biome edge.
|
||||
-- To accomlish that extra distance is applied before removing player from weather affection.
|
||||
local is_outside_recent_weather = function(weather_code, player)
|
||||
local pos = get_meta_plawpos(weather_code, player:get_player_name())
|
||||
if pos == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
local ppos = player:getpos()
|
||||
local d = ((ppos.x - pos.x)^2 + (ppos.y - pos.y)^2 + (ppos.z - pos.z)^2)^0.5
|
||||
return MAX_DISTANCE_FROM_WEATHER - d < 0
|
||||
end
|
||||
|
||||
|
||||
-- While still active weather can or can not affect players based on area they are
|
||||
local render_if_in_area = function(weather_obj, dtime, player)
|
||||
if is_player_affected(weather_obj.affected_players, player:get_player_name()) then
|
||||
if weather_in_area(weather_obj, player:getpos()) then
|
||||
weather_render(weather_obj, dtime, player)
|
||||
add_meta_plawpos(weather_obj.code, player)
|
||||
else
|
||||
weather_remove_player(weather_obj, player)
|
||||
remove_player(weather_obj.affected_players, player:get_player_name())
|
||||
if (is_outside_recent_weather(weather_obj.code, player)) then
|
||||
weather_remove_player(weather_obj, player)
|
||||
remove_player(weather_obj.affected_players, player:get_player_name())
|
||||
-- render weather until player will be completely outside weather range
|
||||
else
|
||||
weather_render(weather_obj, dtime, player)
|
||||
end
|
||||
end
|
||||
else
|
||||
if weather_in_area(weather_obj, player:getpos()) then
|
||||
|
@ -273,7 +334,7 @@ minetest.register_globalstep(function(dtime)
|
|||
remove_player(weather_.affected_players, player:get_player_name())
|
||||
deactivate_weather = true -- should remain true until all players will be removed from weather
|
||||
|
||||
-- Weather still active updating it
|
||||
-- Weather still active updating it
|
||||
else
|
||||
render_if_in_area(weather_, dtime, player)
|
||||
end
|
||||
|
|
13
utils.lua
13
utils.lua
|
@ -78,23 +78,27 @@ hw_utils.get_random_pos = function(player, offset)
|
|||
end
|
||||
|
||||
local is_biome_frozen = function(position)
|
||||
if legacy_MT_version then
|
||||
return false;
|
||||
end
|
||||
local heat = minetest.get_heat(position)
|
||||
print("karstis: " .. heat)
|
||||
-- below 35 heat biome considered to be frozen type
|
||||
return heat < 35
|
||||
end
|
||||
|
||||
hw_utils.is_biome_frozen = function(position)
|
||||
if mg_name == "v6" then
|
||||
return false -- v6 not supported yet.
|
||||
return false -- v6 not supported.
|
||||
end
|
||||
return is_biome_frozen(position)
|
||||
end
|
||||
|
||||
local is_biome_dry = function(position)
|
||||
if legacy_MT_version then
|
||||
return false;
|
||||
end
|
||||
local humidity = minetest.get_humidity(position)
|
||||
local heat = minetest.get_heat(position)
|
||||
print("DREGME: " .. humidity)
|
||||
return humidity < 50 and heat > 65
|
||||
end
|
||||
|
||||
|
@ -106,6 +110,9 @@ hw_utils.is_biome_dry = function(position)
|
|||
end
|
||||
|
||||
local is_biome_tropic = function(position)
|
||||
if legacy_MT_version then
|
||||
return false;
|
||||
end
|
||||
local humidity = minetest.get_humidity(position)
|
||||
local heat = minetest.get_heat(position)
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ local snowstorm = {}
|
|||
-- Weather identification code
|
||||
snowstorm.code = "snowstorm"
|
||||
snowstorm.last_check = 0
|
||||
snowstorm.check_interval = 5
|
||||
snowstorm.chance = 1
|
||||
snowstorm.check_interval = 300
|
||||
snowstorm.chance = 0.05
|
||||
|
||||
-- Keeps sound handler references
|
||||
local sound_handlers = {}
|
||||
|
@ -137,6 +137,40 @@ local add_wide_range_rain_particle = function(player)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
-- Random texture getter
|
||||
local choice_random_rain_drop_texture = function()
|
||||
local base_name = "happy_weather_light_snow_snowflake_"
|
||||
local number = math.random(1, 3)
|
||||
local extension = ".png"
|
||||
return base_name .. number .. extension
|
||||
end
|
||||
|
||||
local add_snow_particle = function(player)
|
||||
local offset = {
|
||||
front = 5,
|
||||
back = 2,
|
||||
top = 4
|
||||
}
|
||||
|
||||
local random_pos = hw_utils.get_random_pos(player, offset)
|
||||
|
||||
if hw_utils.is_outdoor(random_pos) then
|
||||
minetest.add_particle({
|
||||
pos = {x=random_pos.x, y=random_pos.y, z=random_pos.z},
|
||||
velocity = {x = math.random(-5,-2.5), y = math.random(-10,-5), z = math.random(-5,-2.5)},
|
||||
acceleration = {x = math.random(-5,-2.5), y=-2.5, z = math.random(-5,-2.5)},
|
||||
expirationtime = 2.0,
|
||||
size = math.random(1, 3),
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
vertical = true,
|
||||
texture = choice_random_rain_drop_texture(),
|
||||
playername = player:get_player_name()
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local display_particles = function(player)
|
||||
if hw_utils.is_underwater(player) then
|
||||
return
|
||||
|
@ -146,6 +180,11 @@ local display_particles = function(player)
|
|||
for i=particles_number_per_update, 1,-1 do
|
||||
add_wide_range_rain_particle(player)
|
||||
end
|
||||
|
||||
local snow_particles_number_per_update = 10
|
||||
for i=snow_particles_number_per_update, 1,-1 do
|
||||
add_snow_particle(player)
|
||||
end
|
||||
end
|
||||
|
||||
snowstorm.render = function(dtime, player)
|
||||
|
|
Loading…
Reference in New Issue