Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Nov 27, 2015
2 parents 91aef0a + f1e4916 commit 7f75696
Show file tree
Hide file tree
Showing 37 changed files with 786 additions and 402 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -3,6 +3,6 @@ forgeversion=11.14.4.1576-1.8.8

version_major=2
version_minor=0
version_patch=4
version_patch=5

org.gradle.parallel=true
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/ItemRegistry.java
Expand Up @@ -69,7 +69,7 @@ public String getModNameForItem(@Nullable Item item) {
if (item == null) {
return "";
}
return modList.getModNameForItemStack(item);
return modList.getModNameForItem(item);
}

private void addItemAndSubItems(@Nullable Item item, @Nonnull List<ItemStack> itemList, @Nonnull List<ItemStack> fuels) {
Expand Down
89 changes: 47 additions & 42 deletions src/main/java/mezz/jei/RecipeRegistry.java
Expand Up @@ -64,9 +64,6 @@ private static ImmutableMap<Class, IRecipeHandler> buildRecipeHandlersMap(@Nonnu
}

Class recipeClass = recipeHandler.getRecipeClass();
if (recipeClass == null) {
continue;
}

if (mutableRecipeHandlers.containsKey(recipeClass)) {
throw new IllegalArgumentException("A Recipe Handler has already been registered for this recipe class: " + recipeClass.getName());
Expand All @@ -83,54 +80,62 @@ private void addRecipes(@Nullable ImmutableList<Object> recipes) {
}

for (Object recipe : recipes) {
if (recipe == null) {
continue;
try {
addRecipe(recipe);
} catch (RuntimeException e) {
Log.error("Failed to add recipe: {}\nWith error: {}", recipe, e);
}
}
}

Class recipeClass = recipe.getClass();
private void addRecipe(@Nullable Object recipe) {
if (recipe == null) {
return;
}

IRecipeHandler recipeHandler = getRecipeHandler(recipeClass);
if (recipeHandler == null) {
if (!unhandledRecipeClasses.contains(recipeClass)) {
unhandledRecipeClasses.add(recipeClass);
Log.debug("Can't handle recipe: {}", recipeClass);
}
continue;
}
Class recipeCategoryClass = recipeHandler.getRecipeCategoryClass();
IRecipeCategory recipeCategory = recipeCategoriesMap.getInstance(recipeCategoryClass);
if (recipeCategory == null) {
Log.error("No recipe category registered for recipeCategoryClass: {}", recipeCategoryClass);
continue;
Class recipeClass = recipe.getClass();
IRecipeHandler recipeHandler = getRecipeHandler(recipeClass);
if (recipeHandler == null) {
if (!unhandledRecipeClasses.contains(recipeClass)) {
unhandledRecipeClasses.add(recipeClass);
Log.debug("Can't handle recipe: {}", recipeClass);
}
return;
}

//noinspection unchecked
if (!recipeHandler.isRecipeValid(recipe)) {
continue;
}
Class recipeCategoryClass = recipeHandler.getRecipeCategoryClass();
IRecipeCategory recipeCategory = recipeCategoriesMap.getInstance(recipeCategoryClass);
if (recipeCategory == null) {
Log.error("No recipe category registered for recipeCategoryClass: {}", recipeCategoryClass);
return;
}

//noinspection unchecked
IRecipeWrapper recipeWrapper = recipeHandler.getRecipeWrapper(recipe);

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

//noinspection unchecked
IRecipeWrapper recipeWrapper = recipeHandler.getRecipeWrapper(recipe);

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

List outputs = recipeWrapper.getOutputs();
List<FluidStack> fluidOutputs = recipeWrapper.getFluidOutputs();
if (outputs != null || fluidOutputs != null) {
List<ItemStack> outputStacks = StackUtil.toItemStackList(outputs);
if (fluidOutputs == null) {
fluidOutputs = Collections.emptyList();
}
recipeOutputMap.addRecipe(recipe, recipeCategory, outputStacks, fluidOutputs);
List outputs = recipeWrapper.getOutputs();
List<FluidStack> fluidOutputs = recipeWrapper.getFluidOutputs();
if (outputs != null || fluidOutputs != null) {
List<ItemStack> outputStacks = StackUtil.toItemStackList(outputs);
if (fluidOutputs == null) {
fluidOutputs = Collections.emptyList();
}
recipeOutputMap.addRecipe(recipe, recipeCategory, outputStacks, fluidOutputs);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/mezz/jei/api/gui/IGuiFluidTanks.java
@@ -1,6 +1,7 @@
package mezz.jei.api.gui;

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

import net.minecraftforge.fluids.FluidStack;

Expand All @@ -14,10 +15,10 @@ 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 init(int index, int xPosition, int yPosition, int width, int height, int capacityMb);

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

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

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

import net.minecraftforge.fml.common.API;
9 changes: 5 additions & 4 deletions src/main/java/mezz/jei/api/recipe/IRecipeCategory.java
Expand Up @@ -3,6 +3,7 @@
import javax.annotation.Nonnull;

import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiFluidTanks;
import mezz.jei.api.gui.IGuiItemStacks;

/**
Expand All @@ -17,7 +18,7 @@ public interface IRecipeCategory {
* Called every frame, so make sure to store it in a field.
*/
@Nonnull
String getCategoryTitle();
String getTitle();

/**
* Returns the drawable background for a single recipe in this category.
Expand All @@ -27,13 +28,13 @@ public interface IRecipeCategory {
IDrawable getBackground();

/**
* Initialize the IGuiItemStacks with this recipe's layout.
* Initialize the IGuiItemStacks and IGuiFluidTanks with this recipe's layout.
*/
void init(@Nonnull IGuiItemStacks guiItemStacks);
void init(@Nonnull IGuiItemStacks guiItemStacks, @Nonnull IGuiFluidTanks guiFluidTanks);

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

}
3 changes: 3 additions & 0 deletions src/main/java/mezz/jei/api/recipe/IRecipeHandler.java
Expand Up @@ -8,12 +8,15 @@
public interface IRecipeHandler<T> {

/** Returns the class of the Recipe handled by this IRecipeHandler. */
@Nonnull
Class<T> getRecipeClass();

/** Returns the category of this recipe. */
@Nonnull
Class<? extends IRecipeCategory> getRecipeCategoryClass();

/** Returns a recipe wrapper for the given recipe. */
@Nonnull
IRecipeWrapper getRecipeWrapper(@Nonnull T recipe);

/** Returns true if a recipe is valid and can be used. */
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/mezz/jei/gui/Focus.java
@@ -0,0 +1,89 @@
package mezz.jei.gui;

import com.google.common.collect.ImmutableList;

import javax.annotation.Nonnull;

import net.minecraft.item.ItemStack;

import net.minecraftforge.fluids.Fluid;

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

public class Focus {
private final ItemStack stack;
private final Fluid fluid;

public Focus() {
this.stack = null;
this.fluid = null;
}

public Focus(Object focus) {
if (focus instanceof ItemStack) {
this.stack = (ItemStack) focus;
this.fluid = null;
} else if (focus instanceof Fluid) {
this.stack = null;
this.fluid = (Fluid) focus;
} else {
this.stack = null;
this.fluid = null;
}
}

public Focus(ItemStack stack) {
this.stack = stack;
this.fluid = null;
}

public Focus(Fluid fluid) {
this.stack = null;
this.fluid = fluid;
}

public Fluid getFluid() {
return fluid;
}

public ItemStack getStack() {
return stack;
}

@Nonnull
public ImmutableList<IRecipeCategory> getCategoriesWithInput() {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipeCategoriesWithInput(stack);
} else {
return JEIManager.recipeRegistry.getRecipeCategoriesWithInput(fluid);
}
}

@Nonnull
public ImmutableList<IRecipeCategory> getCategoriesWithOutput() {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipeCategoriesWithOutput(stack);
} else {
return JEIManager.recipeRegistry.getRecipeCategoriesWithOutput(fluid);
}
}

@Nonnull
public ImmutableList<Object> getRecipesWithInput(IRecipeCategory recipeCategory) {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipesWithInput(recipeCategory, stack);
} else {
return JEIManager.recipeRegistry.getRecipesWithInput(recipeCategory, fluid);
}
}

@Nonnull
public ImmutableList<Object> getRecipesWithOutput(IRecipeCategory recipeCategory) {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipesWithOutput(recipeCategory, stack);
} else {
return JEIManager.recipeRegistry.getRecipesWithOutput(recipeCategory, fluid);
}
}
}
51 changes: 50 additions & 1 deletion src/main/java/mezz/jei/gui/GuiFluidTank.java
@@ -1,4 +1,53 @@
package mezz.jei.gui;

public class GuiFluidTank {
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;

import net.minecraftforge.fluids.FluidStack;

public class GuiFluidTank extends GuiWidget<FluidStack> {
private final int capacityMb;

public GuiFluidTank(int xPosition, int yPosition, int width, int height, int capacityMb) {
super(xPosition, yPosition, width, height);
this.capacityMb = capacityMb;
}

@Override
protected Collection<FluidStack> expandSubtypes(Collection<FluidStack> contained) {
return contained;
}

@Override
protected FluidStack getMatch(Iterable<FluidStack> contained, @Nonnull Focus toMatch) {
if (toMatch.getFluid() == null) {
return null;
}
for (FluidStack fluidStack : contained) {
if (toMatch.getFluid() == fluidStack.getFluid()) {
return fluidStack;
}
}
return null;
}

@Override
protected void draw(@Nonnull Minecraft minecraft, int xPosition, int yPosition, @Nonnull FluidStack contents) {
// TODO
}

@Override
protected List getTooltip(@Nonnull Minecraft minecraft, @Nonnull FluidStack value) {
// TODO
return null;
}

@Override
protected FontRenderer getFontRenderer(@Nonnull Minecraft minecraft, @Nonnull FluidStack value) {
return minecraft.fontRendererObj;
}
}
13 changes: 13 additions & 0 deletions src/main/java/mezz/jei/gui/GuiFluidTanks.java
@@ -0,0 +1,13 @@
package mezz.jei.gui;

import net.minecraftforge.fluids.FluidStack;

import mezz.jei.api.gui.IGuiFluidTanks;

public class GuiFluidTanks extends GuiWidgets<FluidStack, GuiFluidTank> implements IGuiFluidTanks {
@Override
public void init(int index, int xPosition, int yPosition, int width, int height, int capacityMb) {
GuiFluidTank guiFluidTank = new GuiFluidTank(xPosition, yPosition, width, height, capacityMb);
guiWidgets.put(index, guiFluidTank);
}
}

0 comments on commit 7f75696

Please sign in to comment.