diff --git a/code/datums/components/plumbing/IV_drip.dm b/code/datums/components/plumbing/IV_drip.dm index 26b6bd4e403..2f35b3edd02 100644 --- a/code/datums/components/plumbing/IV_drip.dm +++ b/code/datums/components/plumbing/IV_drip.dm @@ -8,7 +8,7 @@ /datum/component/plumbing/iv_drip/Initialize(start=TRUE, _ducting_layer, _turn_connects=TRUE, datum/reagents/custom_receiver) . = ..() - recipient_reagents_holder = null + set_recipient_reagents_holder(null) /datum/component/plumbing/iv_drip/RegisterWithParent() . = ..() @@ -25,10 +25,10 @@ SIGNAL_HANDLER if(attachee?.reagents) - recipient_reagents_holder = attachee.reagents + set_recipient_reagents_holder(attachee.reagents) ///IV has been detached, so clear the holder /datum/component/plumbing/iv_drip/proc/clear_attached(datum/source) SIGNAL_HANDLER - recipient_reagents_holder = null + set_recipient_reagents_holder(null) diff --git a/code/datums/components/plumbing/_plumbing.dm b/code/datums/components/plumbing/_plumbing.dm index c30f0edf2ff..d93d7beefe2 100644 --- a/code/datums/components/plumbing/_plumbing.dm +++ b/code/datums/components/plumbing/_plumbing.dm @@ -42,25 +42,28 @@ reagents = AM.reagents turn_connects = _turn_connects - if(custom_receiver) - recipient_reagents_holder = custom_receiver - else - recipient_reagents_holder = AM.reagents + set_recipient_reagents_holder(custom_receiver ? custom_receiver : AM.reagents) + if(start) + //We're registering here because I need to check whether we start active or not, and this is just easier + //Should be called after we finished. Done this way because other networks need to finish setting up aswell + RegisterSignal(parent, list(COMSIG_COMPONENT_ADDED), .proc/enable) + +/datum/component/plumbing/RegisterWithParent() RegisterSignal(parent, list(COMSIG_MOVABLE_MOVED,COMSIG_PARENT_PREQDELETED), .proc/disable) RegisterSignal(parent, list(COMSIG_OBJ_DEFAULT_UNFASTEN_WRENCH), .proc/toggle_active) RegisterSignal(parent, list(COMSIG_OBJ_HIDE), .proc/hide) RegisterSignal(parent, list(COMSIG_ATOM_UPDATE_OVERLAYS), .proc/create_overlays) //called by lateinit on startup RegisterSignal(parent, list(COMSIG_MOVABLE_CHANGE_DUCT_LAYER), .proc/change_ducting_layer) - if(start) - //timer 0 so it can finish returning initialize, after which we're added to the parent. - //Only then can we tell the duct next to us they can connect, because only then is the component really added. this was a fun one - addtimer(CALLBACK(src, .proc/enable), 0) +/datum/component/plumbing/UnregisterFromParent() + UnregisterSignal(parent, list(COMSIG_MOVABLE_MOVED,COMSIG_PARENT_PREQDELETED, COMSIG_OBJ_DEFAULT_UNFASTEN_WRENCH,COMSIG_OBJ_HIDE, \ + COMSIG_ATOM_UPDATE_OVERLAYS, COMSIG_MOVABLE_CHANGE_DUCT_LAYER, COMSIG_COMPONENT_ADDED)) /datum/component/plumbing/Destroy() ducts = null reagents = null + set_recipient_reagents_holder(null) //null is there so it's obvious we're setting this to nothing return ..() /datum/component/plumbing/process() @@ -207,8 +210,9 @@ duct.update_appearance() ///settle wherever we are, and start behaving like a piece of plumbing -/datum/component/plumbing/proc/enable() - if(active) +/datum/component/plumbing/proc/enable(obj/object, datum/component/component) + if(active || (component && component != src)) + UnregisterSignal(parent, list(COMSIG_COMPONENT_ADDED)) return update_dir() @@ -308,6 +312,15 @@ disable() enable() +/datum/component/plumbing/proc/set_recipient_reagents_holder(datum/reagents/receiver) + if(recipient_reagents_holder) + UnregisterSignal(recipient_reagents_holder, list(COMSIG_PARENT_QDELETING)) //stop tracking whoever we were tracking + if(receiver) + RegisterSignal(receiver, list(COMSIG_PARENT_QDELETING), .proc/set_recipient_reagents_holder) //so on deletion it calls this proc again, but with no value to set + + recipient_reagents_holder = receiver + + ///has one pipe input that only takes, example is manual output pipe /datum/component/plumbing/simple_demand demand_connects = SOUTH diff --git a/code/modules/plumbing/plumbers/pill_press.dm b/code/modules/plumbing/plumbers/pill_press.dm index 61a0c741401..d0b9abf1036 100644 --- a/code/modules/plumbing/plumbers/pill_press.dm +++ b/code/modules/plumbing/plumbers/pill_press.dm @@ -35,6 +35,7 @@ /obj/machinery/plumbing/pill_press/Initialize(mapload, bolt, layer) . = ..() + AddComponent(/datum/component/plumbing/simple_demand, bolt, layer) //expertly copypasted from chemmasters