Skip to content

Commit

Permalink
Fix available stonecutting recipe recalculation not being stack-aware (
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored Jan 7, 2025
1 parent e5be219 commit 339ab8c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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 <a href="https://github.com/FabricMC/fabric/issues/4340">Issue #4340</a>
*/
@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"ingredient.ClientConnectionMixin",
"ingredient.EncoderHandlerMixin",
"ingredient.IngredientMixin",
"ingredient.ShapelessRecipeMixin"
"ingredient.ShapelessRecipeMixin",
"ingredient.StonecutterScreenHandlerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minecraft:stonecutting",
"ingredient": "minecraft:redstone_ore",
"result": {
"id": "minecraft:redstone_block"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 339ab8c

Please sign in to comment.