Skip to content

Commit

Permalink
fix: confusing between some book and stonecutting recipes
Browse files Browse the repository at this point in the history
some book and stonecutting recipes have same input, which may lead to wrongly use of book recipes
  • Loading branch information
wendavid552 committed Feb 23, 2023
1 parent 245db43 commit a1b95c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.gui.screen.ingame.StonecutterScreen;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.StonecuttingRecipe;
import net.minecraft.screen.StonecutterScreenHandler;
import net.minecraft.screen.slot.Slot;
import fi.dy.masa.itemscroller.ItemScroller;
import fi.dy.masa.itemscroller.config.Configs;
Expand Down Expand Up @@ -189,20 +190,19 @@ public void onClientTick(MinecraftClient mc)
RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe();

CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe);
StonecuttingRecipe stonecuttingRecipe = InventoryUtils.getStonecuttingRecipeFromPattern(recipe);
if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible
int stonecuttingRecipeIndex = InventoryUtils.getStonecuttingRecipeFromPattern(recipe);
if (!(gui instanceof StonecutterScreen) && bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible
// System.out.println("recipe");
int option = InventoryUtils.checkRecipeEnough(recipe, gui);
if(option > 0) {
mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, option > 1);
}
}
else if(stonecuttingRecipe != null && gui instanceof StonecutterScreen) {
mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, stonecuttingRecipe, true);
}
else {
// System.out.println("move");
InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true);
if(stonecuttingRecipeIndex != -1 && gui instanceof StonecutterScreen) {
mc.interactionManager.clickButton((gui.getScreenHandler()).syncId, stonecuttingRecipeIndex);
}
}

if(recipe.getResult().isStackable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RecipePattern
private ItemStack[] recipe = new ItemStack[9];
public CraftingRecipe cachedRecipeFromBook = null;

public StonecuttingRecipe cachedRecipeFromStonecutting = null;
public int cachedRecipeFromStonecutting = -1;
private int maxCraftAmount = 64;
private HashSet<Item> recipeRemainders = new HashSet<Item>();

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,8 @@ public static CraftingRecipe getBookRecipeFromPattern(RecipePattern recipe) {
return null;
}

public static StonecuttingRecipe getStonecuttingRecipeFromPattern(RecipePattern recipe) {
if(recipe.cachedRecipeFromStonecutting != null) {
public static int getStonecuttingRecipeFromPattern(RecipePattern recipe) {
if(recipe.cachedRecipeFromStonecutting != -1) {
return recipe.cachedRecipeFromStonecutting;
}
else {
Expand All @@ -1354,14 +1354,15 @@ public static StonecuttingRecipe getStonecuttingRecipeFromPattern(RecipePattern
search.setStack(i, items[i]);
}
List<StonecuttingRecipe> inputRecipes = recipeManager.getAllMatches(RecipeType.STONECUTTING, search, mc.world);
for(StonecuttingRecipe inputRecipe : inputRecipes) {
for(int i=0; i<inputRecipes.size(); ++i) {
StonecuttingRecipe inputRecipe = inputRecipes.get(i);
if(inputRecipe.getOutput().getItem() == recipe.getResult().getItem()) {
recipe.cachedRecipeFromStonecutting = inputRecipe;
return inputRecipe;
recipe.cachedRecipeFromStonecutting = i;
return recipe.cachedRecipeFromStonecutting;
}
}
}
return null;
return -1;
}

public static void craftEverythingPossibleWithCurrentRecipe(RecipePattern recipe,
Expand Down

0 comments on commit a1b95c8

Please sign in to comment.