Skip to content

Commit

Permalink
#204 Fix render when multiple items are registered for crafting category
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Apr 29, 2016
1 parent 3ee67d3 commit 1ecbad6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
17 changes: 17 additions & 0 deletions src/main/java/mezz/jei/gui/Focus.java
Expand Up @@ -5,8 +5,11 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import mezz.jei.util.StackHelper;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
Expand Down Expand Up @@ -158,6 +161,20 @@ public List<Object> getRecipes(@Nonnull IRecipeCategory recipeCategory) {
}
}

@Nonnull
public Collection<ItemStack> getRecipeCategoryCraftingItems(@Nonnull IRecipeCategory recipeCategory) {
IRecipeRegistry recipeRegistry = Internal.getRuntime().getRecipeRegistry();
Collection<ItemStack> craftingItems = recipeRegistry.getCraftingItems(recipeCategory);
if (stack != null && mode == Mode.INPUT) {
StackHelper stackHelper = Internal.getStackHelper();
ItemStack matchingStack = stackHelper.containsStack(craftingItems, stack);
if (matchingStack != null) {
return Collections.singletonList(matchingStack);
}
}
return craftingItems;
}

@Nonnull
private List<Object> getInputRecipes(@Nonnull IRecipeRegistry recipeRegistry, @Nonnull IRecipeCategory recipeCategory) {
if (stack != null && fluid != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mezz/jei/gui/RecipeGuiLogic.java
Expand Up @@ -202,9 +202,9 @@ private void updateRecipes() {
recipes = Collections.emptyList();
recipeCategoryCraftingItems = Collections.emptyList();
} else {
recipes = state.focus.getRecipes(recipeCategory);
IRecipeRegistry recipeRegistry = Internal.getRuntime().getRecipeRegistry();
recipeCategoryCraftingItems = recipeRegistry.getCraftingItems(recipeCategory);
Focus focus = state.focus;
recipes = focus.getRecipes(recipeCategory);
recipeCategoryCraftingItems = focus.getRecipeCategoryCraftingItems(recipeCategory);
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/mezz/jei/gui/RecipesGui.java
Expand Up @@ -57,6 +57,7 @@ public class RecipesGui extends GuiScreen implements IRecipesGui, IShowsRecipeFo
private String title;
private ResourceLocation backgroundTexture;
private IDrawable recipeCategoryCraftItemBox;
private final GuiItemStackGroup recipeCategoryCraftingItem = new GuiItemStackGroup();
private HoverChecker titleHoverChecker;

private GuiButton nextRecipeCategory;
Expand Down Expand Up @@ -180,10 +181,6 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
recipeCategoryCraftItemBox.draw(mc, recipeCraftingItemArea.x, recipeCraftingItemArea.y);
GlStateManager.disableAlpha();

GuiItemStackGroup recipeCategoryCraftingItem = new GuiItemStackGroup();
recipeCategoryCraftingItem.init(0, true, recipeCraftingItemArea.x + 5, recipeCraftingItemArea.y + 5);
recipeCategoryCraftingItem.set(0, recipeCategoryCraftingItems);

RenderHelper.enableGUIStandardItemLighting();
hoveredItemStack = recipeCategoryCraftingItem.draw(mc, 0, 0, mouseX, mouseY);
RenderHelper.disableStandardItemLighting();
Expand Down Expand Up @@ -235,15 +232,9 @@ public boolean isMouseOver(int mouseX, int mouseY) {
public Focus getFocusUnderMouse(int mouseX, int mouseY) {
Rectangle recipeCraftingItemArea = getRecipeCraftingItemArea();
if (recipeCraftingItemArea != null && recipeCraftingItemArea.contains(mouseX, mouseY)) {
Collection<ItemStack> recipeCategoryCraftingItems = logic.getRecipeCategoryCraftingItems();
if (!recipeCategoryCraftingItems.isEmpty()) {
GuiItemStackGroup recipeCategoryCraftingItem = new GuiItemStackGroup();
recipeCategoryCraftingItem.init(0, true, recipeCraftingItemArea.x + 5, recipeCraftingItemArea.y + 5);
recipeCategoryCraftingItem.set(0, recipeCategoryCraftingItems);
Focus focus = recipeCategoryCraftingItem.getFocusUnderMouse(0, 0, mouseX, mouseY);
if (focus != null) {
return focus;
}
Focus focus = recipeCategoryCraftingItem.getFocusUnderMouse(0, 0, mouseX, mouseY);
if (focus != null) {
return focus;
}
}

Expand Down Expand Up @@ -466,6 +457,15 @@ private void updateLayout() {
nextRecipeCategory.enabled = previousRecipeCategory.enabled = logic.hasMultipleCategories();

pageString = logic.getPageString();

Collection<ItemStack> recipeCategoryCraftingItems = logic.getRecipeCategoryCraftingItems();
if (!recipeCategoryCraftingItems.isEmpty()) {
Rectangle recipeCraftingItemArea = getRecipeCraftingItemArea();
if (recipeCraftingItemArea != null) {
recipeCategoryCraftingItem.init(0, true, recipeCraftingItemArea.x + 5, recipeCraftingItemArea.y + 5);
recipeCategoryCraftingItem.set(0, recipeCategoryCraftingItems);
}
}
}

private void addRecipeTransferButtons(List<RecipeLayout> recipeLayouts) {
Expand Down

0 comments on commit 1ecbad6

Please sign in to comment.