Compare commits

...

11 Commits

Author SHA1 Message Date
cora 9db099fe6d add more rain particles during thunder 2021-09-25 03:39:20 +02:00
cora 22c49ea605 fix typo 2021-09-25 03:38:55 +02:00
cora 85304ae8a3 nether dust: do not show in the overworld 2021-09-25 03:07:51 +02:00
cora 4281165c6c nether dust: remove obsolete line 2021-09-25 03:07:14 +02:00
cora d079493056 replace snow particles with particlespawner 2021-09-25 03:05:18 +02:00
cora 62afe49987 replace nether dust particles with spawners 2021-09-25 02:06:39 +02:00
cora 98eb0a1860 switch to infinitely lived particle spawners
infinitely lived particle spawners (time=0) can be used coord safely if
only send to a particular player. this saves on even more packets.
2021-09-25 00:10:50 +02:00
cora a35c5b66cb fix rain not showing for freshly joined players 2021-09-24 01:07:00 +02:00
cora 9b42b0d5c7 don't rain when indoors 2021-09-24 01:06:30 +02:00
cora 1adcdc1dbb add different falling speeds for rain and thunder 2021-09-24 01:05:51 +02:00
cora a78fe52970 weather, rain: replace add_particle by spawner 2021-09-23 21:38:13 +02:00
3 changed files with 240 additions and 104 deletions

View File

@ -1,36 +1,70 @@
mcl_weather.nether_dust = {}
mcl_weather.nether_dust.particles_count = 99
mcl_weather.nether_dust.particlespawners = {}
-- calculates coordinates and draw particles for Nether dust
mcl_weather.nether_dust.add_dust_particles = function(player)
for i=mcl_weather.nether_dust.particles_count, 1,-1 do
local rpx, rpy, rpz = mcl_weather.get_random_pos_by_player_look_dir(player)
minetest.add_particle({
pos = {x = rpx, y = rpy - math.random(6, 18), z = rpz},
velocity = {x = math.random(-30,30)*0.01, y = math.random(-15,15)*0.01, z = math.random(-30,30)*0.01},
acceleration = {x = math.random(-50,50)*0.02, y = math.random(-20,20)*0.02, z = math.random(-50,50)*0.02},
expirationtime = 3,
size = math.random(6,20)*0.01,
collisiondetection = false,
object_collision = false,
vertical = false,
glow = math.random(0,minetest.LIGHT_MAX),
texture = "mcl_particles_nether_dust"..tostring(i%3+1)..".png",
playername = player:get_player_name()
})
local psdef= {
amount = 99,
time = 0,
minpos = vector.new(-25,0,-25),
maxpos =vector.new(25,15,25),
minvel = vector.new(-0.3,-0.15,-1),
maxvel = vector.new(0.3,0.15,0.3),
minacc = vector.new(-1,-0.4,-1),
maxacc = vector.new(1,0.4,1),
minexptime = 1,
maxexptime = 1,
minsize = mins,
maxsize = maxs,
collisiondetection = false,
collision_removal = false,
object_collision = false,
vertical = false,
glow = math.random(0,minetest.LIGHT_MAX)
}
local function check_player(player)
local name=player:get_player_name(name)
if mcl_worlds.has_dust(player:get_pos()) and not mcl_weather.nether_dust.particlespawners[name] then
return true
end
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 0.7 then return end
timer = 0
mcl_weather.nether_dust.add_particlespawners = function(player)
if not check_player(player) then return end
local name=player:get_player_name(name)
mcl_weather.nether_dust.particlespawners[name]={}
psdef.playername = name
psdef.attached = player
for i=1,3 do
psdef.texture="mcl_particles_nether_dust"..i..".png"
mcl_weather.nether_dust.particlespawners[name][i]=minetest.add_particlespawner(psdef)
end
end
for _, player in ipairs(minetest.get_connected_players()) do
if not mcl_worlds.has_dust(player:get_pos()) then
return false
mcl_weather.nether_dust.delete_particlespawners = function(player)
local name=player:get_player_name(name)
if mcl_weather.nether_dust.particlespawners[name] then
for i=1,3 do
minetest.delete_particlespawner(mcl_weather.nether_dust.particlespawners[name][i])
end
mcl_weather.nether_dust.add_dust_particles(player)
mcl_weather.nether_dust.particlespawners[name]=nil
end
end
mcl_worlds.register_on_dimension_change(function(player, dimension)
if dimension == "nether" then
if check_player(player) then
mcl_weather.nether_dust.add_particlespawners(player)
end
else
mcl_weather.nether_dust.delete_particlespawners(player)
end
end)
minetest.register_on_joinplayer(function(player)
if check_player(player) then
mcl_weather.nether_dust.add_particlespawners(player)
end
end)
minetest.register_on_leaveplayer(function(player)
mcl_weather.nether_dust.delete_particlespawners(player)
end)

View File

@ -1,5 +1,7 @@
local PARTICLES_COUNT_RAIN = 30
local PARTICLES_COUNT_THUNDER = 45
local PARTICLES_COUNT_RAIN = 800
local PARTICLES_COUNT_THUNDER = 1200
local PARTICLES_SPEED_RAIN = 10
local PARTICLES_SPEED_THUNDER = 15
mcl_weather.rain = {
-- max rain particles created at time
@ -8,6 +10,9 @@ mcl_weather.rain = {
-- flag to turn on/off extinguish fire for rain
extinguish_fire = true,
-- falling speed of the raindrops
falling_speed = PARTICLES_SPEED_RAIN,
-- flag useful when mixing weathers
raining = false,
@ -16,6 +21,8 @@ mcl_weather.rain = {
sky_last_update = -1,
init_done = false,
ps = {}
}
mcl_weather.rain.sound_handler = function(player)
@ -42,29 +49,55 @@ mcl_weather.rain.set_sky_box = function()
end
end
-- creating manually parctiles instead of particles spawner because of easier to control
-- spawn position.
mcl_weather.rain.add_rain_particles = function(player)
-- ~~creating manually parctiles instead of particles spawner because of easier to control spawn position~~.
-- why, mcl2, WHY???
-- use particle spawner to not send .. you know hundreds of packets per second for each f*ing rain particle
local function get_spawnerdef(dtype)
local textures = {"weather_pack_rain_raindrop_1.png", "weather_pack_rain_raindrop_2.png", "weather_pack_rain_raindrop_1.png"}
local rt = {
amount = 800,
time = 0,
minpos = vector.new(-15,5,-15),
maxpos = vector.new(15,10,15),
minvel = vector.new(0, -5,0),
maxvel = vector.new(0,-15,0),
minacc = vector.new(0,-10,0),
maxacc = vector.new(0,-30,0),
minexptime = 1,
maxexptime = 1,
minsize = 0.5,
maxsize = 5,
collisiondetection = true,
collision_removal = true,
object_collision = true,
vertical = true,
texture = mcl_weather.rain.get_texture(),
-- animation = {Tile Animation definition},
glow = 0
-- node = {name = "ignore", param2 = 0},
--node_tile = 0,
}
return rt
end
mcl_weather.rain.add_rain_particlespawner = function(name,def)
local player = minetest.get_player_by_name(name)
if not player then return end
mcl_weather.rain.last_rp_count = 0
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)
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
minetest.add_particle({
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
velocity = {x=0, y=-10, z=0},
acceleration = {x=0, y=-30, z=0},
expirationtime = 1.0,
size = math.random(0.5, 3),
collisiondetection = true,
collision_removal = true,
vertical = true,
texture = mcl_weather.rain.get_texture(),
playername = player:get_player_name()
})
end
end
local name=player:get_player_name()
if mcl_weather.is_outdoor(player:get_pos()) then
if mcl_weather.state ~= "thunder" then def.amount=PARTICLES_COUNT_THUNDER end
def.player = name
def.attached = player
mcl_weather.rain.ps[name] = minetest.add_particlespawner(def)
end
mcl_weather.rain.init_done = true
end
-- Simple random texture getter
@ -88,15 +121,33 @@ mcl_weather.rain.add_player = function(player)
local player_meta = {}
player_meta.origin_sky = {player:get_sky()}
mcl_weather.players[player:get_player_name()] = player_meta
mcl_weather.rain.add_rain_particlespawner(player:get_player_name(),get_spawnerdef("rain"))
end
end
minetest.register_on_joinplayer(function(player)
if mcl_weather.rain.raining then
mcl_weather.rain.add_player(player)
end
end)
minetest.register_on_leaveplayer(function(player)
if mcl_weather.rain.raining then
mcl_weather.rain.remove_player(player)
end
end)
-- remove player from player list effected by rain.
-- be sure to remove sound before removing player otherwise soundhandler reference will be lost.
mcl_weather.rain.remove_player = function(player)
local player_meta = mcl_weather.players[player:get_player_name()]
local name = player:get_player_name()
local player_meta = mcl_weather.players[name]
local ps = mcl_weather.rain.ps[name]
if ps then
minetest.delete_particlespawner(ps,name)
end
mcl_weather.rain.ps[name]=nil
if player_meta ~= nil and player_meta.origin_sky ~= nil then
player:set_clouds({color="#FFF0F0E5"})
mcl_weather.rain.remove_sound(player)
mcl_weather.players[player:get_player_name()] = nil
end
end
@ -155,7 +206,6 @@ mcl_weather.rain.clear = function()
mcl_weather.rain.set_particles_mode("rain")
mcl_weather.skycolor.remove_layer("weather-pack-rain-sky")
for _, player in ipairs(minetest.get_connected_players()) do
mcl_weather.rain.remove_sound(player)
mcl_weather.rain.remove_player(player)
end
end
@ -173,16 +223,16 @@ mcl_weather.rain.make_weather = function()
mcl_weather.rain.raining = true
mcl_weather.rain.set_sky_box()
mcl_weather.rain.set_particles_mode(mcl_weather.mode)
mcl_weather.rain.init_done = true
end
for _, player in ipairs(minetest.get_connected_players()) do
if mcl_weather.players[player:get_player_name()] == nil then
mcl_weather.rain.add_player(player)
end
if (mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos())) then
mcl_weather.rain.remove_sound(player)
return false
end
mcl_weather.rain.add_player(player)
mcl_weather.rain.add_rain_particles(player)
mcl_weather.rain.update_sound(player)
end
end
@ -191,8 +241,10 @@ end
mcl_weather.rain.set_particles_mode = function(mode)
if mode == "thunder" then
mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER
mcl_weather.rain.falling_speed = PARTICLES_SPEED_THUNDER
else
mcl_weather.rain.particles_count = PARTICLES_COUNT_RAIN
mcl_weather.rain.falling_speed = PARTICLES_SPEED_RAIN
end
end

View File

@ -1,31 +1,58 @@
mcl_weather.snow = {}
mcl_weather.snow.particlespawners = {}
mcl_weather.snow.particles_count = 15
mcl_weather.snow.init_done = false
local psdef= {
amount = 30,
time = 0,
minpos = vector.new(-15,5,-15),
maxpos =vector.new(15,10,15),
minvel = vector.new(0,-1,0),
maxvel = vector.new(0,-4,0),
minacc = vector.new(0,-1,0),
maxacc = vector.new(0,-4,0),
minexptime = 1,
maxexptime = 1,
minsize = 0.5,
maxsize = 5,
collisiondetection = true,
collision_removal = true,
object_collision = true,
vertical = true,
glow = 1
}
-- calculates coordinates and draw particles for snow weather
mcl_weather.snow.add_snow_particles = function(player)
mcl_weather.rain.last_rp_count = 0
for i=mcl_weather.snow.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)
random_pos_y = math.random() + math.random(player:get_pos().y - 1, player:get_pos().y + 7)
if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then
mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1
minetest.add_particle({
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
velocity = {x = math.random(-100,100)*0.001, y = math.random(-300,-100)*0.004, z = math.random(-100,100)*0.001},
acceleration = {x = 0, y=0, z = 0},
expirationtime = 8.0,
size = 1,
collisiondetection = true,
collision_removal = true,
object_collision = false,
vertical = false,
texture = mcl_weather.snow.get_texture(),
playername = player:get_player_name()
})
end
local function check_player(player)
if mcl_weather.state ~= "snow" then return false end
local name=player:get_player_name(name)
if mcl_worlds.has_weather(player:get_pos()) and not mcl_weather.snow.particlespawners[name] then
return true
end
return false
end
mcl_weather.snow.add_particlespawners = function(player)
if not check_player(player) then
mcl_weather.snow.delete_particlespawners(player)
return
end
local name=player:get_player_name(name)
mcl_weather.snow.particlespawners[name]={}
psdef.playername = name
psdef.attached = player
for i=1,2 do
psdef.texture="weather_pack_snow_snowflake"..i..".png"
mcl_weather.snow.particlespawners[name][i]=minetest.add_particlespawner(psdef)
end
end
mcl_weather.snow.delete_particlespawners = function(player)
local name=player:get_player_name(name)
if mcl_weather.snow.particlespawners[name] then
for i=1,2 do
minetest.delete_particlespawner(mcl_weather.snow.particlespawners[name][i])
end
mcl_weather.snow.particlespawners[name]=nil
end
end
mcl_weather.snow.set_sky_box = function()
@ -38,47 +65,70 @@ mcl_weather.snow.set_sky_box = function()
{r=0, g=0, b=0}})
mcl_weather.skycolor.active = true
for _, player in ipairs(minetest.get_connected_players()) do
player:set_clouds({color="#ADADADE8"})
end
mcl_weather.skycolor.active = true
end
mcl_weather.snow.start_player = function(player)
if check_player(player) then
mcl_weather.snow.add_particlespawners(player)
player:set_clouds({color="#ADADADE8"})
end
end
mcl_weather.snow.clear_player = function(player)
mcl_weather.snow.delete_particlespawners(player)
end
mcl_weather.snow.start = function()
for _, player in ipairs(minetest.get_connected_players()) do
mcl_weather.snow.start_player(player)
end
mcl_weather.snow.set_sky_box()
mcl_weather.snow.init_done = true
end
mcl_weather.snow.clear = function()
for _, player in ipairs(minetest.get_connected_players()) do
mcl_weather.snow.clear_player(player)
end
mcl_weather.skycolor.remove_layer("weather-pack-snow-sky")
mcl_weather.snow.init_done = false
end
-- Simple random texture getter
mcl_weather.snow.get_texture = function()
return "weather_pack_snow_snowflake"..math.random(1,2)..".png"
end
local timer = 0
minetest.register_globalstep(function(dtime)
if mcl_weather.state ~= "snow" then
return false
end
if mcl_weather.state ~= "snow" then
return false
end
timer = timer + dtime;
if timer >= 0.5 then
timer = 0
else
return
end
if mcl_weather.snow.init_done == false then
mcl_weather.snow.set_sky_box()
mcl_weather.snow.init_done = true
end
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
return false
end
mcl_weather.snow.add_snow_particles(player)
end
if mcl_weather.rain.init_done == false then
mcl_weather.snow.start()
mcl_weather.rain.set_sky_box()
mcl_weather.rain.set_particles_mode(mcl_weather.mode)
elseif mcl_weather.state ~= "snow" then
mcl_weather.snow.clear()
end
end)
minetest.register_on_joinplayer(function(player)
mcl_weather.snow.start_player(player)
end)
minetest.register_on_leaveplayer(function(player)
mcl_weather.snow.clear_player(player)
end)
mcl_worlds.register_on_dimension_change(function(player, dimension)
if dimension == "overworld" then
mcl_weather.snow.add_particlespawners(player)
else
mcl_weather.snow.delete_particlespawners(player)
end
end)
-- register snow weather
if mcl_weather.reg_weathers.snow == nil then
mcl_weather.reg_weathers.snow = {