Add crystal (spread laser in all dirs)

master
Wuzzy 2021-12-29 15:24:19 +01:00
parent 30fe6117d6
commit 037d1f9d6f
4 changed files with 57 additions and 2 deletions

View File

@ -229,6 +229,28 @@ register_element("transmissive_mirror", {
})
}, { allow_take = true })
register_element("crystal", {
description = S("Crystal"),
paramtype2 = "facedir",
tiles_takable_off = {
"lzr_laser_crystal.png",
},
tiles_takable_on = {
"lzr_laser_crystal_on.png",
},
tiles_off = {
"lzr_laser_crystal.png^lzr_laser_fixed.png",
},
tiles_on = {
"lzr_laser_crystal_on.png^lzr_laser_fixed.png",
},
groups = { laser_block = 1 },
sounds = lzr_sounds.node_sound_glass_defaults({
_rotate = {name = "lzr_laser_mirror_rotate", gain = 1.0},
})
}, { allow_take = true })
register_element("emitter", {

View File

@ -36,6 +36,9 @@ function lzr_laser.add_laser(pos, dir)
if mirror_dir then
local def = minetest.registered_nodes[node.name]
local active = def._lzr_active
if not active then
return false
end
-- Activate mirror node
minetest.set_node(pos, {name=def._lzr_active, param2 = node.param2})
-- Set new pos and dir
@ -51,6 +54,9 @@ function lzr_laser.add_laser(pos, dir)
if mirror_dir then
local def = minetest.registered_nodes[node.name]
local active = def._lzr_active
if not active then
return false
end
-- Activate mirror node
minetest.set_node(pos, {name=active, param2 = node.param2})
-- Set new pos and dir
@ -58,12 +64,39 @@ function lzr_laser.add_laser(pos, dir)
local dir_straight = dir
local pos_mirrored = vector.add(pos, mirror_dir)
local dir_mirrored = mirror_dir
--return {{pos_straight, dir_straight}}
--return {{pos_mirrored, dir_mirrored}}
return {{pos_straight, dir_straight}, {pos_mirrored, dir_mirrored}}
else
return false
end
-- Spread laser to all directions
elseif minetest.get_item_group(node.name, "crystal") > 0 then
local def = minetest.registered_nodes[node.name]
local active = def._lzr_active
if not active then
return false
end
-- Activate node
minetest.set_node(pos, {name=active, param2 = node.param2})
-- Set dirs
local dirs = {
{ x = 0, y = -1, z = 0 },
{ x = 0, y = 1, z = 0 },
{ x = -1, y = 0, z = 0 },
{ x = 1, y = 0, z = 0 },
{ x = 0, y = 0, z = -1 },
{ x = 0, y = 0, z = 1 },
}
for d=1, #dirs do
if vector.equals(dirs[d], dirs) then
table.remove(dirs, d)
break
end
end
local output = {}
for d=1, #dirs do
table.insert(output, { vector.add(pos, dirs[d]), dirs[d] })
end
return output
-- Detector
elseif minetest.get_item_group(node.name, "detector") > 0 then
local detected = lzr_laser.check_detector(pos, dir)

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B