Skip to content

Commit

Permalink
Add recipe category tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Nov 3, 2016
1 parent c4c03e0 commit 7593f01
Show file tree
Hide file tree
Showing 31 changed files with 1,657 additions and 1,117 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,5 +1,5 @@
mcversion=1.10.2
forgeversion=12.18.2.2097
forgeversion=12.18.2.2118
mcp_mappings=snapshot_20160712
curse_project_id=238222

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/GuiEventHandler.java
Expand Up @@ -5,8 +5,8 @@
import mezz.jei.api.ingredients.IIngredientRegistry;
import mezz.jei.config.Config;
import mezz.jei.gui.ItemListOverlay;
import mezz.jei.gui.RecipesGui;
import mezz.jei.gui.TooltipRenderer;
import mezz.jei.gui.recipes.RecipesGui;
import mezz.jei.input.InputHandler;
import mezz.jei.util.Translator;
import net.minecraft.client.gui.GuiScreen;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/JeiRuntime.java
Expand Up @@ -2,7 +2,7 @@

import mezz.jei.api.IJeiRuntime;
import mezz.jei.gui.ItemListOverlay;
import mezz.jei.gui.RecipesGui;
import mezz.jei.gui.recipes.RecipesGui;

public class JeiRuntime implements IJeiRuntime {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/JeiStarter.java
Expand Up @@ -8,7 +8,7 @@
import mezz.jei.api.IModPlugin;
import mezz.jei.api.gui.IAdvancedGuiHandler;
import mezz.jei.gui.ItemListOverlay;
import mezz.jei.gui.RecipesGui;
import mezz.jei.gui.recipes.RecipesGui;
import mezz.jei.plugins.vanilla.VanillaPlugin;
import mezz.jei.util.Log;
import mezz.jei.util.ModIdUtil;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/RecipeRegistry.java
Expand Up @@ -32,7 +32,7 @@
import mezz.jei.config.Config;
import mezz.jei.config.Constants;
import mezz.jei.gui.Focus;
import mezz.jei.gui.RecipeClickableArea;
import mezz.jei.gui.recipes.RecipeClickableArea;
import mezz.jei.util.ErrorUtil;
import mezz.jei.util.IngredientUtil;
import mezz.jei.util.Ingredients;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/mezz/jei/api/recipe/BlankRecipeCategory.java
@@ -1,12 +1,21 @@
package mezz.jei.api.recipe;

import javax.annotation.Nullable;

import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import net.minecraft.client.Minecraft;

/**
* An {@link IRecipeCategory} that does nothing, inherit from this to avoid implementing methods you don't need.
*/
public abstract class BlankRecipeCategory<T extends IRecipeWrapper> implements IRecipeCategory<T> {
@Nullable
@Override
public IDrawable getIcon() {
return null;
}

@Override
public void drawExtras(Minecraft minecraft) {

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/mezz/jei/api/recipe/IRecipeCategory.java
@@ -1,11 +1,15 @@
package mezz.jei.api.recipe;

import javax.annotation.Nullable;

import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IDrawableAnimated;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;

/**
* Defines a category of recipe, (i.e. Crafting Table Recipe, Furnace Recipe).
Expand Down Expand Up @@ -36,6 +40,16 @@ public interface IRecipeCategory<T extends IRecipeWrapper> {
*/
IDrawable getBackground();

/**
* Optional icon for the category tab.
* If no icon is defined here, JEI will use first item registered with {@link IModRegistry#addRecipeCategoryCraftingItem(ItemStack, String...)}
*
* @return icon to draw on the category tab, max size is 16x16 pixels.
* @since 3.13.1
*/
@Nullable
IDrawable getIcon();

/**
* Draw any extra elements that might be necessary, icons or extra slots.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/config/JEIModConfigGui.java
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import mezz.jei.gui.RecipesGui;
import mezz.jei.gui.recipes.RecipesGui;
import mezz.jei.util.Translator;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/mezz/jei/gui/GuiHelper.java
Expand Up @@ -8,18 +8,26 @@
import mezz.jei.api.gui.IDrawableStatic;
import mezz.jei.api.gui.ITickTimer;
import mezz.jei.api.recipe.IStackHelper;
import mezz.jei.config.Constants;
import mezz.jei.util.Log;
import mezz.jei.util.TickTimer;
import net.minecraft.util.ResourceLocation;

public class GuiHelper implements IGuiHelper {
private final IStackHelper stackHelper;
private final IDrawableStatic slotDrawable;
private final IDrawableStatic tabSelected;
private final IDrawableStatic tabUnselected;

public GuiHelper(IStackHelper stackHelper) {
this.stackHelper = stackHelper;

ResourceLocation location = new ResourceLocation("minecraft", "textures/gui/container/furnace.png");
this.slotDrawable = createDrawable(location, 55, 16, 18, 18);

ResourceLocation recipeBackgroundResource = new ResourceLocation(Constants.RESOURCE_DOMAIN, Constants.TEXTURE_RECIPE_BACKGROUND_PATH);
tabSelected = createDrawable(recipeBackgroundResource, 196, 15, 24, 24);
tabUnselected = createDrawable(recipeBackgroundResource, 220, 15, 24, 22);
}

@Override
Expand Down Expand Up @@ -92,4 +100,12 @@ public ICraftingGridHelper createCraftingGridHelper(int craftInputSlot1, int cra
public ITickTimer createTickTimer(int ticksPerCycle, int maxValue, boolean countDown) {
return new TickTimer(ticksPerCycle, maxValue, countDown);
}

public IDrawableStatic getTabSelected() {
return tabSelected;
}

public IDrawableStatic getTabUnselected() {
return tabUnselected;
}
}
1 change: 1 addition & 0 deletions src/main/java/mezz/jei/gui/GuiProperties.java
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nullable;

import mezz.jei.gui.recipes.RecipesGui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;

Expand Down
Expand Up @@ -13,6 +13,7 @@
import mezz.jei.config.Constants;
import mezz.jei.gui.ingredients.GuiIngredient;
import mezz.jei.gui.ingredients.GuiItemStackGroup;
import mezz.jei.gui.recipes.RecipesGui;
import mezz.jei.input.IClickedIngredient;
import mezz.jei.input.IShowsRecipeFocuses;
import net.minecraft.client.Minecraft;
Expand All @@ -23,7 +24,7 @@
/**
* The area drawn on left side of the {@link RecipesGui} that shows which items can craft the current recipe category.
*/
public class RecipeCategoryCraftingItemsArea implements IShowsRecipeFocuses {
public class RecipeCategoryCraftingItems implements IShowsRecipeFocuses {
private final IRecipeRegistry recipeRegistry;
private final IDrawable topDrawable;
private final IDrawable middleDrawable;
Expand All @@ -33,17 +34,17 @@ public class RecipeCategoryCraftingItemsArea implements IShowsRecipeFocuses {
private int left = 0;
private int top = 0;

public RecipeCategoryCraftingItemsArea(IRecipeRegistry recipeRegistry) {
public RecipeCategoryCraftingItems(IRecipeRegistry recipeRegistry) {
this.recipeRegistry = recipeRegistry;
IFocus<ItemStack> focus = recipeRegistry.createFocus(IFocus.Mode.NONE, null);
craftingItems = new GuiItemStackGroup(focus);

ResourceLocation recipeBackgroundResource = new ResourceLocation(Constants.RESOURCE_DOMAIN, Constants.TEXTURE_RECIPE_BACKGROUND_PATH);

IGuiHelper guiHelper = Internal.getHelpers().getGuiHelper();
topDrawable = guiHelper.createDrawable(recipeBackgroundResource, 196, 65, 25, 6);
middleDrawable = guiHelper.createDrawable(recipeBackgroundResource, 196, 71, 25, 16);
bottomDrawable = guiHelper.createDrawable(recipeBackgroundResource, 196, 87, 55, 6);
topDrawable = guiHelper.createDrawable(recipeBackgroundResource, 196, 65, 26, 6);
middleDrawable = guiHelper.createDrawable(recipeBackgroundResource, 196, 71, 26, 16);
bottomDrawable = guiHelper.createDrawable(recipeBackgroundResource, 196, 87, 26, 6);
}

public void updateLayout(List<ItemStack> itemStacks, GuiProperties guiProperties) {
Expand All @@ -64,8 +65,8 @@ public void updateLayout(List<ItemStack> itemStacks, GuiProperties guiProperties
}
}

top = guiProperties.getGuiTop() + (guiProperties.getGuiYSize() - totalHeight) / 2; // center it
left = guiProperties.getGuiLeft() + - middleDrawable.getWidth() + 3; // overlaps the recipe gui slightly
top = guiProperties.getGuiTop();
left = guiProperties.getGuiLeft() - topDrawable.getWidth() + 4; // overlaps the recipe gui slightly

ListMultimap<Integer, ItemStack> itemStacksForSlots = ArrayListMultimap.create();
for (int i = 0; i < itemStacks.size(); i++) {
Expand Down
@@ -1,49 +1,55 @@
package mezz.jei.gui;

import javax.annotation.Nullable;
import java.util.List;

import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.item.ItemStack;

public interface IRecipeGuiLogic {

String getPageString();

void setRecipesPerPage(int recipesPerPage);

boolean hasMultipleCategories();

boolean hasAllCategories();

void previousRecipeCategory();

void nextRecipeCategory();

boolean hasMultiplePages();

void previousPage();

void nextPage();

boolean setFocus(IFocus focus);

@Nullable
IFocus getFocus();

boolean back();

void clearHistory();

boolean setCategoryFocus();

boolean setCategoryFocus(List<String> recipeCategoryUids);

@Nullable
IRecipeCategory getRecipeCategory();

List<ItemStack> getRecipeCategoryCraftingItems();

List<RecipeLayout> getRecipeWidgets(int posX, int posY, int spacingY);
}
package mezz.jei.gui.recipes;

import javax.annotation.Nullable;
import java.util.List;

import com.google.common.collect.ImmutableList;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.item.ItemStack;

public interface IRecipeGuiLogic {

String getPageString();

void setRecipesPerPage(int recipesPerPage);

boolean hasMultipleCategories();

boolean hasAllCategories();

void previousRecipeCategory();

void nextRecipeCategory();

void setRecipeCategory(IRecipeCategory category);

boolean hasMultiplePages();

void previousPage();

void nextPage();

<V> boolean setFocus(IFocus<V> focus);

IFocus getFocus();

boolean back();

void clearHistory();

boolean setCategoryFocus();

boolean setCategoryFocus(List<String> recipeCategoryUids);

@Nullable
IRecipeCategory getSelectedRecipeCategory();

ImmutableList<IRecipeCategory> getRecipeCategories();

List<ItemStack> getRecipeCategoryCraftingItems();

List<ItemStack> getRecipeCategoryCraftingItems(IRecipeCategory recipeCategory);

List<RecipeLayout> getRecipeWidgets(int posX, int posY, int spacingY);
}
@@ -0,0 +1,5 @@
package mezz.jei.gui.recipes;

public interface IRecipeLogicStateListener {
void onStateChange();
}
52 changes: 52 additions & 0 deletions src/main/java/mezz/jei/gui/recipes/RecipeArrowTab.java
@@ -0,0 +1,52 @@
package mezz.jei.gui.recipes;

import javax.annotation.Nullable;

import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;

public class RecipeArrowTab extends RecipeGuiTab {
private final RecipeGuiTabs recipeGuiTabs;
private final boolean next;

public RecipeArrowTab(RecipeGuiTabs recipeGuiTabs, boolean next, int x, int y) {
super(x, y);
this.recipeGuiTabs = recipeGuiTabs;
this.next = next;
}

@Override
public void draw(Minecraft minecraft, boolean selected, int mouseX, int mouseY) {
super.draw(minecraft, selected, mouseX, mouseY);
String arrow = next ? ">" : "<";
FontRenderer fontRenderer = minecraft.fontRendererObj;
float textCenterX = x + (TAB_WIDTH / 2f);
float textCenterY = y + (TAB_HEIGHT / 2f) - 3;
int color = isMouseOver(mouseX, mouseY) ? 16777120 : 14737632;
fontRenderer.drawStringWithShadow(arrow, textCenterX - fontRenderer.getStringWidth(arrow) / 2f, textCenterY, color);
GlStateManager.color(1, 1, 1, 1);
}

@Override
public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) {
if (next) {
recipeGuiTabs.nextPage();
} else {
recipeGuiTabs.prevPage();
}
return true;
}

@Override
public boolean isSelected(IRecipeCategory selectedCategory) {
return false;
}

@Nullable
@Override
public String getTooltip() {
return null;
}
}

0 comments on commit 7593f01

Please sign in to comment.