Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Commit 3a63fbb

Browse files
committed
feat: error handling in recipe loader
1 parent bb4cc93 commit 3a63fbb

1 file changed

Lines changed: 64 additions & 38 deletions

File tree

  • src/main/kotlin/net/guizhanss/fastmachines/core/recipes/loaders

src/main/kotlin/net/guizhanss/fastmachines/core/recipes/loaders/RecipeLoader.kt

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import net.guizhanss.fastmachines.core.recipes.StandardRecipe
66
import net.guizhanss.fastmachines.core.recipes.raw.RawRecipe
77
import net.guizhanss.fastmachines.implementation.items.machines.base.BaseFastMachine
88
import net.guizhanss.fastmachines.utils.items.isDisabled
9+
import java.util.logging.Level
910

1011
/**
1112
* A [RecipeLoader] is responsible for loading recipes for a specific [BaseFastMachine].
@@ -43,53 +44,78 @@ abstract class RecipeLoader(
4344
val groupedRecipes = rawRecipes.groupBy { it.inputKey() }
4445

4546
groupedRecipes.forEach { (inputKey, recipes) ->
46-
FastMachines.debug("===============")
47-
FastMachines.debug("Processing recipes with input key: $inputKey")
48-
49-
val input = recipes.first().inputs.first()
50-
val outputs = recipes.map { it.output }.flatten().filter { !it.isDisabled() }
51-
52-
// all disabled, no recipe
53-
if (outputs.isEmpty()) {
54-
return@forEach
55-
}
56-
57-
FastMachines.debug(" - Input: $input")
58-
FastMachines.debug(" - Outputs: $outputs")
59-
60-
val recipe = if (outputs.size > 1) {
61-
RandomRecipe(input, outputs)
62-
} else {
63-
StandardRecipe(listOf(input), outputs.first())
47+
try {
48+
FastMachines.debug("===============")
49+
FastMachines.debug("Processing recipes with input key: $inputKey")
50+
51+
val input = recipes.first().inputs.first()
52+
val outputs = recipes.map { it.output }.flatten().filter { !it.isDisabled() }
53+
54+
// all disabled, no recipe
55+
if (outputs.isEmpty()) {
56+
return@forEach
57+
}
58+
59+
FastMachines.debug(" - Input: $input")
60+
FastMachines.debug(" - Outputs: $outputs")
61+
62+
val recipe = if (outputs.size > 1) {
63+
RandomRecipe(input, outputs)
64+
} else {
65+
StandardRecipe(listOf(input), outputs.first())
66+
}
67+
FastMachines.debug(" - Created recipe: $recipe")
68+
machine.addRecipe(recipe)
69+
} catch (e: Exception) {
70+
FastMachines.log(
71+
Level.SEVERE,
72+
e,
73+
"""
74+
An unexpected error has occurred while loading grouped recipes.
75+
Please enable debug mode first and restart the server,
76+
report this issue with FULL debug log only.
77+
""".trimIndent().replace("\n", "")
78+
)
6479
}
65-
FastMachines.debug(" - Created recipe: $recipe")
66-
machine.addRecipe(recipe)
6780
}
6881
}
6982

7083
private fun loadRecipes() {
7184
sortRecipes()
7285

7386
rawRecipes.forEachIndexed { index, rawRecipe ->
74-
FastMachines.debug("===============")
75-
FastMachines.debug("Processing raw recipe (${index + 1}/${rawRecipes.size}): $rawRecipe")
76-
77-
if (rawRecipe.output.size > 1) {
78-
FastMachines.debug(" - Unexpected multiple outputs, skipping")
79-
return@forEachIndexed
87+
try {
88+
89+
FastMachines.debug("===============")
90+
FastMachines.debug("Processing raw recipe (${index + 1}/${rawRecipes.size}): $rawRecipe")
91+
92+
if (rawRecipe.output.size > 1) {
93+
FastMachines.debug(" - Unexpected multiple outputs, skipping")
94+
return@forEachIndexed
95+
}
96+
97+
val outputItem = rawRecipe.output.first()
98+
99+
// no need to load recipe if the output item is disabled
100+
if (outputItem.isDisabled()) {
101+
FastMachines.debug(" - Output item is a disabled Slimefun item, skipping")
102+
return@forEachIndexed
103+
}
104+
105+
val recipe = StandardRecipe(rawRecipe.inputs, outputItem)
106+
FastMachines.debug(" - Created recipe: $recipe")
107+
machine.addRecipe(recipe)
108+
} catch (e: Exception) {
109+
FastMachines.log(
110+
Level.SEVERE,
111+
e,
112+
"""
113+
An unexpected error has occurred while loading recipes.
114+
Please enable debug mode first and restart the server,
115+
report this issue with FULL debug log only.
116+
""".trimIndent().replace("\n", "")
117+
)
80118
}
81-
82-
val outputItem = rawRecipe.output.first()
83-
84-
// no need to load recipe if the output item is disabled
85-
if (outputItem.isDisabled()) {
86-
FastMachines.debug(" - Output item is a disabled Slimefun item, skipping")
87-
return@forEachIndexed
88-
}
89-
90-
val recipe = StandardRecipe(rawRecipe.inputs, outputItem)
91-
FastMachines.debug(" - Created recipe: $recipe")
92-
machine.addRecipe(recipe)
93119
}
94120
}
95121

0 commit comments

Comments
 (0)