From 03c12c5737b4c0299069009137f639db7e9a8dd2 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Wed, 19 Jul 2023 11:24:52 +0300 Subject: [PATCH] do use recipe_type for crafting recipe finder for things like create mechanical crafting support --- .../ru/dbotthepony/mc/otm/matter/MatterManager.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt index 43579a4cf..f792586c8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt @@ -471,10 +471,19 @@ object MatterManager { registrar.register("crafting") { Finder { server, data -> + val location = (data["recipe_type"] ?: throw JsonSyntaxException("Missing recipe type")).let { ResourceLocation.tryParse(it.asString) } ?: throw JsonSyntaxException("Invalid recipe type: ${data["recipe_type"]}") + + if (!ForgeRegistries.RECIPE_TYPES.containsKey(location)) { + LOGGER.error("Invalid or missing recipe category: $location!") + return@Finder Stream.empty() + } + + val findRecipeType = ForgeRegistries.RECIPE_TYPES.getValue(location) as RecipeType>? ?: throw ConcurrentModificationException() + val allowBacktrack = data["allow_backtrack"]?.asBoolean ?: true val ignoreDamageables = data["ignore_damageables"]?.asBoolean ?: false val isCritical = data["is_critical"]?.asBoolean ?: true - var stream = server.recipeManager.byType(RecipeType.CRAFTING).values.stream().filter { !it.isIncomplete } + var stream = server.recipeManager.byType(findRecipeType).values.stream().filter { !it.isIncomplete } if (ignoreDamageables) { stream = stream.filter { it.ingredients.stream().flatMap { it.items.stream() }.noneMatch { it.isDamageableItem } }