diff --git a/code/__DEFINES/materials.dm b/code/__DEFINES/materials.dm
index 3c4a78ea7a5..601df51d77f 100644
--- a/code/__DEFINES/materials.dm
+++ b/code/__DEFINES/materials.dm
@@ -4,10 +4,6 @@
/// Hard materials, such as iron or metal
#define MAT_CATEGORY_RIGID "rigid material"
-
-/// Gets the reference for the material type that was given
-#define getmaterialref(A) (SSmaterials.materials[A] || A)
-
/// Flag for atoms, this flag ensures it isn't re-colored by materials. Useful for snowflake icons such as default toolboxes.
#define MATERIAL_COLOR (1<<0)
#define MATERIAL_ADD_PREFIX (1<<1)
diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm
index 7a19c1ba9d2..f4246e19b3c 100644
--- a/code/__DEFINES/subsystems.dm
+++ b/code/__DEFINES/subsystems.dm
@@ -107,7 +107,6 @@
#define INIT_ORDER_INPUT 85
#define INIT_ORDER_VIS 80
#define INIT_ORDER_ACHIEVEMENTS 77
-#define INIT_ORDER_MATERIALS 76
#define INIT_ORDER_RESEARCH 75
#define INIT_ORDER_EVENTS 70
#define INIT_ORDER_JOBS 65
diff --git a/code/controllers/subsystem/materials.dm b/code/controllers/subsystem/materials.dm
index 0dcc5e96997..9813df6e747 100644
--- a/code/controllers/subsystem/materials.dm
+++ b/code/controllers/subsystem/materials.dm
@@ -7,12 +7,11 @@ These materials call on_applied() on whatever item they are applied to, common e
SUBSYSTEM_DEF(materials)
name = "Materials"
- flags = SS_NO_FIRE
- init_order = INIT_ORDER_MATERIALS
+ flags = SS_NO_FIRE | SS_NO_INIT
///Dictionary of material.type || material ref
- var/list/materials = list()
+ var/list/materials
///Dictionary of category || list of material refs
- var/list/materials_by_category = list()
+ var/list/materials_by_category
///List of stackcrafting recipes for materials using rigid materials
var/list/rigid_stack_recipes = list(
new /datum/stack_recipe("chair", /obj/structure/chair/greyscale, one_per_turf = TRUE, on_floor = TRUE, applies_mats = TRUE),
@@ -20,14 +19,17 @@ SUBSYSTEM_DEF(materials)
new /datum/stack_recipe("sink", /obj/structure/sink/greyscale, one_per_turf = TRUE, on_floor = TRUE, applies_mats = TRUE),
)
-/datum/controller/subsystem/materials/Initialize(timeofday)
- InitializeMaterials()
- return ..()
-
///Ran on initialize, populated the materials and materials_by_category dictionaries with their appropiate vars (See these variables for more info)
-/datum/controller/subsystem/materials/proc/InitializeMaterials(timeofday)
+/datum/controller/subsystem/materials/proc/InitializeMaterials()
+ materials = list()
+ materials_by_category = list()
for(var/type in subtypesof(/datum/material))
var/datum/material/ref = new type
materials[type] = ref
for(var/c in ref.categories)
materials_by_category[c] += list(ref)
+
+/datum/controller/subsystem/materials/proc/GetMaterialRef(datum/material/fakemat)
+ if(!materials)
+ InitializeMaterials()
+ return materials[fakemat] || fakemat
diff --git a/code/datums/components/material_container.dm b/code/datums/components/material_container.dm
index 9bf2dc3819e..29931c900ef 100644
--- a/code/datums/components/material_container.dm
+++ b/code/datums/components/material_container.dm
@@ -42,7 +42,7 @@
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/OnExamine)
for(var/mat in mat_list) //Make the assoc list ref | amount
- var/datum/material/M = getmaterialref(mat) || mat
+ var/datum/material/M = SSmaterials.GetMaterialRef(mat)
materials[M] = 0
/datum/component/material_container/proc/OnExamine(datum/source, mob/user)
@@ -128,9 +128,9 @@
return primary_mat
/// For inserting an amount of material
-/datum/component/material_container/proc/insert_amount_mat(amt, var/datum/material/mat)
+/datum/component/material_container/proc/insert_amount_mat(amt, var/datum/material/mat)
if(!istype(mat))
- mat = getmaterialref(mat)
+ mat = SSmaterials.GetMaterialRef(mat)
if(amt > 0 && has_space(amt))
var/total_amount_saved = total_amount
if(mat)
@@ -143,9 +143,9 @@
return FALSE
/// Uses an amount of a specific material, effectively removing it.
-/datum/component/material_container/proc/use_amount_mat(amt, var/datum/material/mat)
+/datum/component/material_container/proc/use_amount_mat(amt, var/datum/material/mat)
if(!istype(mat))
- mat = getmaterialref(mat)
+ mat = SSmaterials.GetMaterialRef(mat)
var/amount = materials[mat]
if(mat)
if(amount >= amt)
@@ -155,9 +155,9 @@
return FALSE
/// Proc for transfering materials to another container.
-/datum/component/material_container/proc/transer_amt_to(var/datum/component/material_container/T, amt, var/datum/material/mat)
+/datum/component/material_container/proc/transer_amt_to(var/datum/component/material_container/T, amt, var/datum/material/mat)
if(!istype(mat))
- mat = getmaterialref(mat)
+ mat = SSmaterials.GetMaterialRef(mat)
if((amt==0)||(!T)||(!mat))
return FALSE
if(amt<0)
@@ -184,13 +184,13 @@
/datum/component/material_container/proc/use_materials(list/mats, multiplier=1)
if(!mats || !length(mats))
return FALSE
-
+
var/list/mats_to_remove = list() //Assoc list MAT | AMOUNT
for(var/x in mats) //Loop through all required materials
var/datum/material/req_mat = x
if(!istype(req_mat))
- req_mat = getmaterialref(req_mat) //Get the ref if necesary
+ req_mat = SSmaterials.GetMaterialRef(req_mat) //Get the ref if necesary
if(!materials[req_mat]) //Do we have the resource?
return FALSE //Can't afford it
var/amount_required = mats[x] * multiplier
@@ -198,7 +198,7 @@
return FALSE //Can't afford it
mats_to_remove[req_mat] += amount_required //Add it to the assoc list of things to remove
continue
-
+
var/total_amount_save = total_amount
for(var/i in mats_to_remove)
@@ -207,7 +207,7 @@
return total_amount_save - total_amount
/// For spawning mineral sheets at a specific location. Used by machines to output sheets.
-/datum/component/material_container/proc/retrieve_sheets(sheet_amt, var/datum/material/M, target = null)
+/datum/component/material_container/proc/retrieve_sheets(sheet_amt, var/datum/material/M, target = null)
if(!M.sheet_type)
return 0 //Add greyscale sheet handling here later
if(sheet_amt <= 0)
@@ -231,7 +231,7 @@
/// Proc to get all the materials and dump them as sheets
-/datum/component/material_container/proc/retrieve_all(target = null)
+/datum/component/material_container/proc/retrieve_all(target = null)
var/result = 0
for(var/MAT in materials)
var/amount = materials[MAT]
@@ -251,7 +251,7 @@
var/datum/material/req_mat = x
if(!istype(req_mat))
if(ispath(req_mat)) //Is this an actual material, or is it a category?
- req_mat = getmaterialref(req_mat) //Get the ref
+ req_mat = SSmaterials.GetMaterialRef(req_mat) //Get the ref
else // Its a category. (For example MAT_CATEGORY_RIGID)
if(!has_enough_of_category(req_mat, mats[x], multiplier)) //Do we have enough of this category?
@@ -265,7 +265,7 @@
return TRUE
/// Returns all the categories in a recipe.
-/datum/component/material_container/proc/get_categories(list/mats)
+/datum/component/material_container/proc/get_categories(list/mats)
var/list/categories = list()
for(var/x in mats) //Loop through all required materials
if(!istext(x)) //This means its not a category
@@ -275,12 +275,12 @@
/// Returns TRUE if you have enough of the specified material.
-/datum/component/material_container/proc/has_enough_of_material(var/datum/material/req_mat, amount, multiplier=1)
+/datum/component/material_container/proc/has_enough_of_material(var/datum/material/req_mat, amount, multiplier=1)
if(!materials[req_mat]) //Do we have the resource?
return FALSE //Can't afford it
var/amount_required = amount * multiplier
if(materials[req_mat] >= amount_required) // do we have enough of the resource?
- return TRUE
+ return TRUE
return FALSE //Can't afford it
/// Returns TRUE if you have enough of a specified material category (Which could be multiple materials)
@@ -292,7 +292,7 @@
return FALSE
/// Turns a material amount into the amount of sheets it should output
-/datum/component/material_container/proc/amount2sheet(amt)
+/datum/component/material_container/proc/amount2sheet(amt)
if(amt >= MINERAL_MATERIAL_AMOUNT)
return round(amt / MINERAL_MATERIAL_AMOUNT)
return FALSE
@@ -314,7 +314,7 @@
return material_amount
/// Returns the amount of a specific material in this container.
-/datum/component/material_container/proc/get_material_amount(var/datum/material/mat)
+/datum/component/material_container/proc/get_material_amount(var/datum/material/mat)
if(!istype(mat))
- mat = getmaterialref(mat)
+ mat = SSmaterials.GetMaterialRef(mat)
return(materials[mat])
diff --git a/code/game/atoms.dm b/code/game/atoms.dm
index bf1c631c30c..bdc2c563f7a 100644
--- a/code/game/atoms.dm
+++ b/code/game/atoms.dm
@@ -161,7 +161,7 @@
var/temp_list = list()
for(var/i in custom_materials)
- temp_list[getmaterialref(i)] = custom_materials[i] //Get the proper instanced version
+ temp_list[SSmaterials.GetMaterialRef(i)] = custom_materials[i] //Get the proper instanced version
custom_materials = null //Null the list to prepare for applying the materials properly
set_custom_materials(temp_list)
@@ -1204,7 +1204,7 @@
if(custom_materials) //Only runs if custom materials existed at first. Should usually be the case but check anyways
for(var/i in custom_materials)
- var/datum/material/custom_material = getmaterialref(i)
+ var/datum/material/custom_material = SSmaterials.GetMaterialRef(i)
custom_material.on_removed(src, material_flags) //Remove the current materials
if(!length(materials))
@@ -1213,7 +1213,7 @@
custom_materials = list() //Reset the list
for(var/x in materials)
- var/datum/material/custom_material = getmaterialref(x)
+ var/datum/material/custom_material = SSmaterials.GetMaterialRef(x)
if(!(material_flags & MATERIAL_NO_EFFECTS))
custom_material.on_applied(src, materials[custom_material] * multiplier * material_modifier, material_flags)
diff --git a/code/game/machinery/autolathe.dm b/code/game/machinery/autolathe.dm
index 97cfa97715c..32cf77212bf 100644
--- a/code/game/machinery/autolathe.dm
+++ b/code/game/machinery/autolathe.dm
@@ -142,7 +142,7 @@
/obj/machinery/autolathe/proc/AfterMaterialInsert(item_inserted, id_inserted, amount_inserted)
if(istype(item_inserted, /obj/item/stack/ore/bluespace_crystal))
use_power(MINERAL_MATERIAL_AMOUNT / 10)
- else if(custom_materials && custom_materials.len && custom_materials[getmaterialref(/datum/material/glass)])
+ else if(custom_materials && custom_materials.len && custom_materials[SSmaterials.GetMaterialRef(/datum/material/glass)])
flick("autolathe_r",src)//plays glass insertion animation by default otherwise
else
flick("autolathe_o",src)//plays metal insertion animation
diff --git a/code/game/objects/items/apc_frame.dm b/code/game/objects/items/apc_frame.dm
index e5bdd85de23..7d98d227169 100644
--- a/code/game/objects/items/apc_frame.dm
+++ b/code/game/objects/items/apc_frame.dm
@@ -66,8 +66,8 @@
if(iswallturf(T))
T.attackby(src, user, params)
- var/metal_amt = round(custom_materials[getmaterialref(/datum/material/iron)]/MINERAL_MATERIAL_AMOUNT) //Replace this shit later
- var/glass_amt = round(custom_materials[getmaterialref(/datum/material/glass)]/MINERAL_MATERIAL_AMOUNT) //Replace this shit later
+ var/metal_amt = round(custom_materials[SSmaterials.GetMaterialRef(/datum/material/iron)]/MINERAL_MATERIAL_AMOUNT) //Replace this shit later
+ var/glass_amt = round(custom_materials[SSmaterials.GetMaterialRef(/datum/material/glass)]/MINERAL_MATERIAL_AMOUNT) //Replace this shit later
if(W.tool_behaviour == TOOL_WRENCH && (metal_amt || glass_amt))
to_chat(user, "You dismantle [src].")
diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm
index 832a63fac8c..aa21eb24460 100644
--- a/code/game/objects/items/stacks/stack.dm
+++ b/code/game/objects/items/stacks/stack.dm
@@ -52,7 +52,7 @@
mats_per_unit = list()
var/in_process_mat_list = custom_materials.Copy()
for(var/i in custom_materials)
- mats_per_unit[getmaterialref(i)] = in_process_mat_list[i]
+ mats_per_unit[SSmaterials.GetMaterialRef(i)] = in_process_mat_list[i]
custom_materials[i] *= amount
. = ..()
if(merge)
@@ -62,7 +62,7 @@
var/list/temp_recipes = get_main_recipes()
recipes = temp_recipes.Copy()
if(material_type)
- var/datum/material/M = getmaterialref(material_type) //First/main material
+ var/datum/material/M = SSmaterials.GetMaterialRef(material_type) //First/main material
for(var/i in M.categories)
switch(i)
if(MAT_CATEGORY_RIGID)
@@ -236,7 +236,7 @@
if(R.applies_mats && custom_materials && custom_materials.len)
var/list/used_materials = list()
for(var/i in custom_materials)
- used_materials[getmaterialref(i)] = R.req_amount / R.res_amount * (MINERAL_MATERIAL_AMOUNT / custom_materials.len)
+ used_materials[SSmaterials.GetMaterialRef(i)] = R.req_amount / R.res_amount * (MINERAL_MATERIAL_AMOUNT / custom_materials.len)
O.set_custom_materials(used_materials)
//START: oh fuck i'm so sorry
diff --git a/code/game/objects/structures/beds_chairs/chair.dm b/code/game/objects/structures/beds_chairs/chair.dm
index 8bec5d3c4c5..916cbe061b1 100644
--- a/code/game/objects/structures/beds_chairs/chair.dm
+++ b/code/game/objects/structures/beds_chairs/chair.dm
@@ -314,7 +314,7 @@
if(remaining_mats)
for(var/M=1 to remaining_mats)
new stack_type(get_turf(loc))
- else if(custom_materials[getmaterialref(/datum/material/iron)])
+ else if(custom_materials[SSmaterials.GetMaterialRef(/datum/material/iron)])
new /obj/item/stack/rods(get_turf(loc), 2)
qdel(src)
diff --git a/code/modules/antagonists/swarmer/swarmer.dm b/code/modules/antagonists/swarmer/swarmer.dm
index ef315af4726..d2b20af0832 100644
--- a/code/modules/antagonists/swarmer/swarmer.dm
+++ b/code/modules/antagonists/swarmer/swarmer.dm
@@ -193,7 +193,7 @@
/obj/item/IntegrateAmount() //returns the amount of resources gained when eating this item
if(custom_materials)
- if(custom_materials[getmaterialref(/datum/material/iron)] || custom_materials[getmaterialref(/datum/material/glass)])
+ if(custom_materials[SSmaterials.GetMaterialRef(/datum/material/iron)] || custom_materials[SSmaterials.GetMaterialRef(/datum/material/glass)])
return 1
return ..()
diff --git a/code/modules/cargo/exports/materials.dm b/code/modules/cargo/exports/materials.dm
index 09ce7dd6832..fa0281c621b 100644
--- a/code/modules/cargo/exports/materials.dm
+++ b/code/modules/cargo/exports/materials.dm
@@ -14,10 +14,10 @@
if(!isitem(O))
return 0
var/obj/item/I = O
- if(!(getmaterialref(material_id) in I.custom_materials))
+ if(!(SSmaterials.GetMaterialRef(material_id) in I.custom_materials))
return 0
- var/amount = I.custom_materials[getmaterialref(material_id)]
+ var/amount = I.custom_materials[SSmaterials.GetMaterialRef(material_id)]
if(istype(I, /obj/item/stack/ore))
amount *= 0.8 // Station's ore redemption equipment is really goddamn good.
diff --git a/code/modules/food_and_drinks/kitchen_machinery/microwave.dm b/code/modules/food_and_drinks/kitchen_machinery/microwave.dm
index 72fc79754fd..58b7ede754b 100644
--- a/code/modules/food_and_drinks/kitchen_machinery/microwave.dm
+++ b/code/modules/food_and_drinks/kitchen_machinery/microwave.dm
@@ -310,8 +310,8 @@
for(var/obj/item/O in ingredients)
O.microwave_act(src)
if(O.custom_materials && length(O.custom_materials))
- if(O.custom_materials[getmaterialref(/datum/material/iron)])
- metal += O.custom_materials[getmaterialref(/datum/material/iron)]
+ if(O.custom_materials[SSmaterials.GetMaterialRef(/datum/material/iron)])
+ metal += O.custom_materials[SSmaterials.GetMaterialRef(/datum/material/iron)]
if(metal)
spark()
diff --git a/code/modules/hydroponics/biogenerator.dm b/code/modules/hydroponics/biogenerator.dm
index 2d620e1d81b..11d7acdbe71 100644
--- a/code/modules/hydroponics/biogenerator.dm
+++ b/code/modules/hydroponics/biogenerator.dm
@@ -194,7 +194,7 @@
dat += "x5"
if(ispath(D.build_path, /obj/item/stack))
dat += "x10"
- dat += "([D.materials[getmaterialref(/datum/material/biomass)]/efficiency])
"
+ dat += "([D.materials[SSmaterials.GetMaterialRef(/datum/material/biomass)]/efficiency])
"
dat += ""
else
dat += "