mirror of
https://github.com/minetest-mods/technic.git
synced 2024-09-27 06:50:18 +02:00
Supply converter demands only needed power
Supply converter demands only the needed power to satisfy the demand on the output network. It can still be too much if the output network has other power sources, because supply is not taken in account.
This commit is contained in:
parent
11e43ffe13
commit
7f8454814c
|
@ -133,7 +133,6 @@ local run = function(pos, node, run_stage)
|
||||||
enabled = enabled == "1"
|
enabled = enabled == "1"
|
||||||
end
|
end
|
||||||
enabled = enabled and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
|
enabled = enabled and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
|
||||||
local demand = enabled and meta:get_int("power") or 0
|
|
||||||
|
|
||||||
local pos_up = {x=pos.x, y=pos.y+1, z=pos.z}
|
local pos_up = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||||
local pos_down = {x=pos.x, y=pos.y-1, z=pos.z}
|
local pos_down = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||||
|
@ -144,6 +143,18 @@ local run = function(pos, node, run_stage)
|
||||||
local to = technic.get_cable_tier(name_down)
|
local to = technic.get_cable_tier(name_down)
|
||||||
|
|
||||||
if from and to then
|
if from and to then
|
||||||
|
local network_hash = technic.cables[minetest.hash_node_position(pos_down)]
|
||||||
|
local network = network_hash and minetest.get_position_from_hash(network_hash)
|
||||||
|
local sw_pos = network and {x=network.x,y=network.y+1,z=network.z}
|
||||||
|
local timeout = 0
|
||||||
|
for tier in pairs(technic.machines) do
|
||||||
|
timeout = math.max(meta:get_int(tier.."_EU_timeout"),timeout)
|
||||||
|
end
|
||||||
|
if timeout > 0 and sw_pos and minetest.get_node(sw_pos).name == "technic:switching_station" then
|
||||||
|
local sw_meta = minetest.get_meta(sw_pos)
|
||||||
|
local demand = enabled and math.min(meta:get_int("power"),
|
||||||
|
100 * math.ceil(sw_meta:get_int("demand") / remain / 100)) or 0
|
||||||
|
|
||||||
local input = meta:get_int(from.."_EU_input")
|
local input = meta:get_int(from.."_EU_input")
|
||||||
meta:set_int(from.."_EU_demand", demand)
|
meta:set_int(from.."_EU_demand", demand)
|
||||||
meta:set_int(from.."_EU_supply", 0)
|
meta:set_int(from.."_EU_supply", 0)
|
||||||
|
@ -152,6 +163,9 @@ local run = function(pos, node, run_stage)
|
||||||
meta:set_string("infotext", S("@1 (@2 @3 -> @4 @5)", machine_name,
|
meta:set_string("infotext", S("@1 (@2 @3 -> @4 @5)", machine_name,
|
||||||
technic.EU_string(input), from,
|
technic.EU_string(input), from,
|
||||||
technic.EU_string(input * remain), to))
|
technic.EU_string(input * remain), to))
|
||||||
|
else
|
||||||
|
meta:set_string("infotext",S("%s Has No Network"):format(machine_name))
|
||||||
|
end
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", S("%s Has Bad Cabling"):format(machine_name))
|
meta:set_string("infotext", S("%s Has Bad Cabling"):format(machine_name))
|
||||||
if to then
|
if to then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user