diff --git a/code/datums/components/material/material_container.dm b/code/datums/components/material/material_container.dm index 7f07c6cb91d..6b23fcce6f1 100644 --- a/code/datums/components/material/material_container.dm +++ b/code/datums/components/material/material_container.dm @@ -596,16 +596,26 @@ //eject sheets based on available amount after each iteration var/count = 0 while(sheet_amt > 0) - //create sheets in null space so it doesn't merge & delete itself - var/obj/item/stack/sheet/new_sheets = new material.sheet_type(null, min(sheet_amt, MAX_STACK_SIZE), FALSE, list((material) = SHEET_MATERIAL_AMOUNT)) + //don't merge yet. we need to do stuff with it first + var/obj/item/stack/sheet/new_sheets = new material.sheet_type(target, min(sheet_amt, MAX_STACK_SIZE), FALSE) count += new_sheets.amount //use material & deduct work needed use_amount_mat(new_sheets.amount * SHEET_MATERIAL_AMOUNT, material) sheet_amt -= new_sheets.amount //send signal SEND_SIGNAL(src, COMSIG_MATCONTAINER_SHEETS_RETRIEVED, new_sheets, context) - //now move to target so it gets merged - new_sheets.forceMove(target) + //no point merging anything into an already full stack + if(new_sheets.amount == new_sheets.max_amount) + continue + //now we can merge since we are done with it + for(var/obj/item/stack/item_stack in target) + if(item_stack == new_sheets || item_stack.type != material.sheet_type) //don't merge with self or different type + continue + //speed merge + var/merge_amount = min(item_stack.amount, new_sheets.max_amount - new_sheets.get_amount()) + item_stack.use(merge_amount) + new_sheets.add(merge_amount) + break return count /** diff --git a/code/game/machinery/recycler.dm b/code/game/machinery/recycler.dm index ddf55388d0b..cc6ead40627 100644 --- a/code/game/machinery/recycler.dm +++ b/code/game/machinery/recycler.dm @@ -116,11 +116,6 @@ /obj/machinery/recycler/proc/on_entered(datum/source, atom/movable/enterer, old_loc) SIGNAL_HANDLER - // This is explicitly so we avoid processing items that are entering from nullspace, - // to avoid infinite loops. - if(!old_loc) - return - INVOKE_ASYNC(src, PROC_REF(eat), enterer) /obj/machinery/recycler/proc/eat(atom/movable/morsel, sound=TRUE)