Skip to content

Commit

Permalink
Add IStackHelper to API
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Jan 15, 2016
1 parent 8c830f1 commit 09ca045
Show file tree
Hide file tree
Showing 23 changed files with 497 additions and 59 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Expand Up @@ -2,5 +2,5 @@ mcversion=1.8.9
forgeversion=11.15.0.1697

version_major=2
version_minor=17
version_patch=4
version_minor=18
version_patch=0
6 changes: 6 additions & 0 deletions src/main/java/mezz/jei/Internal.java
@@ -1,5 +1,7 @@
package mezz.jei;

import mezz.jei.util.StackHelper;

/** For JEI internal use only, these are normally accessed from the API. */
public class Internal {
private static JeiHelpers helpers;
Expand All @@ -14,6 +16,10 @@ public static JeiHelpers getHelpers() {
return helpers;
}

public static StackHelper getStackHelper() {
return helpers.getStackHelper();
}

public static void setHelpers(JeiHelpers helpers) {
Internal.helpers = helpers;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/mezz/jei/ItemBlacklist.java
Expand Up @@ -11,7 +11,6 @@
import mezz.jei.api.IItemBlacklist;
import mezz.jei.config.Config;
import mezz.jei.util.Log;
import mezz.jei.util.StackUtil;

public class ItemBlacklist implements IItemBlacklist {
@Nonnull
Expand All @@ -23,7 +22,7 @@ public void addItemToBlacklist(@Nullable ItemStack itemStack) {
Log.error("Null itemStack", new NullPointerException());
return;
}
String uid = StackUtil.getUniqueIdentifierForStack(itemStack);
String uid = Internal.getStackHelper().getUniqueIdentifierForStack(itemStack);
itemBlacklist.add(uid);

JustEnoughItems.getProxy().resetItemFilter();
Expand All @@ -35,7 +34,7 @@ public void removeItemFromBlacklist(@Nullable ItemStack itemStack) {
Log.error("Null itemStack", new NullPointerException());
return;
}
String uid = StackUtil.getUniqueIdentifierForStack(itemStack);
String uid = Internal.getStackHelper().getUniqueIdentifierForStack(itemStack);
itemBlacklist.remove(uid);

JustEnoughItems.getProxy().resetItemFilter();
Expand All @@ -47,7 +46,7 @@ public boolean isItemBlacklisted(@Nullable ItemStack itemStack) {
Log.error("Null itemStack", new NullPointerException());
return false;
}
List<String> uids = StackUtil.getUniqueIdentifiersWithWildcard(itemStack);
List<String> uids = Internal.getStackHelper().getUniqueIdentifiersWithWildcard(itemStack);
for (String uid : uids) {
if (itemBlacklist.contains(uid) || Config.getItemBlacklist().contains(uid)) {
return true;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/mezz/jei/ItemRegistry.java
Expand Up @@ -22,12 +22,10 @@
import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.common.registry.GameData;
import net.minecraftforge.oredict.OreDictionary;

import mezz.jei.api.IItemRegistry;
import mezz.jei.util.Log;
import mezz.jei.util.ModList;
import mezz.jei.util.StackUtil;

public class ItemRegistry implements IItemRegistry {

Expand Down Expand Up @@ -136,7 +134,7 @@ private void addItemAndSubItems(@Nullable Item item, @Nonnull List<ItemStack> it
return;
}

List<ItemStack> items = StackUtil.getSubtypes(item, 1);
List<ItemStack> items = Internal.getStackHelper().getSubtypes(item, 1);
addItemStacks(items, itemList, fuels);
}

Expand Down Expand Up @@ -177,7 +175,7 @@ private void addItemStacks(@Nonnull Iterable<ItemStack> stacks, @Nonnull List<It

private void addItemStack(@Nonnull ItemStack stack, @Nonnull List<ItemStack> itemList, @Nonnull List<ItemStack> fuels) {
try {
String itemKey = StackUtil.getUniqueIdentifierForStack(stack);
String itemKey = Internal.getStackHelper().getUniqueIdentifierForStack(stack);

if (itemNameSet.contains(itemKey)) {
return;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/mezz/jei/JeiHelpers.java
Expand Up @@ -5,15 +5,18 @@
import mezz.jei.api.IJeiHelpers;
import mezz.jei.gui.GuiHelper;
import mezz.jei.transfer.RecipeTransferHandlerHelper;
import mezz.jei.util.StackHelper;

public class JeiHelpers implements IJeiHelpers {
private final GuiHelper guiHelper;
private final StackHelper stackHelper;
private final ItemBlacklist itemBlacklist;
private final NbtIgnoreList nbtIgnoreList;
private final RecipeTransferHandlerHelper recipeTransferHandlerHelper;

public JeiHelpers() {
this.guiHelper = new GuiHelper();
this.stackHelper = new StackHelper();
this.itemBlacklist = new ItemBlacklist();
this.nbtIgnoreList = new NbtIgnoreList();
this.recipeTransferHandlerHelper = new RecipeTransferHandlerHelper();
Expand All @@ -25,6 +28,12 @@ public GuiHelper getGuiHelper() {
return guiHelper;
}

@Nonnull
@Override
public StackHelper getStackHelper() {
return stackHelper;
}

@Nonnull
@Override
public ItemBlacklist getItemBlacklist() {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/mezz/jei/RecipeRegistry.java
Expand Up @@ -32,7 +32,6 @@
import mezz.jei.util.Log;
import mezz.jei.util.RecipeCategoryComparator;
import mezz.jei.util.RecipeMap;
import mezz.jei.util.StackUtil;

public class RecipeRegistry implements IRecipeRegistry {
private final ImmutableMap<Class, IRecipeHandler> recipeHandlers;
Expand Down Expand Up @@ -203,7 +202,7 @@ private void addRecipeUnchecked(@Nonnull Object recipe, IRecipeCategory recipeCa
List inputs = recipeWrapper.getInputs();
List<FluidStack> fluidInputs = recipeWrapper.getFluidInputs();
if (inputs != null || fluidInputs != null) {
List<ItemStack> inputStacks = StackUtil.toItemStackList(inputs);
List<ItemStack> inputStacks = Internal.getStackHelper().toItemStackList(inputs);
if (fluidInputs == null) {
fluidInputs = Collections.emptyList();
}
Expand All @@ -213,7 +212,7 @@ private void addRecipeUnchecked(@Nonnull Object recipe, IRecipeCategory recipeCa
List outputs = recipeWrapper.getOutputs();
List<FluidStack> fluidOutputs = recipeWrapper.getFluidOutputs();
if (outputs != null || fluidOutputs != null) {
List<ItemStack> outputStacks = StackUtil.toItemStackList(outputs);
List<ItemStack> outputStacks = Internal.getStackHelper().toItemStackList(outputs);
if (fluidOutputs == null) {
fluidOutputs = Collections.emptyList();
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mezz/jei/api/IJeiHelpers.java
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nonnull;

import mezz.jei.api.recipe.IStackHelper;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper;

/**
Expand All @@ -15,6 +16,12 @@ public interface IJeiHelpers {
@Nonnull
IGuiHelper getGuiHelper();

/**
* Helps with getting itemStacks from recipes.
*/
@Nonnull
IStackHelper getStackHelper();

/**
* Used to stop JEI from displaying a specific item in the item list.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/mezz/jei/api/gui/IGuiItemStackGroup.java
Expand Up @@ -29,6 +29,11 @@ public interface IGuiItemStackGroup extends IGuiIngredientGroup<ItemStack> {
*/
void setFromRecipe(int slotIndex, @Nonnull List ingredients);

/**
* Takes an Object from IRecipeWrapper getInputs or getOutputs
*/
void setFromRecipe(int slotIndex, @Nonnull Object ingredients);

@Override
void set(int slotIndex, @Nonnull Collection<ItemStack> itemStacks);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/api/package-info.java
@@ -1,4 +1,4 @@
@API(apiVersion = "2.4.0", owner = "JEI", provides = "JustEnoughItemsAPI")
@API(apiVersion = "2.5.0", owner = "JEI", provides = "JustEnoughItemsAPI")
package mezz.jei.api;

import net.minecraftforge.fml.common.API;
31 changes: 31 additions & 0 deletions src/main/java/mezz/jei/api/recipe/IStackHelper.java
@@ -0,0 +1,31 @@
package mezz.jei.api.recipe;

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

import net.minecraft.item.ItemStack;

/**
* Helps get ItemStacks from common formats used in recipes.
*/
public interface IStackHelper {
/**
* Returns all the subtypes of itemStack if it has a wildcard meta value.
*/
@Nonnull
List<ItemStack> getSubtypes(@Nonnull ItemStack itemStack);

/**
* Expands an Iterable, which may contain ItemStacks or more Iterables, and
* returns all the subtypes of itemStacks if they have wildcard meta value.
*/
@Nonnull
List<ItemStack> getAllSubtypes(Iterable stacks);

/**
* Flattens ItemStacks, OreDict Strings, and Iterables into a list of ItemStacks.
*/
@Nonnull
List<ItemStack> toItemStackList(@Nullable Object stacks);
}
8 changes: 4 additions & 4 deletions src/main/java/mezz/jei/config/Config.java
Expand Up @@ -10,7 +10,7 @@
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import mezz.jei.util.StackUtil;
import mezz.jei.Internal;

public class Config {
public static final String CATEGORY_MODE = "mode";
Expand Down Expand Up @@ -166,7 +166,7 @@ public static void addItemToConfigBlacklist(ItemStack itemStack, boolean wildcar
if (itemStack == null) {
return;
}
String uid = StackUtil.getUniqueIdentifierForStack(itemStack, wildcard);
String uid = Internal.getStackHelper().getUniqueIdentifierForStack(itemStack, wildcard);
if (itemBlacklist.add(uid)) {
updateBlacklist();
}
Expand All @@ -176,14 +176,14 @@ public static void removeItemFromConfigBlacklist(ItemStack itemStack, boolean wi
if (itemStack == null) {
return;
}
String uid = StackUtil.getUniqueIdentifierForStack(itemStack, wildcard);
String uid = Internal.getStackHelper().getUniqueIdentifierForStack(itemStack, wildcard);
if (itemBlacklist.remove(uid)) {
updateBlacklist();
}
}

public static boolean isItemOnConfigBlacklist(ItemStack itemStack, boolean wildcard) {
String uid = StackUtil.getUniqueIdentifierForStack(itemStack, wildcard);
String uid = Internal.getStackHelper().getUniqueIdentifierForStack(itemStack, wildcard);
return itemBlacklist.contains(uid);
}
}
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/gui/CraftingGridHelper.java
Expand Up @@ -6,9 +6,9 @@

import net.minecraft.item.ItemStack;

import mezz.jei.Internal;
import mezz.jei.api.gui.ICraftingGridHelper;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.util.StackUtil;

public class CraftingGridHelper implements ICraftingGridHelper {

Expand Down Expand Up @@ -40,7 +40,7 @@ public void setInput(@Nonnull IGuiItemStackGroup guiItemStacks, @Nonnull List in
Object recipeItem = input.get(i);
int index = getCraftingIndex(i, width, height);

List<ItemStack> itemStacks = StackUtil.toItemStackList(recipeItem);
List<ItemStack> itemStacks = Internal.getStackHelper().toItemStackList(recipeItem);
setInput(guiItemStacks, index, itemStacks);
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/mezz/jei/gui/ingredients/GuiItemStackGroup.java
Expand Up @@ -5,8 +5,8 @@

import net.minecraft.item.ItemStack;

import mezz.jei.Internal;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.util.StackUtil;

public class GuiItemStackGroup extends GuiIngredientGroup<ItemStack, GuiIngredient<ItemStack>> implements IGuiItemStackGroup {
private static final int baseWidth = 16;
Expand All @@ -28,7 +28,12 @@ private GuiIngredient<ItemStack> createGuiItemStack(int index, boolean input, in

@Override
public void setFromRecipe(int slotIndex, @Nonnull List ingredients) {
set(slotIndex, StackUtil.toItemStackList(ingredients));
set(slotIndex, Internal.getStackHelper().toItemStackList(ingredients));
}

@Override
public void setFromRecipe(int slotIndex, @Nonnull Object ingredients) {
set(slotIndex, Internal.getStackHelper().toItemStackList(ingredients));
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mezz/jei/gui/ingredients/ItemStackHelper.java
Expand Up @@ -5,17 +5,17 @@

import net.minecraft.item.ItemStack;

import mezz.jei.Internal;
import mezz.jei.gui.Focus;
import mezz.jei.util.StackUtil;

public class ItemStackHelper implements IIngredientHelper<ItemStack> {
@Override
public Collection<ItemStack> expandSubtypes(Collection<ItemStack> contained) {
return StackUtil.getAllSubtypes(contained);
return Internal.getStackHelper().getAllSubtypes(contained);
}

@Override
public ItemStack getMatch(Iterable<ItemStack> contained, @Nonnull Focus toMatch) {
return StackUtil.containsStack(contained, toMatch.getStack());
return Internal.getStackHelper().containsStack(contained, toMatch.getStack());
}
}
Expand Up @@ -7,9 +7,9 @@
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;

import mezz.jei.Internal;
import mezz.jei.network.IPacketId;
import mezz.jei.network.PacketIdServer;
import mezz.jei.util.StackUtil;

public class PacketDeletePlayerItem extends PacketJEI {
private ItemStack itemStack;
Expand All @@ -36,7 +36,7 @@ public void writePacketData(PacketBuffer buf) throws IOException {
public void readPacketData(PacketBuffer buf, EntityPlayer player) throws IOException {
itemStack = buf.readItemStackFromBuffer();
ItemStack playerItem = player.inventory.getItemStack();
if (StackUtil.isIdentical(itemStack, playerItem)) {
if (Internal.getStackHelper().isIdentical(itemStack, playerItem)) {
player.inventory.setItemStack(null);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/plugins/vanilla/VanillaPlugin.java
Expand Up @@ -72,8 +72,8 @@ public void register(IModRegistry registry) {
recipeTransferRegistry.addRecipeTransferHandler(ContainerBrewingStand.class, VanillaRecipeCategoryUid.BREWING, 0, 4, 4, 36);

registry.addRecipes(CraftingManager.getInstance().getRecipeList());
registry.addRecipes(SmeltingRecipeMaker.getFurnaceRecipes());
registry.addRecipes(FuelRecipeMaker.getFuelRecipes(itemRegistry, guiHelper));
registry.addRecipes(SmeltingRecipeMaker.getFurnaceRecipes(jeiHelpers));
registry.addRecipes(FuelRecipeMaker.getFuelRecipes(itemRegistry, jeiHelpers));
registry.addRecipes(BrewingRecipeMaker.getBrewingRecipes(itemRegistry));
}

Expand Down
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import mezz.jei.api.IGuiHelper;
Expand All @@ -16,7 +15,6 @@
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import mezz.jei.util.StackUtil;
import mezz.jei.util.Translator;

public class BrewingRecipeCategory implements IRecipeCategory {
Expand Down Expand Up @@ -96,15 +94,11 @@ public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapp

if (recipeWrapper instanceof BrewingRecipeWrapper) {
List inputs = recipeWrapper.getInputs();
List<ItemStack> inputStacks1 = StackUtil.toItemStackList(inputs.get(brewPotionSlot1));
List<ItemStack> inputStacks2 = StackUtil.toItemStackList(inputs.get(brewPotionSlot2));
List<ItemStack> inputStacks3 = StackUtil.toItemStackList(inputs.get(brewPotionSlot3));
List<ItemStack> ingredientStacks = StackUtil.toItemStackList(inputs.get(brewIngredientSlot));

itemStacks.setFromRecipe(brewPotionSlot1, inputStacks1);
itemStacks.setFromRecipe(brewPotionSlot2, inputStacks2);
itemStacks.setFromRecipe(brewPotionSlot3, inputStacks3);
itemStacks.setFromRecipe(brewIngredientSlot, ingredientStacks);

itemStacks.setFromRecipe(brewPotionSlot1, inputs.get(brewPotionSlot1));
itemStacks.setFromRecipe(brewPotionSlot2, inputs.get(brewPotionSlot2));
itemStacks.setFromRecipe(brewPotionSlot3, inputs.get(brewPotionSlot3));
itemStacks.setFromRecipe(brewIngredientSlot, inputs.get(brewIngredientSlot));
itemStacks.setFromRecipe(outputSlot, recipeWrapper.getOutputs());
}
}
Expand Down

0 comments on commit 09ca045

Please sign in to comment.