diff --git a/code/datums/material_container.dm b/code/datums/material_container.dm
index 6870c3d303b..cf8d3100b05 100644
--- a/code/datums/material_container.dm
+++ b/code/datums/material_container.dm
@@ -60,9 +60,14 @@
return 0
/datum/material_container/proc/insert_stack(obj/item/stack/S, amt = 0)
- if(!amt)
+ if(amt <= 0)
+ return 0
+ if(amt > S.amount)
amt = S.amount
var/material_amt = get_item_material_amount(S)
+ if(!material_amt)
+ return 0
+
amt = min(amt, round(((max_amount - total_amount) / material_amt)))
if(!amt)
return 0
diff --git a/code/modules/research/protolathe.dm b/code/modules/research/protolathe.dm
index 3d0c23ddb44..d4348ffb505 100644
--- a/code/modules/research/protolathe.dm
+++ b/code/modules/research/protolathe.dm
@@ -123,10 +123,12 @@ Note: Must be placed west/left of and R&D console to function.
return
if (stat)
return 1
- if(istype(O,/obj/item/stack/sheet))
- if(!materials.has_space( materials.get_item_material_amount(O) ))
- user << "The [src.name]'s material bin is full. Please remove material before adding more."
- return 1
+ if(!istype(O,/obj/item/stack/sheet))
+ return 1
+
+ if(!materials.has_space( materials.get_item_material_amount(O) ))
+ user << "The [src.name]'s material bin is full! Please remove material before adding more."
+ return 1
var/obj/item/stack/sheet/stack = O
var/amount = round(input("How many sheets do you want to add?") as num)//No decimals
@@ -134,14 +136,14 @@ Note: Must be placed west/left of and R&D console to function.
return
var/amount_inserted = materials.insert_stack(O,amount)
if(!amount_inserted)
- user << "You could not insert [O], it has no usable materials."
return 1
else
busy = 1
use_power(max(1000, (MINERAL_MATERIAL_AMOUNT*amount_inserted/10)))
user << "You add [amount_inserted] sheets to the [src.name]."
- overlays += "protolathe_[stack.name]"
+ var/stackname = stack.name
+ src.overlays += "protolathe_[stackname]"
sleep(10)
- overlays -= "protolathe_[stack.name]"
+ src.overlays -= "protolathe_[stackname]"
busy = 0
updateUsrDialog()
\ No newline at end of file