Skip to content

Commit

Permalink
1.0.7 - Enhancements, Bug fixes
Browse files Browse the repository at this point in the history
-Made elements resizable on single axis.
-Added new cursors.
-Improved Item Subsets: sorting alphabetically by mod name, configurable
dropdown size and adding mod name to search field when right clicked.
Closes #7.
-Fixed keys not working over items list.
-Ctrl+P for ConTRoL Profiles. Closes #8.
-Updated method accesses to excore 1.5.3.
-Updated JEI.
  • Loading branch information
Elix-x committed May 4, 2016
1 parent 149cc0a commit 4d940b1
Show file tree
Hide file tree
Showing 33 changed files with 394 additions and 107 deletions.
60 changes: 57 additions & 3 deletions 1.9/src/api/java/mezz/jei/RecipeRegistry.java
Expand Up @@ -5,6 +5,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap;
Expand All @@ -28,6 +29,8 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand All @@ -37,13 +40,22 @@ public class RecipeRegistry implements IRecipeRegistry {
private final ImmutableMap<Class, IRecipeHandler> recipeHandlers;
private final ImmutableTable<Class, String, IRecipeTransferHandler> recipeTransferHandlers;
private final ImmutableMultimap<Class<? extends GuiContainer>, RecipeClickableArea> recipeClickableAreasMap;
private final ImmutableMultimap<IRecipeCategory, ItemStack> craftItemsForCategories;
private final ImmutableMultimap<String, String> categoriesForCraftItemKeys;
private final ImmutableMap<String, IRecipeCategory> recipeCategoriesMap;
private final ListMultimap<IRecipeCategory, Object> recipesForCategories;
private final RecipeMap recipeInputMap;
private final RecipeMap recipeOutputMap;
private final Set<Class> unhandledRecipeClasses;

public RecipeRegistry(@Nonnull List<IRecipeCategory> recipeCategories, @Nonnull List<IRecipeHandler> recipeHandlers, @Nonnull List<IRecipeTransferHandler> recipeTransferHandlers, @Nonnull List<Object> recipes, @Nonnull Multimap<Class<? extends GuiContainer>, RecipeClickableArea> recipeClickableAreasMap) {
public RecipeRegistry(
@Nonnull List<IRecipeCategory> recipeCategories,
@Nonnull List<IRecipeHandler> recipeHandlers,
@Nonnull List<IRecipeTransferHandler> recipeTransferHandlers,
@Nonnull List<Object> recipes,
@Nonnull Multimap<Class<? extends GuiContainer>, RecipeClickableArea> recipeClickableAreasMap,
@Nonnull Multimap<String, ItemStack> craftItemsForCategories
) {
this.recipeCategoriesMap = buildRecipeCategoriesMap(recipeCategories);
this.recipeTransferHandlers = buildRecipeTransferHandlerTable(recipeTransferHandlers);
this.recipeHandlers = buildRecipeHandlersMap(recipeHandlers);
Expand All @@ -57,6 +69,24 @@ public RecipeRegistry(@Nonnull List<IRecipeCategory> recipeCategories, @Nonnull

this.recipesForCategories = ArrayListMultimap.create();
addRecipes(recipes);

StackHelper stackHelper = Internal.getStackHelper();

ImmutableMultimap.Builder<IRecipeCategory, ItemStack> craftItemsForCategoriesBuilder = ImmutableMultimap.builder();
ImmutableMultimap.Builder<String, String> categoriesForCraftItemKeysBuilder = ImmutableMultimap.builder();
for (String recipeCategoryUid : craftItemsForCategories.keySet()) {
IRecipeCategory recipeCategory = recipeCategoriesMap.get(recipeCategoryUid);
Collection<ItemStack> craftItems = craftItemsForCategories.get(recipeCategoryUid);
craftItemsForCategoriesBuilder.putAll(recipeCategory, craftItems);
for (ItemStack craftItem : craftItems) {
recipeInputMap.addRecipeCategory(recipeCategory, craftItem);
String craftItemKey = stackHelper.getUniqueIdentifierForStack(craftItem);
categoriesForCraftItemKeysBuilder.put(craftItemKey, recipeCategoryUid);
}
}

this.craftItemsForCategories = craftItemsForCategoriesBuilder.build();
this.categoriesForCraftItemKeys = categoriesForCraftItemKeysBuilder.build();
}

private static ImmutableMap<String, IRecipeCategory> buildRecipeCategoriesMap(@Nonnull List<IRecipeCategory> recipeCategories) {
Expand Down Expand Up @@ -272,15 +302,33 @@ public ImmutableList<IRecipeCategory> getRecipeCategoriesWithOutput(@Nullable Fl

@Nonnull
@Override
public ImmutableList<Object> getRecipesWithInput(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack input) {
public List<Object> getRecipesWithInput(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack input) {
if (recipeCategory == null) {
Log.error("Null recipeCategory", new NullPointerException());
return ImmutableList.of();
} else if (input == null) {
Log.error("Null ItemStack input", new NullPointerException());
return ImmutableList.of();
}
return recipeInputMap.getRecipes(recipeCategory, input);

ImmutableList<Object> recipes = recipeInputMap.getRecipes(recipeCategory, input);

String recipeCategoryUid = recipeCategory.getUid();
for (String inputKey : Internal.getStackHelper().getUniqueIdentifiersWithWildcard(input)) {
if (categoriesForCraftItemKeys.get(inputKey).contains(recipeCategoryUid)) {
ImmutableSet<Object> specificRecipes = ImmutableSet.copyOf(recipes);
List<Object> recipesForCategory = recipesForCategories.get(recipeCategory);
List<Object> allRecipes = new ArrayList<>(recipes);
for (Object recipe : recipesForCategory) {
if (!specificRecipes.contains(recipe)) {
allRecipes.add(recipe);
}
}
return allRecipes;
}
}

return recipes;
}

@Nonnull
Expand Down Expand Up @@ -331,6 +379,12 @@ public List<Object> getRecipes(@Nullable IRecipeCategory recipeCategory) {
return Collections.unmodifiableList(recipesForCategories.get(recipeCategory));
}

@Nonnull
@Override
public ImmutableCollection<ItemStack> getCraftingItems(@Nonnull IRecipeCategory recipeCategory) {
return craftItemsForCategories.get(recipeCategory);
}

@Nullable
public IRecipeTransferHandler getRecipeTransferHandler(@Nullable Container container, @Nullable IRecipeCategory recipeCategory) {
if (container == null) {
Expand Down
11 changes: 11 additions & 0 deletions 1.9/src/api/java/mezz/jei/api/IModRegistry.java
Expand Up @@ -58,6 +58,17 @@ public interface IModRegistry {
*/
void addRecipeClickArea(@Nonnull Class<? extends GuiContainer> guiContainerClass, int xPos, int yPos, int width, int height, @Nonnull String... recipeCategoryUids);

/**
* Add an association between an item and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
* Allows players to see what item they need to craft in order to make recipes in that recipe category.
*
* @param craftingItem the item that can craft recipes (like a furnace or crafting table item)
* @param recipeCategoryUids the recipe categories handled by the item
*
* @since JEI 3.3.0
*/
void addRecipeCategoryCraftingItem(@Nonnull ItemStack craftingItem, @Nonnull String... recipeCategoryUids);

/**
* Add a handler to give JEI extra information about how to layout the item list next to a specific type of GuiContainer.
* Used for guis with tabs on the side that would normally intersect with JEI's item list.
Expand Down
22 changes: 15 additions & 7 deletions 1.9/src/api/java/mezz/jei/api/IRecipeRegistry.java
@@ -1,15 +1,14 @@
package mezz.jei.api;

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

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

import net.minecraftforge.fluids.Fluid;

import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;

/**
* The IRecipeManager offers several functions for retrieving and handling recipes.
Expand Down Expand Up @@ -66,6 +65,15 @@ public interface IRecipeRegistry {
@Nonnull
List<Object> getRecipes(@Nonnull IRecipeCategory recipeCategory);

/**
* Returns an unmodifiable collection of ItemStacks that can craft recipes from recipeCategory.
* These are registered with {@link IModRegistry#addRecipeCategoryCraftingItem(ItemStack, String...)}.
*
* @since JEI 3.3.0
*/
@Nonnull
Collection<ItemStack> getCraftingItems(@Nonnull IRecipeCategory recipeCategory);

/**
* Add a new recipe while the game is running.
* This is only for things like gated recipes becoming available, like the ones in Thaumcraft.
Expand Down
17 changes: 17 additions & 0 deletions 1.9/src/api/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
5 changes: 5 additions & 0 deletions 1.9/src/api/java/mezz/jei/gui/IRecipeGuiLogic.java
@@ -1,9 +1,11 @@
package mezz.jei.gui;

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

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

public interface IRecipeGuiLogic {
Expand Down Expand Up @@ -43,6 +45,9 @@ public interface IRecipeGuiLogic {
@Nullable
IRecipeCategory getRecipeCategory();

@Nonnull
Collection<ItemStack> getRecipeCategoryCraftingItems();

@Nonnull
List<RecipeLayout> getRecipeWidgets(int posX, int posY, int spacingY);
}
22 changes: 21 additions & 1 deletion 1.9/src/api/java/mezz/jei/gui/RecipeGuiLogic.java
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableList;
import mezz.jei.Internal;
import mezz.jei.RecipeRegistry;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.IRecipeRegistry;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeHandler;
Expand All @@ -11,10 +12,12 @@
import mezz.jei.util.MathUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;

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 java.util.Stack;
Expand Down Expand Up @@ -50,6 +53,14 @@ public State(@Nonnull Focus focus, @Nonnull List<IRecipeCategory> recipeCategori
@Nonnull
private List<Object> recipes = Collections.emptyList();

/**
* List of items that can craft recipes from the current recipe category
*
* @see IModRegistry#addRecipeCategoryCraftingItem(ItemStack, String...)
*/
@Nonnull
private Collection<ItemStack> recipeCategoryCraftingItems = Collections.emptyList();

private int recipesPerPage = 0;

@Override
Expand Down Expand Up @@ -161,6 +172,12 @@ public Focus getFocus() {
return state.focus;
}

@Override
@Nonnull
public Collection<ItemStack> getRecipeCategoryCraftingItems() {
return recipeCategoryCraftingItems;
}

@Override
public void setRecipesPerPage(int recipesPerPage) {
if (state == null) {
Expand All @@ -183,8 +200,11 @@ private void updateRecipes() {
final IRecipeCategory recipeCategory = getRecipeCategory();
if (recipeCategory == null) {
recipes = Collections.emptyList();
recipeCategoryCraftingItems = Collections.emptyList();
} else {
recipes = state.focus.getRecipes(recipeCategory);
Focus focus = state.focus;
recipes = focus.getRecipes(recipeCategory);
recipeCategoryCraftingItems = focus.getRecipeCategoryCraftingItems(recipeCategory);
}
}

Expand Down

0 comments on commit 4d940b1

Please sign in to comment.