From 7205e8a69b0af114a477821799eafa60e83b6e9b Mon Sep 17 00:00:00 2001 From: Serhii Mozhaiskyi Date: Fri, 13 Dec 2019 13:35:52 +0200 Subject: [PATCH] Toggle RDS on shift+click --- README.md | 2 +- receiver.lua | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c672fa9..9679919 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Beacon is a simplified transmitter. After placement it automatically tunes on a Handheld receiver is a wielded tool. - Left click opens configuration dialog to set frequency. Empty string turns receiver off. -- Right click toggles reception of RDS messages. +- Shift + left click toggles reception of RDS messages. When receiver is tuned to a frequency where at least one transmitter is present, HUD signal meter bar shows signal power. The signal power depends on distance and direction to the transmitter. diff --git a/receiver.lua b/receiver.lua index dbbb10e..cd248cc 100644 --- a/receiver.lua +++ b/receiver.lua @@ -5,7 +5,18 @@ minetest.register_tool("ham_radio:handheld_receiver", { groups = { disable_repair = 1 }, -- left click - change frequency on_use = function(itemstack, user, pointed_thing) + local keys = user:get_player_control() local meta = itemstack:get_meta() + if keys.sneak then + -- left click with shift - RDS on/off + local is_rds_disabled = meta:get_string("rds_disabled") + if is_rds_disabled == "" then + meta:set_string("rds_disabled", "true") + else + meta:set_string("rds_disabled", "") + end + return itemstack + end local frequency = meta:get_string("frequency") minetest.show_formspec(user:get_player_name(), "ham_radio:configure_handheld_receiver", table.concat({ @@ -19,17 +30,6 @@ minetest.register_tool("ham_radio:handheld_receiver", { },'') ) return itemstack - end, - -- right click - RDS on/off - on_secondary_use = function(itemstack, user, pointed_thing) - local meta = itemstack:get_meta() - local is_rds_disabled = meta:get_string("rds_disabled") - if is_rds_disabled == "" then - meta:set_string("rds_disabled", "true") - else - meta:set_string("rds_disabled", "") - end - return itemstack end })