From c2aff0c31a04449afb34208f8997373818fc9e8b Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 3 Jan 2022 23:02:57 +0100 Subject: [PATCH] [MIRROR] Autolathe takes as many sheets as it can fit [MDB IGNORE] (#10419) * Autolathe takes as many sheets as it can fit (#63274) * Autolathe takes as many sheets as it can fit * what is invoke_async anyway is this how you do it * no i guess you do it like this still use a dot though * Autolathe takes as many sheets as it can fit Co-authored-by: cacogen <25089914+cacogen@users.noreply.github.com> Co-authored-by: GoldenAlpharex --- code/datums/components/material_container.dm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/code/datums/components/material_container.dm b/code/datums/components/material_container.dm index 16bd6af8d86..999555e97db 100644 --- a/code/datums/components/material_container.dm +++ b/code/datums/components/material_container.dm @@ -129,8 +129,21 @@ to_chat(user, span_warning("[I] does not contain sufficient materials to be accepted by [parent].")) return if(!has_space(material_amount)) - to_chat(user, span_warning("[parent] is full. Please remove materials from [parent] in order to insert more.")) - return + if(istype(I, /obj/item/stack)) + //figure out how much space is left + var/space_left = max_amount - total_amount + //figure out the amount of sheets that can fit that space + var/obj/item/stack/stack_to_split = I + var/material_per_sheet = material_amount / stack_to_split.amount + var/sheets_to_insert = round(space_left / material_per_sheet) + if(!sheets_to_insert) + to_chat(user, span_warning("[parent] can't hold any more of [I] sheets.")) + return + //split the amount we don't need off + INVOKE_ASYNC(stack_to_split, /obj/item/stack.proc/split_stack, user, stack_to_split.amount - sheets_to_insert) + else + to_chat(user, span_warning("[I] contains more materials than [parent] has space to hold.")) + return user_insert(I, user, mat_container_flags) /// Proc used for when player inserts materials