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 7d63a45e6..1c55d6324 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt @@ -42,8 +42,10 @@ import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.world.inventory.TransientCraftingContainer import net.minecraft.world.item.Item import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.crafting.Ingredient import net.minecraft.world.item.crafting.Recipe import net.minecraft.world.item.crafting.RecipeType +import net.minecraft.world.item.crafting.SmithingTransformRecipe import net.minecraft.world.level.ItemLike import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.crafting.IShapedRecipe @@ -585,6 +587,55 @@ object MatterManager { } } } + + registrar.register("smithing") { + 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 isCritical = data["is_critical"]?.asBoolean ?: true + val allowBacktrack = data["allow_backtrack"]?.asBoolean ?: true + + var stream = server.recipeManager.byType(findRecipeType).values.stream().filter { !it.value.isIncomplete } + stream = stream.filter { it.value is SmithingTransformRecipe } + + stream.filter { it.value.getResultItem(server.registryAccess()).isNotEmpty }.map { + try { + val ingredients = ArrayList() + + val recipe = it.value as SmithingTransformRecipe + + ingredients.add(recipe.base) + ingredients.add(recipe.addition) + + ResolvedRecipe( + ingredients.stream() + .filter { !it.isActuallyEmpty } + .map { it.items.stream().filter { it.isNotEmpty }.map(::RecipeEntry) }, + ImmutableStack(it.value.getResultItem(server.registryAccess())), + isCritical = isCritical, + name = it.id, + allowBacktrack = allowBacktrack + ) + } catch(err: Throwable) { + throw RuntimeException("Processing smithing recipe ${it.id}", err) + } + }.filterNotNull().filter { + if (it.inputs.isEmpty()) { + LOGGER.warn("${it.formattedName} with output '${it.output.item.registryName}' ended up with no inputs!") + false + } else { + true + } + } + } + } } private var foundResolvers: Map> = ImmutableMap.of() diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index b97fad5c6..b77390770 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -156,6 +156,9 @@ public net.minecraft.client.renderer.FogRenderer f_109010_ # fogRed public net.minecraft.world.item.crafting.RecipeManager m_44054_(Lnet/minecraft/world/item/crafting/RecipeType;)Ljava/util/Map; # byType +public net.minecraft.world.item.crafting.SmithingTransformRecipe f_265888_ # base +public net.minecraft.world.item.crafting.SmithingTransformRecipe f_265907_ # addition + public net.minecraft.world.entity.boss.wither.WitherBoss f_31432_ # TARGETING_CONDITIONS public-f net.minecraft.world.entity.boss.wither.WitherBoss f_31431_ # LIVING_ENTITY_SELECTOR public net.minecraft.world.entity.ai.targeting.TargetingConditions f_26879_ # selector diff --git a/src/main/resources/data/overdrive_that_matters/otm_recipe_finder/smithing.json b/src/main/resources/data/overdrive_that_matters/otm_recipe_finder/smithing.json index f5aebe2b2..59297e8b1 100644 --- a/src/main/resources/data/overdrive_that_matters/otm_recipe_finder/smithing.json +++ b/src/main/resources/data/overdrive_that_matters/otm_recipe_finder/smithing.json @@ -1,5 +1,5 @@ { "recipe_type": "minecraft:smithing", - "type": "overdrive_that_matters:simple", + "type": "overdrive_that_matters:smithing", "is_critical": false } \ No newline at end of file