From 96c9fe164a91129e192c6ad9011223395c813f50 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Sun, 24 Mar 2024 15:54:24 +0100 Subject: [PATCH] Mesecons compatibility: Nuclear Reactor and Nuclear Reactor Chamber --- compat/mesecons.lua | 118 ++++++++++++++++++++++++++++------- machines/nuclear_reactor.lua | 3 +- 2 files changed, 99 insertions(+), 22 deletions(-) diff --git a/compat/mesecons.lua b/compat/mesecons.lua index 32db1fa..b8a6d96 100644 --- a/compat/mesecons.lua +++ b/compat/mesecons.lua @@ -16,31 +16,107 @@ -- Rotary Macerator local override={ - mesecons={ - effector={ - action_on=function(pos,node) - if node.name~="industrialtest:rotary_macerator" then - return - end - - local meta=minetest.get_meta(pos) - meta:set_int("maintainSpeed",1) + mesecons={ + effector={ + action_on=function(pos,node) + if node.name~="industrialtest:rotary_macerator" then + return + end - local def=minetest.registered_nodes[node.name] - def._industrialtest_updateFormspec(pos) + local meta=minetest.get_meta(pos) + meta:set_int("maintainSpeed",1) - minetest.get_node_timer(pos):start(industrialtest.updateDelay) - end, - action_off=function(pos,node) - local meta=minetest.get_meta(pos) - meta:set_int("maintainSpeed",0) + local def=minetest.registered_nodes[node.name] + def._industrialtest_updateFormspec(pos) - local def=minetest.registered_nodes[node.name] - def._industrialtest_updateFormspec(pos) - end - } - } + minetest.get_node_timer(pos):start(industrialtest.updateDelay) + end, + action_off=function(pos,node) + local meta=minetest.get_meta(pos) + meta:set_int("maintainSpeed",0) + + local def=minetest.registered_nodes[node.name] + def._industrialtest_updateFormspec(pos) + end + } + } } 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) diff --git a/machines/nuclear_reactor.lua b/machines/nuclear_reactor.lua index c572d36..3bebb87 100644 --- a/machines/nuclear_reactor.lua +++ b/machines/nuclear_reactor.lua @@ -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={