Skip to content

Commit

Permalink
Fix #1275 Prioritize showing relevant categories first when in a craf…
Browse files Browse the repository at this point in the history
…ting gui
  • Loading branch information
mezz committed Jul 2, 2018
1 parent c6b1c0b commit 928341a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java
Expand Up @@ -10,9 +10,15 @@
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import mezz.jei.gui.Focus;
import mezz.jei.gui.ingredients.IngredientLookupState;
import mezz.jei.util.MathUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.inventory.Container;

import javax.annotation.Nonnegative;

public class RecipeGuiLogic implements IRecipeGuiLogic {
private final IRecipeRegistry recipeRegistry;
Expand Down Expand Up @@ -46,12 +52,32 @@ public <V> boolean setFocus(IFocus<V> focus) {
history.push(this.state);
}

IngredientLookupState state = new IngredientLookupState(focus, recipeCategories, 0, 0);
int recipeCategoryIndex = getRecipeCategoryIndexToShowFirst(recipeCategories);
IngredientLookupState state = new IngredientLookupState(focus, recipeCategories, recipeCategoryIndex, 0);
setState(state);

return true;
}

@Nonnegative
private int getRecipeCategoryIndexToShowFirst(List<IRecipeCategory> recipeCategories) {
Minecraft minecraft = Minecraft.getMinecraft();
EntityPlayerSP player = minecraft.player;
if (player != null) {
Container openContainer = player.openContainer;
if (openContainer != null) {
for (int i = 0; i < recipeCategories.size(); i++) {
IRecipeCategory recipeCategory = recipeCategories.get(i);
IRecipeTransferHandler recipeTransferHandler = recipeRegistry.getRecipeTransferHandler(openContainer, recipeCategory);
if (recipeTransferHandler != null) {
return i;
}
}
}
}
return 0;
}

@Override
public boolean back() {
if (history.empty()) {
Expand Down

0 comments on commit 928341a

Please sign in to comment.