Machines now explode when there is too much power transferred

This commit is contained in:
mrkubax10 2023-11-19 14:53:43 +01:00
parent 84efcf7f7f
commit 286f95596f
3 changed files with 27 additions and 17 deletions

38
api.lua
View File

@ -244,26 +244,30 @@ industrialtest.api.powerFlow=function(pos)
local roomAvailable=false local roomAvailable=false
for _,endpoint in ipairs(network) do for _,endpoint in ipairs(network) do
local endpointMeta=minetest.get_meta(endpoint.position) 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 local transferredToEndpoint=false
if industrialtest.api.transferPower(meta,endpointMeta,math.min(powerDistribution,endpoint.flow))>0 then if powerDistribution<=endpoint.flow then
transferred=true if industrialtest.api.transferPower(meta,endpointMeta,powerDistribution)>0 then
transferredToEndpoint=true transferred=true
end transferredToEndpoint=true
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 end
local onPowerFlow=def._industrialtest_onPowerFlow local def=minetest.registered_nodes[minetest.get_node(endpoint.position).name]
if onPowerFlow and transferredToEndpoint then if def then
onPowerFlow(endpoint.position,industrialtest.api.getOppositeSide(1)) 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
end minetest.get_node_timer(endpoint.position):start(industrialtest.updateDelay)
minetest.get_node_timer(endpoint.position):start(industrialtest.updateDelay) if not industrialtest.api.isFullyCharged(endpointMeta) then
if not industrialtest.api.isFullyCharged(endpointMeta) then roomAvailable=true
roomAvailable=true end
else
minetest.remove_node(endpoint.position)
industrialtest.internal.explode(endpoint.position,2)
end end
end end
return roomAvailable,transferred return roomAvailable,transferred

View File

@ -70,6 +70,7 @@ if industrialtest.mclAvailable then
end end
return itemstack return itemstack
end end
industrialtest.internal.explode=mcl_explosions.explode
end end
-- compatibilty that adds not existing elements -- compatibilty that adds not existing elements
@ -647,6 +648,10 @@ if industrialtest.mclAvailable then
y_min=mcl_vars.mg_overworld_min y_min=mcl_vars.mg_overworld_min
}) })
elseif industrialtest.mtgAvailable then elseif industrialtest.mtgAvailable then
industrialtest.internal.explode=function(pos,radius)
tnt.boom(pos,{radius=radius})
end
industrialtest.registerMetal=function(name,displayName,hardness) industrialtest.registerMetal=function(name,displayName,hardness)
minetest.register_craftitem("industrialtest:"..name.."_lump",{ minetest.register_craftitem("industrialtest:"..name.."_lump",{
description=S(displayName.." Lump"), description=S(displayName.." Lump"),

View File

@ -243,6 +243,7 @@ reactor.activeOnTimer=function(pos,elapsed,meta,inv)
if heat>200 then if heat>200 then
-- TODO: Explode -- TODO: Explode
minetest.remove_node(pos) minetest.remove_node(pos)
industrialtest.internal.explode(pos,#maxCluster*4)
return false,false return false,false
end end
meta:set_int("heat",heat) meta:set_int("heat",heat)