diff --git a/.luacheckrc b/.luacheckrc index 24e3c60..13fa8a9 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -9,8 +9,7 @@ globals = { read_globals = { -- Builtin - table = {fields = {"copy"}}, - + "table.copy", "vector", "ItemStack", "DIR_DELIM", @@ -19,7 +18,8 @@ read_globals = { "default", "mesecon", "screwdriver", - "QoS" + "QoS", + "vizlib", } exclude_files = { diff --git a/camera.lua b/camera.lua index 153929c..204a941 100644 --- a/camera.lua +++ b/camera.lua @@ -13,8 +13,7 @@ local function get_formspec(enabled) end end -local function search_for_players(pos, send_empty) - local meta = minetest.get_meta(pos) +local function get_search_spot(pos, meta) local distance = meta:get_int("distance") local dir = minetest.facedir_to_dir(minetest.get_node(pos).param2) local spot = vector.add(pos, vector.multiply(dir, -distance)) @@ -24,8 +23,15 @@ local function search_for_players(pos, send_empty) node = minetest.get_node(spot) end if node.name == "air" or node.name == "ignore" then - return true + -- Default to directly in front of camera if ground is not found. + spot.y = pos.y end + return spot +end + +local function search_for_players(pos, send_empty) + local meta = minetest.get_meta(pos) + local spot = get_search_spot(pos, meta) local radius = meta:get_int("radius") local found = {} for _,player in pairs(minetest.get_connected_players()) do @@ -40,6 +46,17 @@ local function search_for_players(pos, send_empty) return true end +local function show_area(pos, node, player) + if not player or player:get_wielded_item():get_name() ~= "" then + -- Only show area when using an empty hand + return + end + local meta = minetest.get_meta(pos) + local spot = get_search_spot(pos, meta) + local radius = meta:get_int("radius") + vizlib.draw_sphere(spot, radius, {player = player}) +end + minetest.register_node("digistuff:camera", { description = "Digilines Camera", tiles = { @@ -102,6 +119,7 @@ minetest.register_node("digistuff:camera", { end end, on_timer = search_for_players, + on_punch = minetest.get_modpath("vizlib") and show_area or nil, digiline = { receptor = {}, effector = { diff --git a/detector.lua b/detector.lua index aa4d08d..a4d8b02 100644 --- a/detector.lua +++ b/detector.lua @@ -28,6 +28,15 @@ local function search_for_players(pos, send_empty) return true end +local function show_area(pos, node, player) + if not player or player:get_wielded_item():get_name() ~= "" then + -- Only show area when using an empty hand + return + end + local radius = minetest.get_meta(pos):get_int("radius") + vizlib.draw_sphere(pos, radius, {player = player}) +end + minetest.register_node("digistuff:detector", { description = "Digilines Player Detector", tiles = { @@ -63,6 +72,7 @@ minetest.register_node("digistuff:detector", { end end, on_timer = search_for_players, + on_punch = minetest.get_modpath("vizlib") and show_area or nil, digiline = { receptor = {}, effector = { diff --git a/mod.conf b/mod.conf index eee7768..28c2af5 100644 --- a/mod.conf +++ b/mod.conf @@ -2,4 +2,4 @@ name = digistuff title = digistuff description = Random digilines devices for Minetest depends = digilines -optional_depends = default,mesecons,mesecons_mvps,screwdriver,pipeworks,qos +optional_depends = default, mesecons, mesecons_mvps, screwdriver, pipeworks, qos, vizlib