diff --git a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/StonecutterScreenHandlerMixin.java b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/StonecutterScreenHandlerMixin.java new file mode 100644 index 0000000000..807171c016 --- /dev/null +++ b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/mixin/recipe/ingredient/StonecutterScreenHandlerMixin.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.recipe.ingredient; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.StonecutterScreenHandler; + +@Mixin(StonecutterScreenHandler.class) +public class StonecutterScreenHandlerMixin { + @Shadow + @Final + private ItemStack inputStack; + + /** + * Since stonecutting recipes with custom ingredients can be stack-aware, recalculating available recipes + * only when the input stack's item changes is not enough. This mixin allows the available recipes to be + * recalculated when the input stack changes in any way. + * + * @see Issue #4340 + */ + @Redirect( + method = "onContentChanged", + at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z") + ) + private boolean recalculateAvailableRecipesForStackChange(ItemStack stack, Item item) { + return ItemStack.areEqual(stack, this.inputStack); + } +} diff --git a/fabric-recipe-api-v1/src/main/resources/fabric-recipe-api-v1.mixins.json b/fabric-recipe-api-v1/src/main/resources/fabric-recipe-api-v1.mixins.json index 3d8508418f..2ca6436bd0 100644 --- a/fabric-recipe-api-v1/src/main/resources/fabric-recipe-api-v1.mixins.json +++ b/fabric-recipe-api-v1/src/main/resources/fabric-recipe-api-v1.mixins.json @@ -6,7 +6,8 @@ "ingredient.ClientConnectionMixin", "ingredient.EncoderHandlerMixin", "ingredient.IngredientMixin", - "ingredient.ShapelessRecipeMixin" + "ingredient.ShapelessRecipeMixin", + "ingredient.StonecutterScreenHandlerMixin" ], "injectors": { "defaultRequire": 1 diff --git a/fabric-recipe-api-v1/src/testmod/resources/data/fabric-recipe-api-v1-testmod/recipe/test_stonecutter_default_match.json b/fabric-recipe-api-v1/src/testmod/resources/data/fabric-recipe-api-v1-testmod/recipe/test_stonecutter_default_match.json new file mode 100644 index 0000000000..b032a787b0 --- /dev/null +++ b/fabric-recipe-api-v1/src/testmod/resources/data/fabric-recipe-api-v1-testmod/recipe/test_stonecutter_default_match.json @@ -0,0 +1,7 @@ +{ + "type": "minecraft:stonecutting", + "ingredient": "minecraft:redstone_ore", + "result": { + "id": "minecraft:redstone_block" + } +} diff --git a/fabric-recipe-api-v1/src/testmod/resources/data/fabric-recipe-api-v1-testmod/recipe/test_stonecutter_epic_match.json b/fabric-recipe-api-v1/src/testmod/resources/data/fabric-recipe-api-v1-testmod/recipe/test_stonecutter_epic_match.json new file mode 100644 index 0000000000..af187a85f0 --- /dev/null +++ b/fabric-recipe-api-v1/src/testmod/resources/data/fabric-recipe-api-v1-testmod/recipe/test_stonecutter_epic_match.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:stonecutting", + "ingredient": { + "fabric:type": "fabric:components", + "base": "minecraft:redstone_ore", + "components": { + "minecraft:rarity": "epic" + } + }, + "result": { + "id": "minecraft:emerald_block" + } +}