Mesecons compatibility: Nuclear Reactor and Nuclear Reactor Chamber

This commit is contained in:
mrkubax10 2024-03-24 15:54:24 +01:00
parent 28040db868
commit 96c9fe164a
2 changed files with 99 additions and 22 deletions

View File

@ -44,3 +44,79 @@ local override={
minetest.override_item("industrialtest:rotary_macerator",override)
minetest.override_item("industrialtest:rotary_macerator_active",override)
-- Nuclear Reactor
override={
mesecons={
effector={
action_on=function(pos,node)
local isChamber=node.name=="industrialtest:nuclear_reactor_chamber"
if node.name~="industrialtest:nuclear_reactor" and not isChamber then
return
end
local originalPos
local meta=minetest.get_meta(pos)
meta:set_int("meseconPowered",1)
if isChamber then
originalPos=pos
pos=minetest.deserialize(meta:get_string("reactor"))
node=minetest.get_node(pos)
meta=minetest.get_meta(pos)
end
meta:set_int("enabled",1)
meta:set_int("stateChanged",1)
local def=minetest.registered_nodes[node.name]
def._industrialtest_updateFormspec(pos)
if isChamber then
def._industrialtest_synchronizeToChamber(originalPos)
end
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end,
action_off=function(pos,node)
local isChamber=node.name=="industrialtest:nuclear_reactor_chamber"
local originalPos
local meta=minetest.get_meta(pos)
meta:set_int("meseconPowered",0)
if isChamber then
originalPos=pos
pos=minetest.deserialize(meta:get_string("reactor"))
node=minetest.get_node(pos)
meta=minetest.get_meta(pos)
end
if meta:get_int("meseconPowered")==1 then
return
end
local chambers=minetest.deserialize(meta:get_string("chambers"))
for _,chamber in ipairs(chambers) do
local chamberMeta=minetest.get_meta(chamber)
if chamberMeta:get_int("meseconPowered")==1 then
return
end
end
meta:set_int("enabled",0)
meta:set_int("stateChanged",1)
local def=minetest.registered_nodes[node.name]
def._industrialtest_updateFormspec(pos)
if isChamber then
def._industrialtest_synchronizeToChamber(originalPos)
end
end
}
}
}
minetest.override_item("industrialtest:nuclear_reactor",override)
minetest.override_item("industrialtest:nuclear_reactor_active",override)
-- Nuclear Reactor Chamber
minetest.override_item("industrialtest:nuclear_reactor_chamber",override)

View File

@ -454,7 +454,8 @@ industrialtest.internal.registerMachine({
},
paramtype2="facedir",
legacy_facedir_simple=true,
on_receive_fields=reactor.handleFormspecFields
on_receive_fields=reactor.handleFormspecFields,
_industrialtest_synchronizeToChamber=reactor.synchronizeToChamber
},
activeCustomKeys={
tiles={