forked from mrkubax10/industrialtest
Machines now explode when there is too much power transferred
This commit is contained in:
38
api.lua
38
api.lua
@@ -244,26 +244,30 @@ industrialtest.api.powerFlow=function(pos)
|
||||
local roomAvailable=false
|
||||
for _,endpoint in ipairs(network) do
|
||||
local endpointMeta=minetest.get_meta(endpoint.position)
|
||||
-- TODO: if supplying machine power flow is too large for receiving machine to handle then that machine should explode
|
||||
local transferredToEndpoint=false
|
||||
if industrialtest.api.transferPower(meta,endpointMeta,math.min(powerDistribution,endpoint.flow))>0 then
|
||||
transferred=true
|
||||
transferredToEndpoint=true
|
||||
end
|
||||
local def=minetest.registered_nodes[minetest.get_node(endpoint.position).name]
|
||||
if def then
|
||||
local updateFormspec=def._industrialtest_updateFormspec
|
||||
if updateFormspec then
|
||||
updateFormspec(endpoint.position)
|
||||
if powerDistribution<=endpoint.flow then
|
||||
if industrialtest.api.transferPower(meta,endpointMeta,powerDistribution)>0 then
|
||||
transferred=true
|
||||
transferredToEndpoint=true
|
||||
end
|
||||
local onPowerFlow=def._industrialtest_onPowerFlow
|
||||
if onPowerFlow and transferredToEndpoint then
|
||||
onPowerFlow(endpoint.position,industrialtest.api.getOppositeSide(1))
|
||||
local def=minetest.registered_nodes[minetest.get_node(endpoint.position).name]
|
||||
if def then
|
||||
local updateFormspec=def._industrialtest_updateFormspec
|
||||
if updateFormspec then
|
||||
updateFormspec(endpoint.position)
|
||||
end
|
||||
local onPowerFlow=def._industrialtest_onPowerFlow
|
||||
if onPowerFlow and transferredToEndpoint then
|
||||
onPowerFlow(endpoint.position,industrialtest.api.getOppositeSide(1))
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.get_node_timer(endpoint.position):start(industrialtest.updateDelay)
|
||||
if not industrialtest.api.isFullyCharged(endpointMeta) then
|
||||
roomAvailable=true
|
||||
minetest.get_node_timer(endpoint.position):start(industrialtest.updateDelay)
|
||||
if not industrialtest.api.isFullyCharged(endpointMeta) then
|
||||
roomAvailable=true
|
||||
end
|
||||
else
|
||||
minetest.remove_node(endpoint.position)
|
||||
industrialtest.internal.explode(endpoint.position,2)
|
||||
end
|
||||
end
|
||||
return roomAvailable,transferred
|
||||
|
||||
Reference in New Issue
Block a user