2021-12-21 07:15:17 -08:00
|
|
|
local S = minetest.get_translator("lzr_laser")
|
|
|
|
|
2021-12-21 12:16:12 -08:00
|
|
|
local mirror_out = {
|
|
|
|
[0] = {1,0,0},
|
|
|
|
[1] = {0,0,-1},
|
|
|
|
[2] = {-1,0,0},
|
|
|
|
[3] = {0,0,1},
|
|
|
|
|
|
|
|
[4] = {1,0,0},
|
|
|
|
[5] = {0,1,0},
|
|
|
|
[6] = {-1,0,0},
|
|
|
|
[7] = {0,-1,0},
|
|
|
|
|
|
|
|
[8] = {1,0,0},
|
|
|
|
[9] = {0,-1,0},
|
|
|
|
[10] = {-1,0,0},
|
|
|
|
[11] = {0,1,0},
|
|
|
|
|
|
|
|
[12] = {0,-1,0},
|
|
|
|
[13] = {0,0,-1},
|
|
|
|
[14] = {0,1,0},
|
|
|
|
[15] = {0,0,1},
|
|
|
|
|
|
|
|
[16] = {0,1,0},
|
|
|
|
[17] = {0,0,-1},
|
|
|
|
[18] = {0,-1,0},
|
|
|
|
[19] = {0,0,1},
|
|
|
|
|
|
|
|
[20] = {-1,0,0},
|
|
|
|
[21] = {0,0,-1},
|
|
|
|
[22] = {1,0,0},
|
|
|
|
[23] = {0,0,1},
|
|
|
|
}
|
|
|
|
|
|
|
|
lzr_laser.get_mirror_dirs = function(param2)
|
|
|
|
local dir_input = minetest.facedir_to_dir(param2)
|
|
|
|
if not dir_input then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
dir_input = vector.multiply(dir_input, -1)
|
|
|
|
local dir_output = vector.new(unpack(mirror_out[param2]))
|
|
|
|
|
|
|
|
return dir_input, dir_output
|
|
|
|
end
|
|
|
|
|
2021-12-21 13:00:51 -08:00
|
|
|
-- Mirror a laser that touches a mirror at mirror_pos with a laser coming towards
|
|
|
|
-- the mirror with the laser_dir direction (direction vector).
|
|
|
|
-- Returns the "output direction" of the laser or false if can't get mirrored.
|
|
|
|
lzr_laser.get_mirrored_laser_dir = function(mirror_pos, laser_dir)
|
|
|
|
local mirror = minetest.get_node(mirror_pos)
|
|
|
|
local mirror_group = minetest.get_item_group(mirror.name, "mirror")
|
|
|
|
if mirror_group == 0 then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local reverse_laser_dir = vector.multiply(laser_dir, -1)
|
|
|
|
local mirror_dir_in, mirror_dir_out = lzr_laser.get_mirror_dirs(mirror.param2)
|
|
|
|
if not mirror_dir_in then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if vector.equals(reverse_laser_dir, mirror_dir_in) then
|
|
|
|
return mirror_dir_out
|
|
|
|
elseif vector.equals(reverse_laser_dir, mirror_dir_out) then
|
|
|
|
return mirror_dir_in
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-12-21 07:15:17 -08:00
|
|
|
minetest.register_node("lzr_laser:mirror", {
|
|
|
|
description = S("Mirror"),
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {
|
|
|
|
"lzr_laser_mirror_top.png",
|
2021-12-21 11:32:54 -08:00
|
|
|
"lzr_laser_mirror_top.png^[transformFY",
|
2021-12-21 07:15:17 -08:00
|
|
|
"lzr_laser_mirror_hole.png",
|
|
|
|
"lzr_laser_mirror_block.png",
|
|
|
|
"lzr_laser_mirror_block.png",
|
|
|
|
"lzr_laser_mirror_hole.png",
|
|
|
|
},
|
2021-12-21 08:45:26 -08:00
|
|
|
groups = { mirror = 1, laser_block = 1, dig_immediate = 2 },
|
|
|
|
_lzr_active = "lzr_laser:mirror_on",
|
2021-12-21 07:15:17 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("lzr_laser:mirror_on", {
|
|
|
|
description = S("Mirror (active)"),
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {
|
|
|
|
"lzr_laser_mirror_on_top.png",
|
|
|
|
"lzr_laser_mirror_on_top.png^[transformFY",
|
|
|
|
"lzr_laser_mirror_on_hole.png",
|
|
|
|
"lzr_laser_mirror_on_block.png",
|
|
|
|
"lzr_laser_mirror_on_block.png",
|
|
|
|
"lzr_laser_mirror_on_hole.png",
|
|
|
|
},
|
2021-12-21 08:45:26 -08:00
|
|
|
groups = { mirror = 2, laser_block = 1, dig_immediate = 2, not_in_creative_inventory = 1 },
|
|
|
|
_lzr_inactive = "lzr_laser:mirror",
|
2021-12-21 07:15:17 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("lzr_laser:emitter", {
|
|
|
|
description = S("Emitter"),
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {
|
|
|
|
"lzr_laser_emitter.png",
|
|
|
|
"lzr_laser_emitter.png",
|
|
|
|
"lzr_laser_emitter.png",
|
|
|
|
"lzr_laser_emitter.png",
|
|
|
|
"lzr_laser_emitter.png",
|
|
|
|
"lzr_laser_emitter_front.png",
|
|
|
|
},
|
2021-12-21 08:45:26 -08:00
|
|
|
groups = { emitter = 1, laser_block = 1, dig_immediate = 2 },
|
|
|
|
_lzr_active = "lzr_laser:emitter_on",
|
2021-12-21 07:15:17 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("lzr_laser:emitter_on", {
|
|
|
|
description = S("Emitter (active)"),
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {
|
|
|
|
"lzr_laser_emitter_on.png",
|
|
|
|
"lzr_laser_emitter_on.png",
|
|
|
|
"lzr_laser_emitter_on.png",
|
|
|
|
"lzr_laser_emitter_on.png",
|
|
|
|
"lzr_laser_emitter_on.png",
|
|
|
|
"lzr_laser_emitter_on_front.png",
|
|
|
|
},
|
2021-12-21 08:45:26 -08:00
|
|
|
groups = { emitter = 2, laser_block = 1, dig_immediate = 2, not_in_creative_inventory = 1 },
|
|
|
|
_lzr_inactive = "lzr_laser:emitter",
|
2021-12-21 07:15:17 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("lzr_laser:detector", {
|
|
|
|
description = S("Detector"),
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {
|
|
|
|
"lzr_laser_detector.png",
|
|
|
|
"lzr_laser_detector.png",
|
|
|
|
"lzr_laser_detector.png",
|
|
|
|
"lzr_laser_detector.png",
|
|
|
|
"lzr_laser_detector.png",
|
|
|
|
"lzr_laser_detector_front.png",
|
|
|
|
},
|
2021-12-21 08:45:26 -08:00
|
|
|
groups = { detector = 1, laser_block = 1, dig_immediate = 2 },
|
|
|
|
_lzr_active = "lzr_laser:detector_on",
|
2021-12-21 07:15:17 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("lzr_laser:detector_on", {
|
|
|
|
description = S("Detector (active)"),
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = {
|
|
|
|
"lzr_laser_detector_on.png",
|
|
|
|
"lzr_laser_detector_on.png",
|
|
|
|
"lzr_laser_detector_on.png",
|
|
|
|
"lzr_laser_detector_on.png",
|
|
|
|
"lzr_laser_detector_on.png",
|
|
|
|
"lzr_laser_detector_on_front.png",
|
|
|
|
},
|
2021-12-21 08:45:26 -08:00
|
|
|
groups = { detector = 2, laser_block = 1, dig_immediate = 2, not_in_creative_inventory = 1 },
|
|
|
|
_lzr_inactive = "lzr_laser:detector",
|
2021-12-21 07:15:17 -08:00
|
|
|
})
|
|
|
|
|