From 10120979cdf2599cb01b144e5b3d123abdf1fb2b Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Mon, 19 Jul 2021 20:37:31 +0200 Subject: [PATCH] Fix bugs --- power/power_terminal2.lua | 2 +- power/powerswitch.lua | 19 ++++++++++++++++++- power/powerswitchbox.lua | 24 ++++++++++++++---------- solar/inverter.lua | 4 ++-- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/power/power_terminal2.lua b/power/power_terminal2.lua index a9ee720..e1513b2 100644 --- a/power/power_terminal2.lua +++ b/power/power_terminal2.lua @@ -44,7 +44,7 @@ end local function formspec1(pos, data) local mem = techage.get_mem(pos) local outdir = M(pos):get_int("outdir") - local netw = networks.get_network_table(pos, Cable, outdir) or {} + local netw = networks.get_network_table(pos, Cable, outdir, true) or {} data = data or power.get_network_data(pos, Cable, outdir) mem.star = ((mem.star or 0) + 1) % 2 diff --git a/power/powerswitch.lua b/power/powerswitch.lua index 65e7355..4cf3577 100644 --- a/power/powerswitch.lua +++ b/power/powerswitch.lua @@ -29,6 +29,18 @@ local Param2ToDir = { [5] = 3, } +local function sign_in(pos, node) + local dir = Param2ToDir[node.param2] + local pos2 = tubelib2.get_pos(pos, dir) + M(pos2):set_int("switch_sign_in", 1) +end + +local function sign_off(pos, node) + local dir = Param2ToDir[node.param2] + local pos2 = tubelib2.get_pos(pos, dir) + M(pos2):set_int("switch_sign_in", 0) +end + local function switch_on(pos, node, clicker, name) if clicker and minetest.is_protected(pos, clicker:get_player_name()) then return @@ -64,7 +76,6 @@ local function switch_off(pos, node, clicker, name) techage.legacy_switches(pos2) power.turn_switch_off(pos2, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") - end @@ -92,12 +103,14 @@ minetest.register_node("techage:powerswitch", { meta:set_string("infotext", S("TA Power Switch").." "..number) local node = minetest.get_node(pos) switch_on(pos, node, placer, "techage:powerswitch_on") + sign_in(pos, node) end, on_rightclick = function(pos, node, clicker) switch_on(pos, node, clicker, "techage:powerswitch_on") end, + after_dig_node = sign_off, on_rotate = screwdriver.disallow, paramtype = "light", use_texture_alpha = techage.CLIP, @@ -129,6 +142,7 @@ minetest.register_node("techage:powerswitch_on", { switch_off(pos, node, clicker, "techage:powerswitch") end, + after_dig_node = sign_off, drop = "techage:powerswitch", on_rotate = screwdriver.disallow, paramtype = "light", @@ -164,12 +178,14 @@ minetest.register_node("techage:powerswitchsmall", { meta:set_string("infotext", S("TA Power Switch Small").." "..number) local node = minetest.get_node(pos) switch_on(pos, node, placer, "techage:powerswitchsmall_on") + sign_in(pos, node) end, on_rightclick = function(pos, node, clicker) switch_on(pos, node, clicker, "techage:powerswitchsmall_on") end, + after_dig_node = sign_off, on_rotate = screwdriver.disallow, paramtype = "light", use_texture_alpha = techage.CLIP, @@ -201,6 +217,7 @@ minetest.register_node("techage:powerswitchsmall_on", { switch_off(pos, node, clicker, "techage:powerswitchsmall") end, + after_dig_node = sign_off, drop = "techage:powerswitchsmall", on_rotate = screwdriver.disallow, paramtype = "light", diff --git a/power/powerswitchbox.lua b/power/powerswitchbox.lua index 7e04aad..763a6e5 100644 --- a/power/powerswitchbox.lua +++ b/power/powerswitchbox.lua @@ -77,11 +77,13 @@ minetest.register_node("techage:powerswitch_box_on", { end, on_rightclick = function(pos, node, clicker) techage.legacy_switches(pos) - if power.turn_switch_off(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then - minetest.sound_play("doors_glass_door_open", { - pos = pos, - gain = 1, - max_hear_distance = 5}) + if M(pos):get_int("switch_sign_in") ~= 1 then + if power.turn_switch_off(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then + minetest.sound_play("doors_glass_door_open", { + pos = pos, + gain = 1, + max_hear_distance = 5}) + end end end, after_dig_node = function(pos, oldnode, oldmetadata, digger) @@ -112,11 +114,13 @@ minetest.register_node("techage:powerswitch_box_off", { }, on_rightclick = function(pos, node, clicker) techage.legacy_switches(pos) - if power.turn_switch_on(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then - minetest.sound_play("doors_glass_door_open", { - pos = pos, - gain = 1, - max_hear_distance = 5}) + if M(pos):get_int("switch_sign_in") ~= 1 then + if power.turn_switch_on(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then + minetest.sound_play("doors_glass_door_open", { + pos = pos, + gain = 1, + max_hear_distance = 5}) + end end end, after_dig_node = function(pos, oldnode, oldmetadata, digger) diff --git a/solar/inverter.lua b/solar/inverter.lua index 2c8f2c3..f2c5eb9 100644 --- a/solar/inverter.lua +++ b/solar/inverter.lua @@ -30,7 +30,7 @@ local COUNTDOWN_TICKS = 1 local function determine_power(pos, nvm) -- determine DC node position local outdir = M(pos):get_int("leftdir") - local netw = networks.get_network_table(pos, Solar, outdir) or {} + local netw = networks.get_network_table(pos, Solar, outdir, true) or {} local num_inv = #(netw.con or {}) local max_power = 0 for _, power in ipairs(control.request(pos, Solar, outdir, "junc", "power")) do @@ -124,7 +124,7 @@ local function node_timer(pos, elapsed) stop_node(pos, nvm, State) elseif not running and has_power then State:start(pos, nvm) - -- start_node() is called implicit + -- start_node() is called implicit elseif running then local meta = M(pos) local outdir = meta:get_int("outdir")