Skip to content

Commit

Permalink
Begin fluid support
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Nov 23, 2015
1 parent de2601e commit d0a5628
Show file tree
Hide file tree
Showing 43 changed files with 489 additions and 262 deletions.
9 changes: 1 addition & 8 deletions src/main/java/mezz/jei/ItemFilter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mezz.jei;

import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
Expand All @@ -9,7 +8,6 @@
import com.google.common.collect.ImmutableList;

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

Expand Down Expand Up @@ -46,12 +44,7 @@ public ImmutableList<ItemStackElement> load(@Nonnull final String filterText) th
ImmutableList<ItemStackElement> baseItemSet = filteredItemMapsCache.get(prevFilterText);

Collection<ItemStackElement> filteredItemList = Collections2.filter(baseItemSet,
new Predicate<ItemStackElement>() {
@Override
public boolean apply(@Nullable ItemStackElement input) {
return input != null && input.getLocalizedName().contains(filterText);
}
}
input -> input != null && input.getLocalizedName().contains(filterText)
);

return ImmutableList.copyOf(filteredItemList);
Expand Down
23 changes: 5 additions & 18 deletions src/main/java/mezz/jei/ItemRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
class ItemRegistry implements IItemRegistry {

@Nonnull
private final Set<Object> itemNameSet = new HashSet<Object>();
private final Set<Object> itemNameSet = new HashSet<>();
@Nonnull
private final ImmutableList<ItemStack> itemList;
@Nonnull
private final ImmutableList<ItemStack> fuels;

public ItemRegistry() {
List<ItemStack> itemList = new ArrayList<ItemStack>();
List<ItemStack> fuels = new ArrayList<ItemStack>();
List<ItemStack> itemList = new ArrayList<>();
List<ItemStack> fuels = new ArrayList<>();

for (Block block : GameData.getBlockRegistry().typeSafeIterable()) {
addBlockAndSubBlocks(block, itemList, fuels);
Expand Down Expand Up @@ -93,7 +93,7 @@ private void addBlockAndSubBlocks(@Nullable Block block, @Nonnull List<ItemStack
return;
}

List<ItemStack> subItems = new ArrayList<ItemStack>();
List<ItemStack> subItems = new ArrayList<>();
for (CreativeTabs itemTab : item.getCreativeTabs()) {
subItems.clear();
block.getSubBlocks(item, itemTab, subItems);
Expand Down Expand Up @@ -124,7 +124,7 @@ private void addItemStack(@Nonnull ItemStack stack, @Nonnull List<ItemStack> ite
return;
}

String itemKey = uniqueIdentifierForStack(stack);
String itemKey = StackUtil.uniqueIdentifierForStack(stack, false);

if (itemNameSet.contains(itemKey)) {
return;
Expand All @@ -137,17 +137,4 @@ private void addItemStack(@Nonnull ItemStack stack, @Nonnull List<ItemStack> ite
}
}

@Nonnull
private String uniqueIdentifierForStack(@Nonnull ItemStack stack) {
Item item = stack.getItem();
Object itemName = GameData.getItemRegistry().getNameForObject(item);

StringBuilder itemKey = new StringBuilder();
itemKey.append(itemName).append(':').append(stack.getItemDamage());
if (stack.hasTagCompound()) {
itemKey.append(':').append(stack.getTagCompound());
}
return itemKey.toString();
}

}
6 changes: 2 additions & 4 deletions src/main/java/mezz/jei/JustEnoughItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ public class JustEnoughItems implements IPluginRegistry {
public static JustEnoughItems instance;

@Nonnull
private final List<IModPlugin> plugins;
private boolean pluginsCanRegister;
private final List<IModPlugin> plugins = new ArrayList<>();
private boolean pluginsCanRegister = true;

public JustEnoughItems() {
plugins = new ArrayList<IModPlugin>();
JEIManager.guiHelper = new GuiHelper();
JEIManager.pluginRegistry = this;
this.pluginsCanRegister = true;
}

@Mod.EventHandler
Expand Down
79 changes: 63 additions & 16 deletions src/main/java/mezz/jei/RecipeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,39 @@

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

import net.minecraft.item.ItemStack;

import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

import mezz.jei.api.IRecipeRegistry;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
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;
private final ImmutableClassToInstanceMap<IRecipeCategory> recipeCategoriesMap;
private final ImmutableList<IRecipeCategory> recipeCategories;
private final RecipeMap recipeInputMap;
private final RecipeMap recipeOutputMap;

RecipeRegistry(@Nonnull ImmutableList<IRecipeCategory> recipeCategories, @Nonnull ImmutableList<IRecipeHandler> recipeHandlers, @Nonnull ImmutableList<Object> recipes) {
this.recipeCategories = ImmutableSet.copyOf(recipeCategories).asList(); //remove duplicates
this.recipeCategoriesMap = buildRecipeCategoriesMap(this.recipeCategories);
recipeCategories = ImmutableSet.copyOf(recipeCategories).asList(); //remove duplicates
this.recipeCategoriesMap = buildRecipeCategoriesMap(recipeCategories);
this.recipeHandlers = buildRecipeHandlersMap(recipeHandlers);

this.recipeInputMap = new RecipeMap(this);
this.recipeOutputMap = new RecipeMap(this);
RecipeCategoryComparator recipeCategoryComparator = new RecipeCategoryComparator(recipeCategories);
this.recipeInputMap = new RecipeMap(recipeCategoryComparator);
this.recipeOutputMap = new RecipeMap(recipeCategoryComparator);

addRecipes(recipes);
}

Expand Down Expand Up @@ -85,25 +91,34 @@ private void addRecipes(@Nullable ImmutableList<Object> recipes) {
Log.debug("Can't handle recipe: " + recipe);
continue;
}
Class<? extends IRecipeCategory> recipeCategoryClass = recipeHandler.getRecipeCategoryClass();
Class recipeCategoryClass = recipeHandler.getRecipeCategoryClass();
IRecipeCategory recipeCategory = recipeCategoriesMap.getInstance(recipeCategoryClass);
if (recipeCategory == null) {
Log.error("No recipe category registered for recipeCategoryClass: " + recipeCategoryClass);
continue;
}

@SuppressWarnings("unchecked")
IRecipeWrapper recipeWrapper = recipeHandler.getRecipeWrapper(recipe);

List inputs = recipeWrapper.getInputs();
if (inputs != null) {
List<FluidStack> fluidInputs = recipeWrapper.getFluidInputs();
if (inputs != null || fluidInputs != null) {
List<ItemStack> inputStacks = StackUtil.toItemStackList(inputs);
recipeInputMap.addRecipe(recipe, recipeCategory, inputStacks);
if (fluidInputs == null) {
fluidInputs = Collections.emptyList();
}
recipeInputMap.addRecipe(recipe, recipeCategory, inputStacks, fluidInputs);
}

List outputs = recipeWrapper.getOutputs();
if (outputs != null) {
List<FluidStack> fluidOutputs = recipeWrapper.getFluidOutputs();
if (outputs != null || fluidOutputs != null) {
List<ItemStack> outputStacks = StackUtil.toItemStackList(outputs);
recipeOutputMap.addRecipe(recipe, recipeCategory, outputStacks);
if (fluidOutputs == null) {
fluidOutputs = Collections.emptyList();
}
recipeOutputMap.addRecipe(recipe, recipeCategory, outputStacks, fluidOutputs);
}
}
}
Expand All @@ -121,7 +136,16 @@ public IRecipeHandler getRecipeHandler(@Nonnull Class recipeClass) {

@Nonnull
@Override
public ImmutableList<IRecipeCategory> getRecipeCategoriesForInput(@Nullable ItemStack input) {
public ImmutableList<IRecipeCategory> getRecipeCategoriesWithInput(@Nullable ItemStack input) {
if (input == null) {
return ImmutableList.of();
}
return recipeInputMap.getRecipeCategories(input);
}

@Nonnull
@Override
public ImmutableList<IRecipeCategory> getRecipeCategoriesWithInput(Fluid input) {
if (input == null) {
return ImmutableList.of();
}
Expand All @@ -130,7 +154,16 @@ public ImmutableList<IRecipeCategory> getRecipeCategoriesForInput(@Nullable Item

@Nonnull
@Override
public ImmutableList<IRecipeCategory> getRecipeCategoriesForOutput(@Nullable ItemStack output) {
public ImmutableList<IRecipeCategory> getRecipeCategoriesWithOutput(@Nullable ItemStack output) {
if (output == null) {
return ImmutableList.of();
}
return recipeOutputMap.getRecipeCategories(output);
}

@Nonnull
@Override
public ImmutableList<IRecipeCategory> getRecipeCategoriesWithOutput(Fluid output) {
if (output == null) {
return ImmutableList.of();
}
Expand All @@ -139,7 +172,16 @@ public ImmutableList<IRecipeCategory> getRecipeCategoriesForOutput(@Nullable Ite

@Nonnull
@Override
public ImmutableList<Object> getInputRecipes(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack input) {
public ImmutableList<Object> getRecipesWithInput(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack input) {
if (recipeCategory == null || input == null) {
return ImmutableList.of();
}
return recipeInputMap.getRecipes(recipeCategory, input);
}

@Nonnull
@Override
public ImmutableList<Object> getRecipesWithInput(@Nullable IRecipeCategory recipeCategory, @Nullable Fluid input) {
if (recipeCategory == null || input == null) {
return ImmutableList.of();
}
Expand All @@ -148,14 +190,19 @@ public ImmutableList<Object> getInputRecipes(@Nullable IRecipeCategory recipeCat

@Nonnull
@Override
public ImmutableList<Object> getOutputRecipes(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack output) {
public ImmutableList<Object> getRecipesWithOutput(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack output) {
if (recipeCategory == null || output == null) {
return ImmutableList.of();
}
return recipeOutputMap.getRecipes(recipeCategory, output);
}

public int getRecipeCategoryIndex(IRecipeCategory recipeCategory) {
return recipeCategories.indexOf(recipeCategory);
@Nonnull
@Override
public ImmutableList<Object> getRecipesWithOutput(@Nullable IRecipeCategory recipeCategory, @Nullable Fluid output) {
if (recipeCategory == null || output == null) {
return ImmutableList.of();
}
return recipeOutputMap.getRecipes(recipeCategory, output);
}
}
26 changes: 22 additions & 4 deletions src/main/java/mezz/jei/api/IRecipeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import net.minecraft.item.ItemStack;

import net.minecraftforge.fluids.Fluid;

import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeHandler;

Expand All @@ -23,18 +25,34 @@ public interface IRecipeRegistry {

/** Returns a list of Recipe Categories that have the ItemStack as an input */
@Nonnull
ImmutableList<IRecipeCategory> getRecipeCategoriesForInput(ItemStack input);
ImmutableList<IRecipeCategory> getRecipeCategoriesWithInput(ItemStack input);

/** Returns a list of Recipe Categories that have the Fluid as an input */
@Nonnull
ImmutableList<IRecipeCategory> getRecipeCategoriesWithInput(Fluid input);

/** Returns a list of Recipe Categories that have the ItemStack as an output */
@Nonnull
ImmutableList<IRecipeCategory> getRecipeCategoriesForOutput(ItemStack output);
ImmutableList<IRecipeCategory> getRecipeCategoriesWithOutput(ItemStack output);

/** Returns a list of Recipe Categories that have the Fluid as an output */
@Nonnull
ImmutableList<IRecipeCategory> getRecipeCategoriesWithOutput(Fluid output);

/** Returns a list of Recipes of recipeCategory that have the ItemStack as an input */
@Nonnull
ImmutableList<Object> getInputRecipes(IRecipeCategory recipeCategory, ItemStack input);
ImmutableList<Object> getRecipesWithInput(IRecipeCategory recipeCategory, ItemStack input);

/** Returns a list of Recipes of recipeCategory that have the Fluid as an input */
@Nonnull
ImmutableList<Object> getRecipesWithInput(IRecipeCategory recipeCategory, Fluid input);

/** Returns a list of Recipes of recipeCategory that have the ItemStack as an output */
@Nonnull
ImmutableList<Object> getOutputRecipes(IRecipeCategory recipeCategory, ItemStack output);
ImmutableList<Object> getRecipesWithOutput(IRecipeCategory recipeCategory, ItemStack output);

/** Returns a list of Recipes of recipeCategory that have the Fluid as an output */
@Nonnull
ImmutableList<Object> getRecipesWithOutput(IRecipeCategory recipeCategory, Fluid output);

}
23 changes: 23 additions & 0 deletions src/main/java/mezz/jei/api/gui/IGuiFluidTanks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package mezz.jei.api.gui;

import javax.annotation.Nonnull;

import net.minecraftforge.fluids.FluidStack;

/**
* IGuiFluidTanks displays FluidStack Tanks in a gui.
*
* If multiple FluidStacks are set, they will be displayed in rotation.
*/
public interface IGuiFluidTanks {

/**
* Fluid tanks must be initialized once, and then can be set many times.
*/
void init(int index, int xPosition, int yPosition, int capacityMb);

void set(int index, @Nonnull Iterable<FluidStack> fluidStacks);

void set(int index, @Nonnull FluidStack fluidStacks);

}
9 changes: 5 additions & 4 deletions src/main/java/mezz/jei/api/gui/IGuiItemStacks.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package mezz.jei.api.gui;

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

import net.minecraft.item.ItemStack;

/**
* IGuiItemStacks displays ItemStacks in a gui.
*
* Multiple ItemStacks will be displayed in rotation.
* If multiple ItemStacks are set, they will be displayed in rotation.
* ItemStacks with subtypes and wildcard metadata will be displayed as multiple ItemStacks.
*/
public interface IGuiItemStacks {

/**
* ItemStacks must be initialized once, and then can be set many times.
*/
void initItemStack(int index, int xPosition, int yPosition);
void init(int index, int xPosition, int yPosition);

void setItemStack(int index, @Nonnull Iterable<ItemStack> itemStacks);
void set(int index, @Nonnull Collection<ItemStack> itemStacks);

void setItemStack(int index, @Nonnull ItemStack itemStack);
void set(int index, @Nonnull ItemStack itemStack);

}
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/api/package-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@API(apiVersion = "21.1.0", owner = "JEI", provides = "JustEnoughItemsAPI")
@API(apiVersion = "22.0.0", owner = "JEI", provides = "JustEnoughItemsAPI")
package mezz.jei.api;

import net.minecraftforge.fml.common.API;
6 changes: 3 additions & 3 deletions src/main/java/mezz/jei/api/recipe/IRecipeCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public interface IRecipeCategory {
/**
* Initialize the IGuiItemStacks with this recipe's layout.
*/
public void init(@Nonnull IGuiItemStacks guiItemStacks);
void init(@Nonnull IGuiItemStacks guiItemStacks);

/**
* Set the IGuiItemStacks from the RecipeWrapper.
* Set the IGuiItemStacks and IGuiFluidTanks properties from the RecipeWrapper.
*/
public void setRecipe(@Nonnull IGuiItemStacks guiItemStacks, @Nonnull IRecipeWrapper recipeWrapper);
void setRecipe(@Nonnull IGuiItemStacks guiItemStacks, @Nonnull IRecipeWrapper recipeWrapper);

}
Loading

0 comments on commit d0a5628

Please sign in to comment.