diff --git a/basic_machines/source.lua b/basic_machines/source.lua index 48164b2..5056980 100644 --- a/basic_machines/source.lua +++ b/basic_machines/source.lua @@ -35,7 +35,7 @@ local function formspec(self, pos, nvm) default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. + power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided).. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" end diff --git a/coal_power_station/generator.lua b/coal_power_station/generator.lua index 5a44f2d..e8c6e8c 100644 --- a/coal_power_station/generator.lua +++ b/coal_power_station/generator.lua @@ -32,7 +32,7 @@ local function formspec(self, pos, nvm) default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. + power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided).. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" end diff --git a/digtron/battery.lua b/digtron/battery.lua index 239d983..021b955 100644 --- a/digtron/battery.lua +++ b/digtron/battery.lua @@ -49,7 +49,7 @@ local function formspec(self, pos, nvm) default.gui_slots.. "box[0,-0.1;4.8,0.5;#c6e8ff]".. "label[1,-0.1;"..minetest.colorize("#000000", S("Digtron Battery")).."]".. - power.formspec_label_bar(0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents")).. + power.formspec_label_bar(pos, 0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents")).. "image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.6,2;1,1;"..self:get_state_tooltip(nvm).."]".. "image[3.75,2;1,1;"..techage.get_power_image(pos, nvm).."]" diff --git a/energy_storage/generator.lua b/energy_storage/generator.lua index 78f172b..cd36b3a 100644 --- a/energy_storage/generator.lua +++ b/energy_storage/generator.lua @@ -32,7 +32,7 @@ local function formspec(self, pos, nvm) default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - power.formspec_label_bar(0, 0.8, S("Electricity"), PWR_CAPA, nvm.provided).. + power.formspec_label_bar(pos, 0, 0.8, S("Electricity"), PWR_CAPA, nvm.provided).. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" end diff --git a/energy_storage/heatexchanger2.lua b/energy_storage/heatexchanger2.lua index 6069e14..55fcf86 100644 --- a/energy_storage/heatexchanger2.lua +++ b/energy_storage/heatexchanger2.lua @@ -44,8 +44,8 @@ local function formspec(self, pos, nvm) default.gui_slots.. "box[0,-0.1;5.8,0.5;#c6e8ff]".. "label[2,-0.1;"..minetest.colorize( "#000000", S("Heat Exchanger")).."]".. - power.formspec_label_bar(0, 0.8, S("Electricity"), needed_max, needed).. - power.formspec_label_bar(3.5, 0.8, S("Thermal"), capa_max, capa, "").. + power.formspec_label_bar(pos, 0, 0.8, S("Electricity"), needed_max, needed).. + power.formspec_label_bar(pos, 3.5, 0.8, S("Thermal"), capa_max, capa, "").. arrow.. "image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]" diff --git a/furnace/cooking.lua b/furnace/cooking.lua index 2f188aa..4583407 100644 --- a/furnace/cooking.lua +++ b/furnace/cooking.lua @@ -111,7 +111,7 @@ local function process(inv, recipe, output) if recipe.waste then local leftover = inv:add_item("dst", ItemStack(recipe.waste)) if leftover:get_count() > 0 then - inv:set_list("src", leftover) + inv:add_item("src", leftover) return techage.BLOCKED end end diff --git a/hydrogen/electrolyzer.lua b/hydrogen/electrolyzer.lua index 2efcf25..13890c5 100644 --- a/hydrogen/electrolyzer.lua +++ b/hydrogen/electrolyzer.lua @@ -44,7 +44,7 @@ local function formspec(self, pos, nvm) default.gui_slots.. "box[0,-0.1;5.8,0.5;#c6e8ff]".. "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Electrolyzer")).."]".. - techage.power.formspec_label_bar(0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken).. + techage.power.formspec_label_bar(pos, 0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken).. arrow.. "image_button[3,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[3,2.5;1,1;"..self:get_state_tooltip(nvm).."]".. diff --git a/hydrogen/fuelcell.lua b/hydrogen/fuelcell.lua index 2c7e32a..1c1e040 100644 --- a/hydrogen/fuelcell.lua +++ b/hydrogen/fuelcell.lua @@ -48,7 +48,7 @@ local function formspec(self, pos, nvm) arrow.. "image_button[2,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2,2.5;1,1;"..self:get_state_tooltip(nvm).."]".. - techage.power.formspec_label_bar(3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.given) + techage.power.formspec_label_bar(pos, 3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.given) end local function start_node(pos, nvm, state) diff --git a/power/formspecs.lua b/power/formspecs.lua index c82f500..d8c0e2e 100644 --- a/power/formspecs.lua +++ b/power/formspecs.lua @@ -48,11 +48,24 @@ function techage.power.formspec_power_bar(max_power, current_power) return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png" end -function techage.power.formspec_label_bar(x, y, label, max_power, current_power, unit) +function techage.power.formspec_label_bar(pos, x, y, label, max_power, current_power, unit) local percent, ypos - current_power = current_power or 0 + max_power = max_power or 1 unit = unit or "ku" + + if current_power == 0 then + -- check if power network is overloaded + if techage.power.network_overloaded(pos, techage.ElectricCable) then + return "container["..x..","..y.."]".. + "box[0,0;2.3,3.3;#395c74]".. + "label[0.2,0;"..label.."]".. + "label[0.7,0.4;"..max_power.." "..unit.."]".. + "image[0,0.5;1,3;techage_form_level_red_fg.png]".. + "container_end[]" + end + end + current_power = current_power or 0 if current_power == 0 then percent = 0 ypos = 2.8 diff --git a/power/node_api.lua b/power/node_api.lua index 07d6a7a..1c4cc39 100644 --- a/power/node_api.lua +++ b/power/node_api.lua @@ -148,6 +148,17 @@ function techage.power.power_available(pos, Cable) return netw and netw.on and netw.alive and netw.alive > 0 end +function techage.power.network_overloaded(pos, Cable) + local nvm = techage.get_nvm(pos) + local tlib_type = Cable.tube_type + local netID = nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"] + local netw = networks.has_network(tlib_type, netID) + if netw then + local sum = (netw.available1 or 0) + (netw.available2 or 0) + return sum > 0 and sum < (netw.needed1 or 0) + end +end + -- this is more a try to start, the start will be performed by on_power() function techage.power.consumer_start(pos, Cable, cycle_time) local nvm = techage.get_nvm(pos) diff --git a/power/power_terminal.lua b/power/power_terminal.lua index ccf1988..a20852c 100644 --- a/power/power_terminal.lua +++ b/power/power_terminal.lua @@ -129,10 +129,10 @@ local function formspec(pos, nvm) "box[0,-0.1;9.8,0.5;#c6e8ff]".. "label[4,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]".. "label[9.5,-0.1;"..minetest.colorize( "#000000", star).."]".. - power.formspec_label_bar(0, 0.7, S("Genera. 1"), gen1.pow_act, gen1.pow_used).. - power.formspec_label_bar(2.5, 0.7, S("Genera. 2"), gen2.pow_act, gen2.pow_used).. - power.formspec_label_bar(5, 0.7, S("Consum. 2"), con2.pow_act, con2.pow_used).. - power.formspec_label_bar(7.5, 0.7, S("Consum. 1"), con1.pow_act, con1.pow_used).. + power.formspec_label_bar(pos, 0, 0.7, S("Genera. 1"), gen1.pow_act, gen1.pow_used).. + power.formspec_label_bar(pos, 2.5, 0.7, S("Genera. 2"), gen2.pow_act, gen2.pow_used).. + power.formspec_label_bar(pos, 5, 0.7, S("Consum. 2"), con2.pow_act, con2.pow_used).. + power.formspec_label_bar(pos, 7.5, 0.7, S("Consum. 1"), con1.pow_act, con1.pow_used).. "box[0,4.3;9.8,0.4;#c6e8ff]".. "box[0,4.85;9.8,0.4;#395c74]".. "box[0,5.35;9.8,0.4;#395c74]".. diff --git a/solar/inverter.lua b/solar/inverter.lua index b5ea96c..9b877f8 100644 --- a/solar/inverter.lua +++ b/solar/inverter.lua @@ -67,8 +67,8 @@ local function formspec(self, pos, nvm) default.gui_slots.. "box[0,-0.1;5.8,0.5;#c6e8ff]".. "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Inverter")).."]".. - power.formspec_label_bar(0, 0.8, S("Power DC"), PWR_PERF, max_power).. - power.formspec_label_bar(3.5, 0.8, S("Power AC"), max_power, delivered).. + power.formspec_label_bar(pos, 0, 0.8, S("Power DC"), PWR_PERF, max_power).. + power.formspec_label_bar(pos, 3.5, 0.8, S("Power AC"), max_power, delivered).. arrow.. "image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]" diff --git a/steam_engine/flywheel.lua b/steam_engine/flywheel.lua index 6d5bf1c..189a3bd 100644 --- a/steam_engine/flywheel.lua +++ b/steam_engine/flywheel.lua @@ -38,7 +38,7 @@ local function formspec(self, pos, nvm) default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. + power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided).. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" end diff --git a/ta3_power/akkubox.lua b/ta3_power/akkubox.lua index 17421a0..f5efc7a 100644 --- a/ta3_power/akkubox.lua +++ b/ta3_power/akkubox.lua @@ -36,7 +36,7 @@ local function formspec(self, pos, nvm) default.gui_slots.. "box[0,-0.1;4.8,0.5;#c6e8ff]".. "label[1,-0.1;"..minetest.colorize( "#000000", S("TA3 Akku Box")).."]".. - power.formspec_label_bar(0, 0.8, S("Load"), PWR_CAPA, capa).. + power.formspec_label_bar(pos, 0, 0.8, S("Load"), PWR_CAPA, capa).. "image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[3,2;1,1;"..self:get_state_tooltip(nvm).."]".. "label[3.7,1.2;"..S("Electricity").."]".. diff --git a/ta3_power/tiny_generator.lua b/ta3_power/tiny_generator.lua index ffd3ff0..3d27862 100644 --- a/ta3_power/tiny_generator.lua +++ b/ta3_power/tiny_generator.lua @@ -39,7 +39,7 @@ local function formspec(self, pos, nvm) "image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]".. "image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]".. - power.formspec_label_bar(2.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided) + power.formspec_label_bar(pos, 2.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided) end local function play_sound(pos)