Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.19.2 and fix various bugs #22

Open
wants to merge 9 commits into
base: 1.18.x
Choose a base branch
from
Prev Previous commit
Readd recipe awarding
Now recipes you use will be awarded as expected.
Ampflower committed Dec 6, 2022
commit eb134a589daac35bffc80c753a7b848f26a4c883
20 changes: 13 additions & 7 deletions src/main/java/tfar/fastbench/MixinHooks.java
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
import tfar.fastbench.interfaces.CraftingInventoryDuck;
import tfar.fastbench.mixin.ContainerAccessor;

import java.util.Collections;

public class MixinHooks {

public static boolean hascachedrecipe = false;
@@ -38,19 +40,18 @@ public static void slotChangedCraftingGrid(Level level, CraftingContainer inv, R

public static ItemStack handleShiftCraft(Player player, AbstractContainerMenu container, Slot resultSlot, CraftingContainer input, ResultContainer craftResult, int outStart, int outEnd) {
ItemStack outputCopy = ItemStack.EMPTY;
CraftingInventoryDuck duck = (CraftingInventoryDuck)input;
CraftingInventoryDuck duck = (CraftingInventoryDuck) input;
duck.setCheckMatrixChanges(false);
if (resultSlot != null && resultSlot.hasItem()) {

Recipe<CraftingContainer> recipe = (Recipe<CraftingContainer>) craftResult.getRecipeUsed();
Recipe<CraftingContainer> recipe = (Recipe<CraftingContainer>) craftResult.getRecipeUsed();

while (recipe != null && recipe.matches(input, player.level)) {
if (recipe != null && resultSlot != null && resultSlot.hasItem()) {
while (recipe.matches(input, player.level)) {
ItemStack recipeOutput = resultSlot.getItem().copy();
outputCopy = recipeOutput.copy();

recipeOutput.getItem().onCraftedBy(recipeOutput, player.level, player);

if (!player.level.isClientSide && !((ContainerAccessor)container).insert(recipeOutput, outStart, outEnd,true)) {
if (!player.level.isClientSide && !((ContainerAccessor) container).insert(recipeOutput, outStart, outEnd, true)) {
duck.setCheckMatrixChanges(true);
return ItemStack.EMPTY;
}
@@ -69,9 +70,14 @@ public static ItemStack handleShiftCraft(Player player, AbstractContainerMenu co
}
duck.setCheckMatrixChanges(true);
slotChangedCraftingGrid(player.level, input, craftResult);

// Award the player the recipe for using it. Mimics vanilla behaviour.
if (!recipe.isSpecial()) {
player.awardRecipes(Collections.singleton(recipe));
}
}
duck.setCheckMatrixChanges(true);
return craftResult.getRecipeUsed() == null ? ItemStack.EMPTY : outputCopy;
return recipe == null ? ItemStack.EMPTY : outputCopy;
}

public static Recipe<CraftingContainer> findRecipe(CraftingContainer inv, Level level) {
11 changes: 10 additions & 1 deletion src/main/java/tfar/fastbench/mixin/CraftingResultSlotMixin.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import tfar.fastbench.MixinHooks;
import tfar.fastbench.interfaces.CraftingInventoryDuck;

import java.util.Collections;

@Mixin(ResultSlot.class)
public class CraftingResultSlotMixin extends Slot {
@@ -46,7 +49,13 @@ public void set(ItemStack stack) {
@Redirect(method = "checkTakeAchievements",
at = @At(value = "INVOKE",target = "Lnet/minecraft/world/inventory/RecipeHolder;awardUsedRecipes(Lnet/minecraft/world/entity/player/Player;)V"))
public void no(RecipeHolder recipeUnlocker, Player player) {
//do nothing
if (((CraftingInventoryDuck) craftSlots).getCheckMatrixChanges() &&
this.container instanceof RecipeHolder recipeHolder) {
var recipeUsed = recipeHolder.getRecipeUsed();
if (recipeUsed != null && !recipeUsed.isSpecial()) {
player.awardRecipes(Collections.singleton(recipeUsed));
}
}
}

//this.container is actually the crafting result inventory so it's a safe cast