From ad43f5b744705fd343cd22d05f0b6b0d54cc0d6f Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Tue, 8 Oct 2019 21:13:28 +0200 Subject: [PATCH] solar cell improvements --- coal_power_station/power_terminal.lua | 4 ++-- solar/solarcell.lua | 18 +++++++++++++----- tools/repairkit.lua | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/coal_power_station/power_terminal.lua b/coal_power_station/power_terminal.lua index 0ecf48f..ed52439 100644 --- a/coal_power_station/power_terminal.lua +++ b/coal_power_station/power_terminal.lua @@ -77,8 +77,8 @@ local function collect_network_data(pos, mem) add("fcel", "curr", mem.provided) elseif node.name == "techage:ta4_electrolyzer" or node.name == "techage:ta4_electrolyzer_on" then add("elec", "num", 1) - add("elec", "nomi", -mem.pwr_could_need) - add("elec", "curr", -mem.consumed) + add("elec", "nomi", -(mem.pwr_could_need or 0)) + add("elec", "curr", -(mem.consumed or 0)) end end ) diff --git a/solar/solarcell.lua b/solar/solarcell.lua index 11bb1d0..d5079cc 100644 --- a/solar/solarcell.lua +++ b/solar/solarcell.lua @@ -39,10 +39,9 @@ end -- do we have enough light? local function light(pos) - pos.y = pos.y + 1 + if minetest.get_node(pos).name ~= "air" then return false end local light = minetest.get_node_light(pos) or 0 - pos.y = pos.y - 1 - return light >= (minetest.LIGHT_MAX - 1) + return light >= (15 - 1) end -- check if solar module is available and has the correct orientation @@ -50,7 +49,8 @@ local function is_solar_module(base_pos, pos, side) local pos1 = techage.get_pos(pos, side) if pos1 then local node = techage.get_node_lvm(pos1) - if node and node.name == "techage:ta4_solar_module" and light(pos1) then + if node and node.name == "techage:ta4_solar_module" and + light({x = pos1.x, y = pos1.y + 1, z = pos1.z}) then if side == "L" and node.param2 == M(base_pos):get_int("left_param2") then return true elseif side == "R" and node.param2 == M(base_pos):get_int("right_param2") then @@ -94,7 +94,15 @@ minetest.register_node("techage:ta4_solar_module", { {-1/2, 7/16, -1/2, 1/2, 8/16, 16/16}, }, }, - + techage_info = function(pos) + local power = 0 + local pos1 = {x = pos.x, y = pos.y + 1, z = pos.z} + if light(pos1) then + power = PWR_PERF * temperature(pos) / 200.0 + end + local light = minetest.get_node_light(pos1).." / " ..15 + return S("power").." = "..power..", "..S("light").." = "..light + end, paramtype = "light", paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, diff --git a/tools/repairkit.lua b/tools/repairkit.lua index 8704df1..7234a39 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -108,6 +108,9 @@ local function read_state(itemstack, user, pointed_thing) if power then minetest.chat_send_player(user:get_player_name(), ndef.description..":\n"..power_data(power)) end + elseif ndef.techage_info then + local info = ndef.techage_info(pos) or "" + minetest.chat_send_player(user:get_player_name(), ndef.description..":\n"..info) end local owner = M(pos):get_string("owner") or "" if owner ~= "" then