Files
Bubberstation/code/datums/elements/openspace_item_click_handler.dm
MrMelbert aaaf761adc Openspace Item Handler doesn't think stuff in bags are valid (#83973)
## About The Pull Request

Fixes #83972 

Clicking on stuff in your bag with stuff that has
`openspace_item_click_handler` makes it think you're on a different z
level (which is technically true) so it overrides the click and does its
own thing.

So we check that z is not 0. Also move the return to be safe. 


## Changelog

🆑 Melbert
fix: Fix inability to make r-glass by hand inside your backpack
/🆑

---------

Co-authored-by: san7890 <the@san7890.com>
2024-06-14 21:14:02 -06:00

30 lines
1.2 KiB
Plaintext

/**
* allow players to easily use items such as iron rods, rcds on open space without
* having to pixelhunt for portions not occupied by object or mob visuals.
*/
/datum/element/openspace_item_click_handler
/datum/element/openspace_item_click_handler/Attach(datum/target)
. = ..()
if(!isitem(target))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_ITEM_INTERACTING_WITH_ATOM, PROC_REF(divert_interaction))
/datum/element/openspace_item_click_handler/Detach(datum/source)
UnregisterSignal(source, COMSIG_ITEM_INTERACTING_WITH_ATOM)
return ..()
//Invokes the proctype with a turf above as target.
/datum/element/openspace_item_click_handler/proc/divert_interaction(obj/item/source, mob/user, atom/target, click_parameters)
SIGNAL_HANDLER
if((target.z == 0) || (user.z == 0) || target.z == user.z)
return NONE
var/turf/checked_turf = get_turf(target)
while(!isnull(checked_turf))
checked_turf = GET_TURF_ABOVE(checked_turf)
if(checked_turf?.z == user.z && user.CanReach(checked_turf, source))
INVOKE_ASYNC(source, TYPE_PROC_REF(/obj/item, handle_openspace_click), checked_turf, user, click_parameters)
return ITEM_INTERACT_BLOCKING
return NONE