From 74958f5c97623bbd83d5b6602fa932aa683655c6 Mon Sep 17 00:00:00 2001 From: Michal Cieslakiewicz Date: Sun, 7 Oct 2018 19:35:21 +0200 Subject: [PATCH] minertools: add flashlight mode to umg. UMG can now be the source of very bright light if wielded_light mod is also enabled. Signed-off-by: Michal Cieslakiewicz --- minertools/functions.lua | 24 ++++++++++++++++++++++++ minertools/umg.lua | 22 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/minertools/functions.lua b/minertools/functions.lua index 16506b0..101511f 100644 --- a/minertools/functions.lua +++ b/minertools/functions.lua @@ -409,3 +409,27 @@ function minertools.computer_ms_revert_range_change(label, player_name, msg_white .. " and saving") return new_range end + +-- flashlight, should be used with wielded_light mod for effect +function minertools.flashlight_switch(label, player_name, light_flag) + play_click(player_name) + local new_light_on = not light_flag + local ltsw = "OFF" + if new_light_on then ltsw = "ON" end + minetest.chat_send_player(player_name, + msg_yellow .. "[" .. label .. "]" .. msg_white .. + " Switching flashlight to " .. msg_zero .. + ltsw .. msg_white) + return new_light_on +end +function minertools.computer_fl_revert_switch(label, player_name, + light_flag) + local new_light_on = not light_flag + local ltsw = "OFF" + if new_light_on then ltsw = "ON" end + minetest.chat_send_player(player_name, + msg_yellow .. "[" .. label .. "]" .. msg_white .. + " Changing back flashlight to " .. msg_zero .. ltsw .. + msg_white .. " and saving") + return new_light_on +end diff --git a/minertools/umg.lua b/minertools/umg.lua index e3db925..77e34d9 100644 --- a/minertools/umg.lua +++ b/minertools/umg.lua @@ -32,11 +32,16 @@ local umg = {} local MODE_GEOTHERM = 1 local MODE_OREFIND = 2 local MODE_ORESCAN = 3 +local MODE_LIGHT = 4 local mode = MODE_GEOTHERM local mode_name = { [MODE_GEOTHERM] = "Geothermometer", [MODE_OREFIND] = "Mineral Finder", [MODE_ORESCAN] = "Mineral Scanner", } -local tool_range = { [MODE_GEOTHERM] = 12, [MODE_OREFIND] = 8, [MODE_ORESCAN] = 0 } +if minetest.get_modpath("wielded_light") then + mode_name[MODE_LIGHT] = "Flashlight" +end +local tool_range = { [MODE_GEOTHERM] = 12, [MODE_OREFIND] = 8, + [MODE_ORESCAN] = 0, [MODE_LIGHT] = 4 } local scan_range_min = 1 local scan_range_max = 16 local scan_range = scan_range_max @@ -44,6 +49,7 @@ local find_range = 12 local find_stone_idx = 1 local temp_range = 16 local temp_scale = 50.0 +local light_on = false local last_rclick_ts = 0 local find_ore_stones = { "default:stone_with_coal", "default:stone_with_iron", @@ -97,6 +103,13 @@ function umg.change_mode(itemstack, user_placer, pointed_thing) scan_range = minertools.computer_ms_revert_range_change( "UMG:MineralScanner", player_name, scan_range_min, scan_range_max, scan_range) + elseif mode == MODE_LIGHT then + light_on = minertools.computer_fl_revert_switch( + "UMG:Flashlight", player_name, light_on) + local lightlvl = 0 + if light_on then lightlvl = default.LIGHT_MAX end + minetest.override_item("minertools:ultimate_mining_gizmo", + { light_source = lightlvl }) end -- mode change mode = (mode % #mode_name) + 1 @@ -123,6 +136,13 @@ function umg.change_mode(itemstack, user_placer, pointed_thing) scan_range = minertools.mineralscanner_switch_range( "UMG:MineralScanner", player_name, scan_range_min, scan_range_max, scan_range) + elseif mode == MODE_LIGHT then + light_on = minertools.flashlight_switch( + "UMG:Flashlight", player_name, light_on) + local lightlvl = 0 + if light_on then lightlvl = default.LIGHT_MAX end + minetest.override_item("minertools:ultimate_mining_gizmo", + { light_source = lightlvl }) end end last_rclick_ts = rclick_ts