diff --git a/code/game/objects/items/stacks/rods.dm b/code/game/objects/items/stacks/rods.dm
index 5ab56ea942b..790815844be 100644
--- a/code/game/objects/items/stacks/rods.dm
+++ b/code/game/objects/items/stacks/rods.dm
@@ -43,7 +43,6 @@ var/global/list/datum/stack_recipe/rod_recipes = list ( \
if(WT.remove_fuel(0,user))
var/obj/item/stack/sheet/metal/new_item = new(usr.loc)
- new_item.add_to_stacks(usr)
user.visible_message("[user.name] shaped [src] into metal with the welding tool.", \
"You shape [src] into metal with the welding tool.", \
"You hear welding.")
diff --git a/code/game/objects/items/stacks/sheets/glass.dm b/code/game/objects/items/stacks/sheets/glass.dm
index 3881915f99d..c12fa7dc3a2 100644
--- a/code/game/objects/items/stacks/sheets/glass.dm
+++ b/code/game/objects/items/stacks/sheets/glass.dm
@@ -42,7 +42,6 @@
if (V.get_amount() >= 1 && src.get_amount() >= 1)
var/obj/item/stack/sheet/rglass/RG = new (user.loc)
RG.add_fingerprint(user)
- RG.add_to_stacks(user)
var/obj/item/stack/sheet/glass/G = src
src = null
var/replace = (user.get_inactive_hand()==G)
diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm
index 3feb6b0dff3..a18fb047f3d 100644
--- a/code/game/objects/items/stacks/stack.dm
+++ b/code/game/objects/items/stacks/stack.dm
@@ -133,7 +133,6 @@
if (R.max_res_amount > 1)
var/obj/item/stack/new_item = O
new_item.amount = R.res_amount*multiplier
- new_item.add_to_stacks(usr) //try to merge with existing stacks on current tile
if(new_item.amount <= 0)//if the stack is empty, i.e it has been merged with an existing stack and has been garbage collected
return
@@ -196,21 +195,27 @@
src.amount += amount
update_icon()
-/obj/item/stack/proc/add_to_stacks(mob/usr)
- var/obj/item/stack/oldsrc = src
- src = null
- for (var/obj/item/stack/item in usr.loc)
- if (item==oldsrc)
- continue
- if (!istype(item, oldsrc.type))
- continue
- if (item.amount>=item.max_amount)
- continue
- oldsrc.attackby(item, usr)
- usr << "You add new [item.singular_name] to the stack. It now contains [item.amount] [item.singular_name]\s."
- if(oldsrc.amount <= 0)
- break
- oldsrc.update_icon()
+/obj/item/stack/proc/merge(obj/item/stack/S) //Merge src into S, as much as possible
+ var/transfer = get_amount()
+ if(S.is_cyborg)
+ transfer = min(transfer, round((S.source.max_energy - S.source.energy) / S.cost))
+ else
+ transfer = min(transfer, S.max_amount - S.amount)
+ if(pulledby)
+ pulledby.start_pulling(S)
+ S.copy_evidences(src)
+ use(transfer)
+ S.add(transfer)
+
+/obj/item/stack/Crossed(obj/o)
+ if(istype(o, src.type) && !o.throwing)
+ merge(o)
+ return ..()
+
+/obj/item/stack/hitby(atom/movable/AM, skip, hitpush)
+ if(istype(AM, src.type))
+ merge(AM)
+ return ..()
/obj/item/stack/attack_hand(mob/user)
if (user.get_inactive_hand() == src)
@@ -228,34 +233,10 @@
return
/obj/item/stack/attackby(obj/item/W, mob/user, params)
-
- if (istype(W, src.type))
- if(zero_amount()) return
+ if(istype(W, src.type))
var/obj/item/stack/S = W
- if (S.is_cyborg)
- var/to_transfer = min(src.amount, round((S.source.max_energy - S.source.energy) / S.cost))
- S.add(to_transfer)
- if (S && usr.machine==S)
- spawn(0) S.interact(usr)
- src.use(to_transfer)
- if (src && usr.machine==src)
- spawn(0) src.interact(usr)
- else
- if (S.amount >= max_amount)
- return
- var/to_transfer as num
- if (user.get_inactive_hand()==src)
- to_transfer = 1
- else
- to_transfer = min(src.amount, S.max_amount-S.amount)
- S.amount+=to_transfer
- if (S && usr.machine==S)
- spawn(0) S.interact(usr)
- src.use(to_transfer)
- if (src && usr.machine==src)
- spawn(0) src.interact(usr)
- S.update_icon()
-
+ merge(S)
+ user << "Your [S.name] stack now contains [S.get_amount()] [S.singular_name]\s."
else
..()
diff --git a/code/game/objects/items/stacks/tiles/tile_types.dm b/code/game/objects/items/stacks/tiles/tile_types.dm
index 63b826797ef..27424a95a17 100644
--- a/code/game/objects/items/stacks/tiles/tile_types.dm
+++ b/code/game/objects/items/stacks/tiles/tile_types.dm
@@ -40,7 +40,6 @@
if (mineralType == "metal")
var/obj/item/stack/sheet/metal/new_item = new(user.loc)
- new_item.add_to_stacks(user)
user.visible_message("[user.name] shaped [src] into metal with the weldingtool.", \
"You shaped [src] into metal with the weldingtool.", \
"You hear welding.")
@@ -54,7 +53,6 @@
else
var/sheet_type = text2path("/obj/item/stack/sheet/mineral/[mineralType]")
var/obj/item/stack/sheet/mineral/new_item = new sheet_type(user.loc)
- new_item.add_to_stacks(user)
user.visible_message("[user.name] shaped [src] into a sheet with the weldingtool.", \
"You shaped [src] into a sheet with the weldingtool.", \
"You hear welding.")