forked from mtcontrib/weather_pack
minor code cleanup
This commit is contained in:
parent
1f07735c44
commit
e90133b30a
@ -9,6 +9,7 @@
|
||||
local light_rain = {}
|
||||
light_rain.last_check = 0
|
||||
light_rain.check_interval = 200
|
||||
light_rain.chance = 0.15
|
||||
|
||||
-- Weather identification code
|
||||
light_rain.code = "light_rain"
|
||||
@ -26,7 +27,7 @@ local SKYCOLOR_LAYER = "happy_weather_light_rain_sky"
|
||||
light_rain.is_starting = function(dtime, position)
|
||||
if light_rain.last_check + light_rain.check_interval < os.time() then
|
||||
light_rain.last_check = os.time()
|
||||
if math.random() < 0.15 then
|
||||
if math.random() < light_rain.chance then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -98,16 +99,10 @@ end
|
||||
|
||||
-- Random texture getter
|
||||
local choice_random_rain_drop_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.33 then
|
||||
texture_name = "happy_weather_light_rain_raindrop_1.png"
|
||||
elseif random_number > 0.66 then
|
||||
texture_name = "happy_weather_light_rain_raindrop_2.png"
|
||||
else
|
||||
texture_name = "happy_weather_light_rain_raindrop_3.png"
|
||||
end
|
||||
return texture_name;
|
||||
local base_name = "happy_weather_light_rain_raindrop_"
|
||||
local number = math.random(1, 4)
|
||||
local extension = ".png"
|
||||
return base_name .. number .. extension
|
||||
end
|
||||
|
||||
local add_rain_particle = function(player)
|
||||
|
19
rain.lua
19
rain.lua
@ -9,6 +9,7 @@
|
||||
local rain = {}
|
||||
rain.last_check = 0
|
||||
rain.check_interval = 300
|
||||
rain.chance = 0.1
|
||||
|
||||
-- Weather identification code
|
||||
rain.code = "rain"
|
||||
@ -26,7 +27,7 @@ local SKYCOLOR_LAYER = "happy_weather_rain_sky"
|
||||
rain.is_starting = function(dtime, position)
|
||||
if rain.last_check + rain.check_interval < os.time() then
|
||||
rain.last_check = os.time()
|
||||
if math.random() < 0.1 then
|
||||
if math.random() < rain.chance then
|
||||
happy_weather.request_to_end("light_rain")
|
||||
happy_weather.request_to_end("heavy_rain")
|
||||
return true
|
||||
@ -101,16 +102,10 @@ end
|
||||
|
||||
-- Random texture getter
|
||||
local choice_random_rain_drop_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.33 then
|
||||
texture_name = "happy_weather_light_rain_raindrop_1.png"
|
||||
elseif random_number > 0.66 then
|
||||
texture_name = "happy_weather_light_rain_raindrop_2.png"
|
||||
else
|
||||
texture_name = "happy_weather_light_rain_raindrop_3.png"
|
||||
end
|
||||
return texture_name;
|
||||
local base_name = "happy_weather_light_rain_raindrop_"
|
||||
local number = math.random(1, 4)
|
||||
local extension = ".png"
|
||||
return base_name .. number .. extension
|
||||
end
|
||||
|
||||
local add_rain_particle = function(player)
|
||||
@ -128,7 +123,7 @@ local add_rain_particle = function(player)
|
||||
velocity = {x=0, y=-15, z=0},
|
||||
acceleration = {x=0, y=-35, z=0},
|
||||
expirationtime = 2,
|
||||
size = math.random(1, 6),
|
||||
size = math.random(1, 4),
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
vertical = true,
|
||||
|
19
snow.lua
19
snow.lua
@ -9,6 +9,7 @@
|
||||
local snow = {}
|
||||
snow.last_check = 0
|
||||
snow.check_interval = 200
|
||||
snow.chance = 0.2
|
||||
|
||||
-- Weather identification code
|
||||
snow.code = "snow"
|
||||
@ -23,7 +24,7 @@ local SKYCOLOR_LAYER = "happy_weather_snow_sky"
|
||||
snow.is_starting = function(dtime, position)
|
||||
if snow.last_check + snow.check_interval < os.time() then
|
||||
snow.last_check = os.time()
|
||||
if math.random() < 0.2 then
|
||||
if math.random() < snow.chance then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -59,7 +60,7 @@ local set_sky_box = function(player_name)
|
||||
sl.data = {gradient_data={}}
|
||||
sl.data.gradient_data.colors = {
|
||||
{r=0, g=0, b=0},
|
||||
{r=241, g=244, b=249},
|
||||
{r=231, g=234, b=239},
|
||||
{r=0, g=0, b=0}
|
||||
}
|
||||
skylayer.add_layer(player_name, sl)
|
||||
@ -75,16 +76,10 @@ end
|
||||
|
||||
-- Random texture getter
|
||||
local choice_random_rain_drop_texture = function()
|
||||
local texture_name
|
||||
local random_number = math.random()
|
||||
if random_number > 0.33 then
|
||||
texture_name = "happy_weather_light_snow_snowflake_1.png"
|
||||
elseif random_number > 0.66 then
|
||||
texture_name = "happy_weather_light_snow_snowflake_2.png"
|
||||
else
|
||||
texture_name = "happy_weather_light_snow_snowflake_3.png"
|
||||
end
|
||||
return texture_name;
|
||||
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_particle = function(player)
|
||||
|
BIN
textures/happy_weather_light_rain_raindrop_4.png
Normal file
BIN
textures/happy_weather_light_rain_raindrop_4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 256 B |
@ -11,6 +11,7 @@
|
||||
local thunder = {}
|
||||
thunder.last_check = 0
|
||||
thunder.check_interval = 100
|
||||
thunder.chance = 0.8
|
||||
|
||||
-- Weather identification code
|
||||
thunder.code = "thunder"
|
||||
@ -33,7 +34,7 @@ thunder.is_starting = function(dtime)
|
||||
|
||||
if thunder.last_check + thunder.check_interval < os.time() then
|
||||
thunder.last_check = os.time()
|
||||
if math.random() < 0.8 and happy_weather.is_weather_active("heavy_rain") then
|
||||
if math.random() < thunder.chance and happy_weather.is_weather_active("heavy_rain") then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -68,8 +69,8 @@ local calculate_thunder_strike_delay = function()
|
||||
end
|
||||
|
||||
thunder.render = function(dtime, player)
|
||||
if happy_weather.is_player_in_weather_area(player:get_player_name(),
|
||||
"heavy_rain") == false then
|
||||
local player_name = player:get_player_name()
|
||||
if happy_weather.is_player_in_weather_area(player_name, "heavy_rain") == false then
|
||||
return
|
||||
end
|
||||
|
||||
|
33
utils.lua
33
utils.lua
@ -27,7 +27,8 @@ end
|
||||
hw_utils.is_underwater = function(player)
|
||||
local ppos = player:getpos()
|
||||
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,
|
||||
z = ppos.z + offset.z}
|
||||
local node_level = minetest.get_node_level(player_eye_pos)
|
||||
@ -71,7 +72,6 @@ hw_utils.get_random_pos = function(player, offset)
|
||||
random_pos_y = player_pos.y + offset.top
|
||||
end
|
||||
|
||||
|
||||
return {x=random_pos_x, y=random_pos_y, z=random_pos_z}
|
||||
end
|
||||
|
||||
@ -95,15 +95,7 @@ local np_humid = {
|
||||
lacunarity = 2.0
|
||||
}
|
||||
|
||||
hw_utils.is_biome_frozen = function(position)
|
||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||
if mg_name == "v6" then
|
||||
return false -- v6 not supported yet.
|
||||
end
|
||||
return hw_utils.is_biome_frozen_v7(position)
|
||||
end
|
||||
|
||||
hw_utils.is_biome_frozen_v7 = function(position)
|
||||
local is_biome_frozen_v7 = function(position)
|
||||
local posx = math.floor(position.x)
|
||||
local posz = math.floor(position.z)
|
||||
local noise_obj = minetest.get_perlin(np_temp)
|
||||
@ -113,15 +105,15 @@ hw_utils.is_biome_frozen_v7 = function(position)
|
||||
return noise_temp < 35
|
||||
end
|
||||
|
||||
hw_utils.is_biome_dry = function(position)
|
||||
hw_utils.is_biome_frozen = function(position)
|
||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||
if mg_name == "v6" then
|
||||
return false -- v6 not supported yet.
|
||||
end
|
||||
return hw_utils.is_biome_dry_v7(position)
|
||||
return is_biome_frozen_v7(position)
|
||||
end
|
||||
|
||||
hw_utils.is_biome_dry_v7 = function(position)
|
||||
local is_biome_dry_v7 = function(position)
|
||||
local posx = math.floor(position.x)
|
||||
local posz = math.floor(position.z)
|
||||
local noise_obj = minetest.get_perlin(np_humid)
|
||||
@ -131,15 +123,15 @@ hw_utils.is_biome_dry_v7 = function(position)
|
||||
return noise_humid < 50
|
||||
end
|
||||
|
||||
hw_utils.is_biome_tropic = function(position)
|
||||
hw_utils.is_biome_dry = function(position)
|
||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||
if mg_name == "v6" then
|
||||
return false -- v6 not supported yet.
|
||||
end
|
||||
return hw_utils.is_biome_tropic_v7(position)
|
||||
return is_biome_dry_v7(position)
|
||||
end
|
||||
|
||||
hw_utils.is_biome_tropic_v7 = function(position)
|
||||
local is_biome_tropic_v7 = function(position)
|
||||
local posx = math.floor(position.x)
|
||||
local posz = math.floor(position.z)
|
||||
local noise_obj = minetest.get_perlin(np_humid)
|
||||
@ -151,3 +143,10 @@ hw_utils.is_biome_tropic_v7 = function(position)
|
||||
return noise_humid > 55 and noise_temp > 80
|
||||
end
|
||||
|
||||
hw_utils.is_biome_tropic = function(position)
|
||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||
if mg_name == "v6" then
|
||||
return false -- v6 not supported yet.
|
||||
end
|
||||
return is_biome_tropic_v7(position)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user