diff --git a/mods/lzr_laser/physics.lua b/mods/lzr_laser/physics.lua index 19a4b51..7bec696 100644 --- a/mods/lzr_laser/physics.lua +++ b/mods/lzr_laser/physics.lua @@ -1,8 +1,9 @@ -- Max. number of steps in the laser travel algorithm local MAX_LASER_ITERATIONS = 10000 --- TODO: Don't use this variable, instead transport it between functions +-- TODO: Don't use these variables, instead transport it between functions local burning_cache = {} +local destroy_cache = {} -- Add a laser node to pos with the direction `dir`. -- Dir is a direction vector, and only one direction must be set @@ -22,6 +23,9 @@ function lzr_laser.add_laser(pos, dir, varea, vdata) local dirs = lzr_laser.vector_to_dirs(dir) local dirstring = lzr_laser.dirs_to_dirstring(dirs) vdata[vi] = minetest.get_content_id("lzr_laser:laser_"..dirstring) + if ld == 1 then + table.insert(destroy_cache, {pos=pos, nodename=nodename}) + end pos = vector.add(pos, dir) return {{pos, dir}} elseif ld == 2 then @@ -270,6 +274,7 @@ function lzr_laser.full_laser_update(pos1, pos2) local benchmark_time_1 = minetest.get_us_time() burning_cache = {} + destroy_cache = {} local vmanip = minetest.get_voxel_manip(pos1, pos2) local vpos1, vpos2 = vmanip:get_emerged_area() @@ -284,6 +289,7 @@ function lzr_laser.full_laser_update(pos1, pos2) vmanip:set_param2_data(vdata_p2) vmanip:write_to_map() + -- Trigger node burning for nodes burned by laser for b=1, #burning_cache do local node = minetest.get_node(burning_cache[b]) local def = minetest.registered_nodes[node.name] @@ -292,6 +298,31 @@ function lzr_laser.full_laser_update(pos1, pos2) end end burning_cache = {} + -- Trigger animation and sound effect for nodes destroyed by laser + for d=1, #destroy_cache do + local dpos = destroy_cache[d].pos + local nodename = destroy_cache[d].nodename + local def = minetest.registered_nodes[nodename] + if def and def.sounds and def.sounds.dug then + minetest.sound_play(def.sounds.dug, {pos=dpos}, true) + end + minetest.add_particlespawner({ + amount = 12, + time = 0.001, + minpos = vector.subtract(dpos, vector.new(0.5, 0.5, 0.5)), + maxpos = vector.add(dpos, vector.new(0.5, 0.5, 0.5)), + minvel = vector.new(-0.5, -0.2, -0.5), + maxvel = vector.new(0.5, 0.2, 0.5), + minacc = vector.new(0, -lzr_globals.GRAVITY, 0), + maxacc = vector.new(0, -lzr_globals.GRAVITY, 0), + minsize = 0.8, + maxsize = 0.8, + minexptime = 0.5, + maxexptime = 0.55, + node = {name=nodename}, + }) + end + destroy_cache = {} -- Print benchmark time local benchmark_time_2 = minetest.get_us_time()