Skip to content

Commit

Permalink
Resolve conflict with Traveler's Backpack
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
Ampflower committed Aug 30, 2024
1 parent 2555e64 commit 7444138
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@

import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.RecipeCraftingHolder;
import net.minecraft.world.inventory.ResultContainer;
import net.minecraft.world.inventory.ResultSlot;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
Expand Down Expand Up @@ -77,7 +81,7 @@ public void set(ItemStack stack) {
@Redirect(method = "checkTakeAchievements",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/RecipeCraftingHolder;awardUsedRecipes(Lnet/minecraft/world/entity/player/Player;Ljava/util/List;)V"))
public void no(final RecipeCraftingHolder instance, final Player player, final List<ItemStack> list) {
if (((CraftingInventoryDuck) craftSlots).getCheckMatrixChanges() &&
if ((!(craftSlots instanceof CraftingInventoryDuck duck) || duck.getCheckMatrixChanges()) &&
this.container instanceof RecipeCraftingHolder recipeHolder) {
var recipeUsed = recipeHolder.getRecipeUsed();
if (recipeUsed != null && !recipeUsed.value().isSpecial()) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/tfar/fastbench/mixin/RecipeManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ public class RecipeManagerMixin {
//note: C is actually CraftingInventory, treat it accordingly
@Inject(method = "getRemainingItemsFor",at = @At("HEAD"),cancellable = true)
private <C extends Container, T extends Recipe<C>> void techRebornWorkAround(RecipeType<T> recipeType, C craftInput, Level world, CallbackInfoReturnable<NonNullList<ItemStack>> cir) {
if (MixinHooks.hascachedrecipe) {
if (MixinHooks.lastRecipe != null) cir.setReturnValue(MixinHooks.lastRecipe.getRemainingItems((CraftingContainer) craftInput));
else cir.setReturnValue(((CraftingInventoryAccessor) craftInput).getItems());
// Explicit check on CraftingInventoryAccessor resolves crash relating to Traveler's Backpack
if (MixinHooks.hascachedrecipe && craftInput instanceof CraftingInventoryAccessor accessor) {
if (MixinHooks.lastRecipe != null) {
cir.setReturnValue(MixinHooks.lastRecipe.getRemainingItems((CraftingContainer) craftInput));
} else {
cir.setReturnValue(accessor.getItems());
}
MixinHooks.hascachedrecipe = false;
}
}
Expand Down

0 comments on commit 7444138

Please sign in to comment.