replace nether dust particles with p. spawners

mcl2 uses add_particle for nether dust resulting in a 10-fold
increase in network traffic when in the nether. Nether dust is not
configurable making it impossible to turn this off for server admins.
this commit replaces the add_particle method with particle spawners
This commit is contained in:
cora 2021-09-25 02:06:39 +02:00 committed by Gitea
parent 53715212a2
commit 7f1bb7af92
1 changed files with 58 additions and 28 deletions

View File

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