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