From c288b6ab93ac5e8189d94f1e64f126939951dc91 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Sun, 13 Nov 2022 14:22:00 -0800 Subject: [PATCH] make townaura more preformant --- mods/ITEMS/mcl_core/nodes_base.lua | 42 +++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index 27f879d5e..5474142d3 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -448,28 +448,40 @@ minetest.register_node("mcl_core:mycelium", { }) mcl_core.register_snowed_node("mcl_core:mycelium_snow", "mcl_core:mycelium", nil, nil, false, S("Mycelium with Snow")) +local PARTICLE_ABM_DISTANCE = 16 --if minetest.settings:get("mcl_node_particles") == "full" then minetest.register_abm({ label = "Townaura particles", nodenames = {"group:mycelium"}, - interval = 0.1, + interval = 2, chance = 30, action = function(pos, node) - local apos = {x=pos.x, y=pos.y+0.51, z=pos.z} - local vel = { x = math.random(-3, 3)/10, y = math.random(0, 10)/60, z = math.random(-3, 3)/10 } - local acc = { x = 0, y = 0, z = 0 } - minetest.add_particle({ - pos = apos, - velocity = vel, - acceleration = acc, - expirationtime = 4, - collisiondetection = true, - collision_removal = true, - size = 1, - texture = "mcl_core_mycelium_particle.png", - glow = LIGHT_LAVA, - }) + local player_near = false + for _,player in pairs(minetest.get_connected_players()) do + if vector.distance(player:get_pos(), pos) < PARTICLE_ABM_DISTANCE then + player_near = true + end + end + if player_near then + local apos = {x=pos.x-2, y=pos.y+0.51, z=pos.z-2} + local apos2 = {x=pos.x+2, y=pos.y+0.51, z=pos.z+2} + local acc = { x = 0, y = 0, z = 0 } + minetest.add_particlespawner({ + time = 2, + amount = 5, + minpos = apos, + maxpos = apos2, + minvel = vector.new(-3/10, 0, -3/10), + maxvel = vector.new(3/10, 10/60, 3/10), + minacc = acc, + expirationtime = 4, + collisiondetection = true, + collision_removal = true, + size = 1, + texture = "mcl_core_mycelium_particle.png", + }) + end end, }) --end