mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-29 16:18:01 +01:00
[MIRROR] Adds a food trash element (#574)
* Adds a food trash element (#53225) adds a food trash element, for dumping trash when u eat food unused now, needed for food refactor. spawns trash in your hands (or on the floor) when the food this is attached to is eaten. * Adds a food trash element Co-authored-by: Qustinnus <Floydje123@hotmail.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// If an item has the food_trash element it will drop an item when it is consumed.
|
||||
/datum/element/food_trash
|
||||
element_flags = ELEMENT_BESPOKE
|
||||
id_arg_index = 2
|
||||
/// The type of trash that is spawned by this element
|
||||
var/trash
|
||||
|
||||
/datum/element/food_trash/Attach(datum/target, atom/trash)
|
||||
. = ..()
|
||||
if(!isatom(target))
|
||||
return ELEMENT_INCOMPATIBLE
|
||||
src.trash = trash
|
||||
RegisterSignal(target, COMSIG_FOOD_CONSUMED, .proc/generate_trash)
|
||||
|
||||
/datum/element/food_trash/Detach(datum/target)
|
||||
. = ..()
|
||||
UnregisterSignal(target, COMSIG_FOOD_CONSUMED)
|
||||
|
||||
/datum/element/food_trash/proc/generate_trash(datum/source, mob/living/eater, mob/living/feeder)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
///cringy signal_handler shouldnt be needed if you dont want to return but oh well
|
||||
INVOKE_ASYNC(src, .proc/async_generate_trash, source)
|
||||
|
||||
/datum/element/food_trash/proc/async_generate_trash(datum/source)
|
||||
var/datum/component/edible/edible_component = source
|
||||
|
||||
var/obj/item/trash_item = new trash()
|
||||
|
||||
var/atom/edible_object = edible_component.parent
|
||||
|
||||
var/mob/living/mob_location = edible_object.loc //The foods location
|
||||
|
||||
if(istype(mob_location))
|
||||
mob_location.put_in_hands(trash_item)
|
||||
else
|
||||
trash_item.forceMove(get_turf(edible_component.parent))
|
||||
Reference in New Issue
Block a user