Add emitter toggler debug tool
parent
adde85e9b7
commit
7be0b0b324
|
@ -0,0 +1,5 @@
|
|||
lzr_globals = {}
|
||||
|
||||
lzr_globals.PLAYFIELD_START = { x = -50, y = 0, z = -50 }
|
||||
lzr_globals.PLAYFIELD_SIZE = { x = 100, y = 100, z = 100 }
|
||||
lzr_globals.PLAYFIELD_END = vector.add(lzr_globals.PLAYFIELD_START, lzr_globals.PLAYFIELD_SIZE)
|
|
@ -4,3 +4,4 @@ dofile(minetest.get_modpath("lzr_laser").."/util.lua")
|
|||
dofile(minetest.get_modpath("lzr_laser").."/laser.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/blocks.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/physics.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/tools.lua")
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
name = lzr_laser
|
||||
depends = lzr_globals
|
||||
|
|
|
@ -75,7 +75,7 @@ function lzr_laser.travel_laser(pos, dir)
|
|||
end
|
||||
|
||||
-- Remove all lasers in area and disable all laser blocks
|
||||
function lzr_laser.clear_lasers_in_area(pos1, pos2)
|
||||
function lzr_laser.clear_lasers_in_area(pos1, pos2, ignore_emitters)
|
||||
-- Remove lasers
|
||||
local lasers = minetest.find_nodes_in_area(pos1, pos2, {"group:laser"})
|
||||
minetest.bulk_set_node(lasers, {name="air"})
|
||||
|
@ -86,7 +86,11 @@ function lzr_laser.clear_lasers_in_area(pos1, pos2)
|
|||
local block_pos = laser_blocks[b]
|
||||
local block = minetest.get_node(block_pos)
|
||||
local def = minetest.registered_nodes[block.name]
|
||||
if def then
|
||||
local is_ignored_emitter = false
|
||||
if ignore_emitters ~= true then
|
||||
is_ignored_emitter = minetest.get_item_group(block.name, "emitter") > 0
|
||||
end
|
||||
if def and not is_ignored_emitter then
|
||||
local inactive = def._lzr_inactive
|
||||
if inactive then
|
||||
minetest.set_node(block_pos, {name=inactive, param2=block.param2})
|
||||
|
@ -94,3 +98,16 @@ function lzr_laser.clear_lasers_in_area(pos1, pos2)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Emit lasers from all active emitters
|
||||
function lzr_laser.emit_lasers_in_area(pos1, pos2)
|
||||
local emitters = minetest.find_nodes_in_area(pos1, pos2, {"group:emitter"})
|
||||
for e=1, #emitters do
|
||||
local epos = emitters[e]
|
||||
local emitter = minetest.get_node(epos)
|
||||
local is_active = minetest.get_item_group(emitter.name, "emitter") == 2
|
||||
if is_active then
|
||||
lzr_laser.emit_laser(emitters[e])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,11 +15,16 @@ minetest.register_tool("lzr_laser:emit_toggler", {
|
|||
return itemstack
|
||||
end
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
-- Deactivate emitter
|
||||
if def._lzr_inactive then
|
||||
minetest.swap_node(pos, {name=def._lzr_inactive, param2=node.param2})
|
||||
lzr_laser.clear_lasers_in_area(lzr_globals.PLAYFIELD_START, lzr_globals.PLAYFIELD_END)
|
||||
lzr_laser.emit_lasers_in_area(lzr_globals.PLAYFIELD_START, lzr_globals.PLAYFIELD_END)
|
||||
-- Activate emitter
|
||||
elseif def._lzr_active then
|
||||
minetest.swap_node(pos, {name=def._lzr_active, param2=node.param2})
|
||||
lzr_laser.emit_laser(pos)
|
||||
lzr_laser.clear_lasers_in_area(lzr_globals.PLAYFIELD_START, lzr_globals.PLAYFIELD_END)
|
||||
lzr_laser.emit_lasers_in_area(lzr_globals.PLAYFIELD_START, lzr_globals.PLAYFIELD_END)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
|
|
Loading…
Reference in New Issue