From 91c8100729be120ea06a0fd7a7e28e327ed5a6ed Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Sat, 21 Oct 2023 15:32:25 +0300 Subject: [PATCH] =?UTF-8?q?DBot=20=E2=80=94=20=D0=A1=D0=B5=D0=B3=D0=BE?= =?UTF-8?q?=D0=B4=D0=BD=D1=8F,=20=D0=B2=2014:51=20=D0=A1=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D1=87=D1=82=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=20=D0=9F=D0=BE=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B5=20=D0=B4=D0=BE=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BE=D0=B1=D1=80=D0=B0=D1=82=D0=BD=D0=BE=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mc/otm/matter/MatterManager.kt | 51 +++++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 3 ++ .../otm_recipe_finder/smithing.json | 2 +- 3 files changed, 55 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 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