diff --git a/src/main/java/mezz/jei/ItemFilter.java b/src/main/java/mezz/jei/ItemFilter.java index d7b58e318..0742b14a2 100644 --- a/src/main/java/mezz/jei/ItemFilter.java +++ b/src/main/java/mezz/jei/ItemFilter.java @@ -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; @@ -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; @@ -46,12 +44,7 @@ public ImmutableList load(@Nonnull final String filterText) th ImmutableList baseItemSet = filteredItemMapsCache.get(prevFilterText); Collection filteredItemList = Collections2.filter(baseItemSet, - new Predicate() { - @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); diff --git a/src/main/java/mezz/jei/ItemRegistry.java b/src/main/java/mezz/jei/ItemRegistry.java index e3dd75681..3173f2050 100644 --- a/src/main/java/mezz/jei/ItemRegistry.java +++ b/src/main/java/mezz/jei/ItemRegistry.java @@ -27,15 +27,15 @@ class ItemRegistry implements IItemRegistry { @Nonnull - private final Set itemNameSet = new HashSet(); + private final Set itemNameSet = new HashSet<>(); @Nonnull private final ImmutableList itemList; @Nonnull private final ImmutableList fuels; public ItemRegistry() { - List itemList = new ArrayList(); - List fuels = new ArrayList(); + List itemList = new ArrayList<>(); + List fuels = new ArrayList<>(); for (Block block : GameData.getBlockRegistry().typeSafeIterable()) { addBlockAndSubBlocks(block, itemList, fuels); @@ -93,7 +93,7 @@ private void addBlockAndSubBlocks(@Nullable Block block, @Nonnull List subItems = new ArrayList(); + List subItems = new ArrayList<>(); for (CreativeTabs itemTab : item.getCreativeTabs()) { subItems.clear(); block.getSubBlocks(item, itemTab, subItems); @@ -124,7 +124,7 @@ private void addItemStack(@Nonnull ItemStack stack, @Nonnull List ite return; } - String itemKey = uniqueIdentifierForStack(stack); + String itemKey = StackUtil.uniqueIdentifierForStack(stack, false); if (itemNameSet.contains(itemKey)) { return; @@ -137,17 +137,4 @@ private void addItemStack(@Nonnull ItemStack stack, @Nonnull List 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(); - } - } diff --git a/src/main/java/mezz/jei/JustEnoughItems.java b/src/main/java/mezz/jei/JustEnoughItems.java index 61af6d863..752b11726 100644 --- a/src/main/java/mezz/jei/JustEnoughItems.java +++ b/src/main/java/mezz/jei/JustEnoughItems.java @@ -38,14 +38,12 @@ public class JustEnoughItems implements IPluginRegistry { public static JustEnoughItems instance; @Nonnull - private final List plugins; - private boolean pluginsCanRegister; + private final List plugins = new ArrayList<>(); + private boolean pluginsCanRegister = true; public JustEnoughItems() { - plugins = new ArrayList(); JEIManager.guiHelper = new GuiHelper(); JEIManager.pluginRegistry = this; - this.pluginsCanRegister = true; } @Mod.EventHandler diff --git a/src/main/java/mezz/jei/RecipeRegistry.java b/src/main/java/mezz/jei/RecipeRegistry.java index ea6d832f2..4eae3f3c5 100644 --- a/src/main/java/mezz/jei/RecipeRegistry.java +++ b/src/main/java/mezz/jei/RecipeRegistry.java @@ -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 recipeHandlers; private final ImmutableClassToInstanceMap recipeCategoriesMap; - private final ImmutableList recipeCategories; private final RecipeMap recipeInputMap; private final RecipeMap recipeOutputMap; RecipeRegistry(@Nonnull ImmutableList recipeCategories, @Nonnull ImmutableList recipeHandlers, @Nonnull ImmutableList 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); } @@ -85,25 +91,34 @@ private void addRecipes(@Nullable ImmutableList recipes) { Log.debug("Can't handle recipe: " + recipe); continue; } - Class 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 fluidInputs = recipeWrapper.getFluidInputs(); + if (inputs != null || fluidInputs != null) { List 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 fluidOutputs = recipeWrapper.getFluidOutputs(); + if (outputs != null || fluidOutputs != null) { List outputStacks = StackUtil.toItemStackList(outputs); - recipeOutputMap.addRecipe(recipe, recipeCategory, outputStacks); + if (fluidOutputs == null) { + fluidOutputs = Collections.emptyList(); + } + recipeOutputMap.addRecipe(recipe, recipeCategory, outputStacks, fluidOutputs); } } } @@ -121,7 +136,16 @@ public IRecipeHandler getRecipeHandler(@Nonnull Class recipeClass) { @Nonnull @Override - public ImmutableList getRecipeCategoriesForInput(@Nullable ItemStack input) { + public ImmutableList getRecipeCategoriesWithInput(@Nullable ItemStack input) { + if (input == null) { + return ImmutableList.of(); + } + return recipeInputMap.getRecipeCategories(input); + } + + @Nonnull + @Override + public ImmutableList getRecipeCategoriesWithInput(Fluid input) { if (input == null) { return ImmutableList.of(); } @@ -130,7 +154,16 @@ public ImmutableList getRecipeCategoriesForInput(@Nullable Item @Nonnull @Override - public ImmutableList getRecipeCategoriesForOutput(@Nullable ItemStack output) { + public ImmutableList getRecipeCategoriesWithOutput(@Nullable ItemStack output) { + if (output == null) { + return ImmutableList.of(); + } + return recipeOutputMap.getRecipeCategories(output); + } + + @Nonnull + @Override + public ImmutableList getRecipeCategoriesWithOutput(Fluid output) { if (output == null) { return ImmutableList.of(); } @@ -139,7 +172,16 @@ public ImmutableList getRecipeCategoriesForOutput(@Nullable Ite @Nonnull @Override - public ImmutableList getInputRecipes(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack input) { + public ImmutableList getRecipesWithInput(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack input) { + if (recipeCategory == null || input == null) { + return ImmutableList.of(); + } + return recipeInputMap.getRecipes(recipeCategory, input); + } + + @Nonnull + @Override + public ImmutableList getRecipesWithInput(@Nullable IRecipeCategory recipeCategory, @Nullable Fluid input) { if (recipeCategory == null || input == null) { return ImmutableList.of(); } @@ -148,14 +190,19 @@ public ImmutableList getInputRecipes(@Nullable IRecipeCategory recipeCat @Nonnull @Override - public ImmutableList getOutputRecipes(@Nullable IRecipeCategory recipeCategory, @Nullable ItemStack output) { + public ImmutableList 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 getRecipesWithOutput(@Nullable IRecipeCategory recipeCategory, @Nullable Fluid output) { + if (recipeCategory == null || output == null) { + return ImmutableList.of(); + } + return recipeOutputMap.getRecipes(recipeCategory, output); } } diff --git a/src/main/java/mezz/jei/api/IRecipeRegistry.java b/src/main/java/mezz/jei/api/IRecipeRegistry.java index 5fb7ce6d6..c8f80ba3f 100644 --- a/src/main/java/mezz/jei/api/IRecipeRegistry.java +++ b/src/main/java/mezz/jei/api/IRecipeRegistry.java @@ -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; @@ -23,18 +25,34 @@ public interface IRecipeRegistry { /** Returns a list of Recipe Categories that have the ItemStack as an input */ @Nonnull - ImmutableList getRecipeCategoriesForInput(ItemStack input); + ImmutableList getRecipeCategoriesWithInput(ItemStack input); + + /** Returns a list of Recipe Categories that have the Fluid as an input */ + @Nonnull + ImmutableList getRecipeCategoriesWithInput(Fluid input); /** Returns a list of Recipe Categories that have the ItemStack as an output */ @Nonnull - ImmutableList getRecipeCategoriesForOutput(ItemStack output); + ImmutableList getRecipeCategoriesWithOutput(ItemStack output); + + /** Returns a list of Recipe Categories that have the Fluid as an output */ + @Nonnull + ImmutableList getRecipeCategoriesWithOutput(Fluid output); /** Returns a list of Recipes of recipeCategory that have the ItemStack as an input */ @Nonnull - ImmutableList getInputRecipes(IRecipeCategory recipeCategory, ItemStack input); + ImmutableList getRecipesWithInput(IRecipeCategory recipeCategory, ItemStack input); + + /** Returns a list of Recipes of recipeCategory that have the Fluid as an input */ + @Nonnull + ImmutableList getRecipesWithInput(IRecipeCategory recipeCategory, Fluid input); /** Returns a list of Recipes of recipeCategory that have the ItemStack as an output */ @Nonnull - ImmutableList getOutputRecipes(IRecipeCategory recipeCategory, ItemStack output); + ImmutableList getRecipesWithOutput(IRecipeCategory recipeCategory, ItemStack output); + + /** Returns a list of Recipes of recipeCategory that have the Fluid as an output */ + @Nonnull + ImmutableList getRecipesWithOutput(IRecipeCategory recipeCategory, Fluid output); } diff --git a/src/main/java/mezz/jei/api/gui/IGuiFluidTanks.java b/src/main/java/mezz/jei/api/gui/IGuiFluidTanks.java new file mode 100644 index 000000000..bc0c6db2f --- /dev/null +++ b/src/main/java/mezz/jei/api/gui/IGuiFluidTanks.java @@ -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 fluidStacks); + + void set(int index, @Nonnull FluidStack fluidStacks); + +} diff --git a/src/main/java/mezz/jei/api/gui/IGuiItemStacks.java b/src/main/java/mezz/jei/api/gui/IGuiItemStacks.java index f6ee5bf27..831e5372c 100644 --- a/src/main/java/mezz/jei/api/gui/IGuiItemStacks.java +++ b/src/main/java/mezz/jei/api/gui/IGuiItemStacks.java @@ -1,13 +1,14 @@ 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 { @@ -15,10 +16,10 @@ 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 itemStacks); + void set(int index, @Nonnull Collection itemStacks); - void setItemStack(int index, @Nonnull ItemStack itemStack); + void set(int index, @Nonnull ItemStack itemStack); } diff --git a/src/main/java/mezz/jei/api/package-info.java b/src/main/java/mezz/jei/api/package-info.java index 278b0e043..740810886 100644 --- a/src/main/java/mezz/jei/api/package-info.java +++ b/src/main/java/mezz/jei/api/package-info.java @@ -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; diff --git a/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java b/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java index 371fa0a0d..cad5caae7 100644 --- a/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java +++ b/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java @@ -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); } diff --git a/src/main/java/mezz/jei/api/recipe/IRecipeHandler.java b/src/main/java/mezz/jei/api/recipe/IRecipeHandler.java index f3c4f5140..43c333f42 100644 --- a/src/main/java/mezz/jei/api/recipe/IRecipeHandler.java +++ b/src/main/java/mezz/jei/api/recipe/IRecipeHandler.java @@ -5,15 +5,15 @@ /** * An IRecipeHandler provides information about one Recipe Class. */ -public interface IRecipeHandler { +public interface IRecipeHandler { /** Returns the class of the Recipe handled by this IRecipeHandler. */ - Class getRecipeClass(); + Class getRecipeClass(); /* Returns the category of this recipe. */ Class getRecipeCategoryClass(); /* Returns a recipe wrapper for the given recipe. */ - IRecipeWrapper getRecipeWrapper(@Nonnull Object recipe); + IRecipeWrapper getRecipeWrapper(@Nonnull T recipe); } diff --git a/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java b/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java index 5fb525fe1..972e1f3e1 100644 --- a/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java +++ b/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java @@ -5,12 +5,18 @@ import net.minecraft.client.Minecraft; +import net.minecraftforge.fluids.FluidStack; + public interface IRecipeWrapper { List getInputs(); + List getFluidInputs(); + List getOutputs(); + List getFluidOutputs(); + /* Draw additional info about the recipe. */ void drawInfo(@Nonnull Minecraft minecraft); } diff --git a/src/main/java/mezz/jei/gui/CraftingGridHelper.java b/src/main/java/mezz/jei/gui/CraftingGridHelper.java index efe6c6e2a..40ddd33e4 100644 --- a/src/main/java/mezz/jei/gui/CraftingGridHelper.java +++ b/src/main/java/mezz/jei/gui/CraftingGridHelper.java @@ -1,6 +1,7 @@ package mezz.jei.gui; import javax.annotation.Nonnull; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -72,11 +73,11 @@ public void setInput(@Nonnull IGuiItemStacks guiItemStacks, @Nonnull List input, } public void setOutput(@Nonnull IGuiItemStacks guiItemStacks, @Nonnull List output) { - guiItemStacks.setItemStack(craftOutputSlot, output); + guiItemStacks.set(craftOutputSlot, output); } - private void setInput(@Nonnull IGuiItemStacks guiItemStacks, int inputIndex, @Nonnull Iterable input) { - guiItemStacks.setItemStack(craftInputSlot1 + inputIndex, input); + private void setInput(@Nonnull IGuiItemStacks guiItemStacks, int inputIndex, @Nonnull Collection input) { + guiItemStacks.set(craftInputSlot1 + inputIndex, input); } } diff --git a/src/main/java/mezz/jei/gui/GuiFluidTank.java b/src/main/java/mezz/jei/gui/GuiFluidTank.java new file mode 100644 index 000000000..0fada7611 --- /dev/null +++ b/src/main/java/mezz/jei/gui/GuiFluidTank.java @@ -0,0 +1,4 @@ +package mezz.jei.gui; + +public class GuiFluidTank { +} diff --git a/src/main/java/mezz/jei/gui/GuiItemStack.java b/src/main/java/mezz/jei/gui/GuiItemStack.java index 14c4a46ba..b7a750432 100644 --- a/src/main/java/mezz/jei/gui/GuiItemStack.java +++ b/src/main/java/mezz/jei/gui/GuiItemStack.java @@ -1,11 +1,7 @@ package mezz.jei.gui; 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 net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -15,35 +11,11 @@ import mezz.jei.util.Log; import mezz.jei.util.StackUtil; -public class GuiItemStack { +public class GuiItemStack extends GuiWidget { private static final int baseWidth = 16; private static final int baseHeight = 16; - private final int width; - private final int height; - private final int padding; - private final int xPosition; - private final int yPosition; - - /* the amount of time in ms to display one itemStack before cycling to the next one */ - private static final int cycleTime = 1000; - private long drawTime = 0; - - private boolean enabled; - private boolean visible; - - @Nonnull - private final List itemStacks = new ArrayList(); - - public GuiItemStack(int xPosition, int yPosition, int padding) { - this.xPosition = xPosition; - this.yPosition = yPosition; - this.padding = padding; - this.width = getWidth(padding); - this.height = getHeight(padding); - } - public static int getWidth(int padding) { return baseWidth + (2 * padding); } @@ -52,47 +24,31 @@ public static int getHeight(int padding) { return baseHeight + (2 * padding); } - public void setItemStacks(@Nonnull Iterable itemStacksIn, @Nullable ItemStack focusStack) { - this.itemStacks.clear(); - Collection itemStacks = StackUtil.getAllSubtypes(itemStacksIn); - ItemStack matchingItemStack = StackUtil.containsStack(itemStacks, focusStack); - if (matchingItemStack != null) { - this.itemStacks.add(matchingItemStack); - } else { - this.itemStacks.addAll(itemStacks); - } - visible = enabled = !this.itemStacks.isEmpty(); - } - - public void setItemStack(@Nonnull ItemStack itemStack, @Nullable ItemStack focusStack) { - setItemStacks(Collections.singletonList(itemStack), focusStack); - } + private final int padding; - public void clearItemStacks() { - itemStacks.clear(); - visible = enabled = false; + public GuiItemStack(int xPosition, int yPosition, int padding) { + super(xPosition, yPosition, getWidth(padding), getHeight(padding)); + this.padding = padding; } - @Nullable - public ItemStack getItemStack() { - if (itemStacks.isEmpty()) { - return null; - } - - Long stackIndex = (drawTime / cycleTime) % itemStacks.size(); - return itemStacks.get(stackIndex.intValue()); + @Override + protected Collection expandSubtypes(Collection contained) { + return StackUtil.getAllSubtypes(contained); } - public boolean isMouseOver(int mouseX, int mouseY) { - return enabled && visible && (mouseX >= xPosition) && (mouseY >= yPosition) && (mouseX < xPosition + width) && (mouseY < yPosition + height); + @Override + protected ItemStack getMatch(Iterable contained, ItemStack toMatch) { + return StackUtil.containsStack(contained, toMatch); } + @Override public void draw(@Nonnull Minecraft minecraft) { draw(minecraft, true); } + @Override public void drawHovered(@Nonnull Minecraft minecraft, int mouseX, int mouseY) { - ItemStack itemStack = getItemStack(); + ItemStack itemStack = get(); if (itemStack == null) { return; } @@ -110,11 +66,9 @@ private void draw(Minecraft minecraft, boolean cycleIcons) { return; } - if (cycleIcons) { - drawTime = System.currentTimeMillis(); - } + cycleTimer.onDraw(cycleIcons); - ItemStack itemStack = getItemStack(); + ItemStack itemStack = get(); if (itemStack == null) { return; } diff --git a/src/main/java/mezz/jei/gui/GuiItemStacks.java b/src/main/java/mezz/jei/gui/GuiItemStacks.java index c6f9c9521..634c19465 100644 --- a/src/main/java/mezz/jei/gui/GuiItemStacks.java +++ b/src/main/java/mezz/jei/gui/GuiItemStacks.java @@ -2,6 +2,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -13,14 +14,14 @@ public class GuiItemStacks implements IGuiItemStacks { @Nonnull - private final Map guiItemStacks = new HashMap(); + private final Map guiItemStacks = new HashMap<>(); private ItemStack focusStack; - public void initItemStack(int index, int xPosition, int yPosition) { - initItemStack(index, xPosition, yPosition, 1); + public void init(int index, int xPosition, int yPosition) { + init(index, xPosition, yPosition, 1); } - public void initItemStack(int index, int xPosition, int yPosition, int padding) { + public void init(int index, int xPosition, int yPosition, int padding) { GuiItemStack guiItemStack = new GuiItemStack(xPosition, yPosition, padding); guiItemStacks.put(index, guiItemStack); } @@ -33,17 +34,17 @@ public void setFocusStack(@Nullable ItemStack focusStack) { this.focusStack = focusStack; } - public void setItemStack(int index, @Nonnull Iterable itemStacks) { - guiItemStacks.get(index).setItemStacks(itemStacks, focusStack); + public void set(int index, @Nonnull Collection itemStacks) { + guiItemStacks.get(index).set(itemStacks, focusStack); } - public void setItemStack(int index, @Nonnull ItemStack itemStack) { - guiItemStacks.get(index).setItemStack(itemStack, focusStack); + public void set(int index, @Nonnull ItemStack itemStack) { + guiItemStacks.get(index).set(itemStack, focusStack); } public void clearItemStacks() { for (GuiItemStack guiItemStack : guiItemStacks.values()) { - guiItemStack.clearItemStacks(); + guiItemStack.clear(); } } @@ -51,7 +52,7 @@ public void clearItemStacks() { public ItemStack getStackUnderMouse(int mouseX, int mouseY) { for (GuiItemStack item : guiItemStacks.values()) { if (item != null && item.isMouseOver(mouseX, mouseY)) { - return item.getItemStack(); + return item.get(); } } return null; diff --git a/src/main/java/mezz/jei/gui/GuiWidget.java b/src/main/java/mezz/jei/gui/GuiWidget.java new file mode 100644 index 000000000..8f35468e2 --- /dev/null +++ b/src/main/java/mezz/jei/gui/GuiWidget.java @@ -0,0 +1,71 @@ +package mezz.jei.gui; + +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.CycleTimer; + +public abstract class GuiWidget implements IGuiWidget { + protected final int xPosition; + protected final int yPosition; + protected final int width; + protected final int height; + + protected boolean enabled; + protected boolean visible; + + protected final CycleTimer cycleTimer = new CycleTimer(); + + @Nonnull + protected final List contained = new ArrayList<>(); + + public GuiWidget(int xPosition, int yPosition, int width, int height) { + this.xPosition = xPosition; + this.yPosition = yPosition; + this.width = width; + this.height = height; + } + + @Override + public void clear() { + visible = enabled = false; + contained.clear(); + } + + @Override + public boolean isMouseOver(int mouseX, int mouseY) { + return enabled && visible && (mouseX >= xPosition) && (mouseY >= yPosition) && (mouseX < xPosition + width) && (mouseY < yPosition + height); + } + + @Override + @Nullable + public T get() { + return cycleTimer.getCycledItem(contained); + } + + @Override + public void set(@Nonnull T contained, @Nullable T focus) { + set(Collections.singleton(contained), focus); + } + + @Override + public void set(@Nonnull Collection contained, @Nullable T focus) { + this.contained.clear(); + contained = expandSubtypes(contained); + T match = getMatch(contained, focus); + if (match != null) { + this.contained.add(match); + } else { + this.contained.addAll(contained); + } + visible = enabled = !this.contained.isEmpty(); + } + + protected abstract Collection expandSubtypes(Collection contained); + + protected abstract T getMatch(Iterable contained, T toMatch); +} diff --git a/src/main/java/mezz/jei/gui/IGuiWidget.java b/src/main/java/mezz/jei/gui/IGuiWidget.java new file mode 100644 index 000000000..fd7d9d158 --- /dev/null +++ b/src/main/java/mezz/jei/gui/IGuiWidget.java @@ -0,0 +1,24 @@ +package mezz.jei.gui; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Collection; + +import net.minecraft.client.Minecraft; + +public interface IGuiWidget { + void set(@Nonnull T contained, @Nullable T focus); + + void set(@Nonnull Collection contained, @Nullable T focus); + + void clear(); + + @Nullable + T get(); + + boolean isMouseOver(int mouseX, int mouseY); + + void draw(@Nonnull Minecraft minecraft); + + void drawHovered(@Nonnull Minecraft minecraft, int mouseX, int mouseY); +} diff --git a/src/main/java/mezz/jei/gui/ItemListOverlay.java b/src/main/java/mezz/jei/gui/ItemListOverlay.java index 285deeec2..aadf39e41 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlay.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlay.java @@ -37,7 +37,7 @@ public class ItemListOverlay implements IShowsItemStacks, IClickable, IKeyable { private final ItemFilter itemFilter; private int buttonHeight; - private final ArrayList guiItemStacks = new ArrayList(); + private final ArrayList guiItemStacks = new ArrayList<>(); private GuiButton nextButton; private GuiButton backButton; private GuiTextField searchField; @@ -129,10 +129,10 @@ private void updateLayout() { ImmutableList itemList = itemFilter.getItemList(); for (GuiItemStack itemButton : guiItemStacks) { if (i >= itemList.size()) { - itemButton.clearItemStacks(); + itemButton.clear(); } else { ItemStack stack = itemList.get(i).getItemStack(); - itemButton.setItemStack(stack, null); + itemButton.set(stack, null); } i++; } @@ -208,7 +208,7 @@ public ItemStack getStackUnderMouse(int mouseX, int mouseY) { } for (GuiItemStack guiItemStack : guiItemStacks) { if (guiItemStack.isMouseOver(mouseX, mouseY)) { - return guiItemStack.getItemStack(); + return guiItemStack.get(); } } return null; @@ -222,11 +222,7 @@ public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { return true; } - boolean searchClicked = handleMouseClickedSearch(mouseX, mouseY, mouseButton); - if (!searchClicked) { - setKeyboardFocus(false); - } - return searchClicked; + return handleMouseClickedSearch(mouseX, mouseY, mouseButton); } private boolean handleMouseClickedButtons(int mouseX, int mouseY, int mouseButton) { @@ -243,8 +239,8 @@ private boolean handleMouseClickedButtons(int mouseX, int mouseY, int mouseButto private boolean handleMouseClickedSearch(int mouseX, int mouseY, int mouseButton) { boolean searchClicked = mouseX >= searchField.xPosition && mouseX < searchField.xPosition + searchField.width && mouseY >= searchField.yPosition && mouseY < searchField.yPosition + searchField.height; + setKeyboardFocus(searchClicked); if (searchClicked) { - setKeyboardFocus(true); if (mouseButton == 1) { searchField.setText(""); if (itemFilter.setFilterText(searchField.getText())) { diff --git a/src/main/java/mezz/jei/gui/RecipesGui.java b/src/main/java/mezz/jei/gui/RecipesGui.java index b6e644591..2480e48fc 100644 --- a/src/main/java/mezz/jei/gui/RecipesGui.java +++ b/src/main/java/mezz/jei/gui/RecipesGui.java @@ -26,13 +26,12 @@ import mezz.jei.api.recipe.IRecipeWrapper; import mezz.jei.config.Constants; import mezz.jei.input.IClickable; -import mezz.jei.input.IKeyable; import mezz.jei.input.IShowsItemStacks; import mezz.jei.util.Log; import mezz.jei.util.MathUtil; import mezz.jei.util.StringUtil; -public class RecipesGui extends GuiScreen implements IShowsItemStacks, IClickable, IKeyable { +public class RecipesGui extends GuiScreen implements IShowsItemStacks, IClickable { private enum Mode { INPUT, OUTPUT } @@ -54,7 +53,7 @@ private enum Mode { /* List of RecipeWidget to display */ @Nonnull - private final List recipeWidgets = new ArrayList(); + private final List recipeWidgets = new ArrayList<>(); /* List of recipes for the currently selected recipeClass */ @Nonnull @@ -175,21 +174,6 @@ public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { return false; } - @Override - public boolean hasKeyboardFocus() { - return false; - } - - @Override - public void setKeyboardFocus(boolean keyboardFocus) { - - } - - @Override - public boolean onKeyPressed(int keyCode) { - return false; - } - @Override public void open() { this.isOpen = true; @@ -241,10 +225,10 @@ private boolean setStack(@Nullable ItemStack stack, @Nonnull Mode mode) { ImmutableList types = null; switch (mode) { case INPUT: - types = JEIManager.recipeRegistry.getRecipeCategoriesForInput(stack); + types = JEIManager.recipeRegistry.getRecipeCategoriesWithInput(stack); break; case OUTPUT: - types = JEIManager.recipeRegistry.getRecipeCategoriesForOutput(stack); + types = JEIManager.recipeRegistry.getRecipeCategoriesWithOutput(stack); break; } if (types.isEmpty()) { @@ -306,10 +290,10 @@ private void updateLayout() { switch (mode) { case INPUT: - recipes = JEIManager.recipeRegistry.getInputRecipes(recipeCategory, focusStack); + recipes = JEIManager.recipeRegistry.getRecipesWithInput(recipeCategory, focusStack); break; case OUTPUT: - recipes = JEIManager.recipeRegistry.getOutputRecipes(recipeCategory, focusStack); + recipes = JEIManager.recipeRegistry.getRecipesWithOutput(recipeCategory, focusStack); break; } diff --git a/src/main/java/mezz/jei/input/InputHandler.java b/src/main/java/mezz/jei/input/InputHandler.java index 230bc0d76..6564d055a 100644 --- a/src/main/java/mezz/jei/input/InputHandler.java +++ b/src/main/java/mezz/jei/input/InputHandler.java @@ -29,9 +29,9 @@ public class InputHandler { private final ItemListOverlay itemListOverlay; private final MouseHelper mouseHelper; - private final List clickables = new ArrayList(); - private final List keyables = new ArrayList(); - private final List showsItemStacks = new ArrayList(); + private final List clickables = new ArrayList<>(); + private final List keyables = new ArrayList<>(); + private final List showsItemStacks = new ArrayList<>(); private boolean clickHandled = false; @@ -41,7 +41,7 @@ public InputHandler(RecipesGui recipesGui, ItemListOverlay itemListOverlay, GuiC this.mouseHelper = new MouseHelper(); - List objects = new ArrayList(); + List objects = new ArrayList<>(); objects.add(recipesGui); objects.add(itemListOverlay); objects.add(new GuiContainerWrapper(guiContainer, recipesGui)); diff --git a/src/main/java/mezz/jei/plugins/vanilla/VanillaPlugin.java b/src/main/java/mezz/jei/plugins/vanilla/VanillaPlugin.java index e067d4104..700035227 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/VanillaPlugin.java +++ b/src/main/java/mezz/jei/plugins/vanilla/VanillaPlugin.java @@ -48,7 +48,7 @@ public Iterable getRecipeHandlers() { @Override public Iterable getRecipes() { - List recipes = new ArrayList(); + List recipes = new ArrayList<>(); recipes.addAll(CraftingRecipeMaker.getCraftingRecipes()); recipes.addAll(SmeltingRecipeMaker.getFurnaceRecipes()); diff --git a/src/main/java/mezz/jei/plugins/vanilla/VanillaRecipeWrapper.java b/src/main/java/mezz/jei/plugins/vanilla/VanillaRecipeWrapper.java new file mode 100644 index 000000000..46227125e --- /dev/null +++ b/src/main/java/mezz/jei/plugins/vanilla/VanillaRecipeWrapper.java @@ -0,0 +1,20 @@ +package mezz.jei.plugins.vanilla; + +import java.util.Collections; +import java.util.List; + +import net.minecraftforge.fluids.FluidStack; + +import mezz.jei.api.recipe.IRecipeWrapper; + +public abstract class VanillaRecipeWrapper implements IRecipeWrapper { + @Override + public List getFluidInputs() { + return Collections.emptyList(); + } + + @Override + public List getFluidOutputs() { + return Collections.emptyList(); + } +} diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/CraftingRecipeCategory.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/CraftingRecipeCategory.java index 476d4b1dd..3c0844a5f 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/CraftingRecipeCategory.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/CraftingRecipeCategory.java @@ -13,6 +13,7 @@ import mezz.jei.api.recipe.IRecipeWrapper; import mezz.jei.api.recipe.wrapper.ICraftingRecipeWrapper; import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper; +import mezz.jei.util.Log; public class CraftingRecipeCategory implements IRecipeCategory { @@ -47,12 +48,12 @@ public IDrawable getBackground() { @Override public void init(@Nonnull IGuiItemStacks guiItemStacks) { - guiItemStacks.initItemStack(craftOutputSlot, 94, 18); + guiItemStacks.init(craftOutputSlot, 94, 18); for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { int index = craftInputSlot1 + x + (y * 3); - guiItemStacks.initItemStack(index, x * 18, y * 18); + guiItemStacks.init(index, x * 18, y * 18); } } } @@ -67,8 +68,9 @@ public void setRecipe(@Nonnull IGuiItemStacks guiItemStacks, @Nonnull IRecipeWra ICraftingRecipeWrapper wrapper = (ICraftingRecipeWrapper) recipeWrapper; craftingGridHelper.setInput(guiItemStacks, wrapper.getInputs()); craftingGridHelper.setOutput(guiItemStacks, wrapper.getOutputs()); + } else { + Log.error("RecipeWrapper is not a know crafting wrapper type: %s", recipeWrapper); } } - } diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeHandler.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeHandler.java index ea1beca9f..bca20fe6e 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeHandler.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeHandler.java @@ -8,11 +8,11 @@ import mezz.jei.api.recipe.IRecipeHandler; import mezz.jei.api.recipe.IRecipeWrapper; -public class ShapedOreRecipeHandler implements IRecipeHandler { +public class ShapedOreRecipeHandler implements IRecipeHandler { @Nonnull @Override - public Class getRecipeClass() { + public Class getRecipeClass() { return ShapedOreRecipe.class; } @@ -23,7 +23,7 @@ public Class getRecipeCategoryClass() { } @Override - public IRecipeWrapper getRecipeWrapper(@Nonnull Object recipe) { + public IRecipeWrapper getRecipeWrapper(@Nonnull ShapedOreRecipe recipe) { return new ShapedOreRecipeWrapper(recipe); } diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeWrapper.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeWrapper.java index 1fb604c97..f29aec282 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeWrapper.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedOreRecipeWrapper.java @@ -12,16 +12,17 @@ import net.minecraftforge.oredict.ShapedOreRecipe; import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper; +import mezz.jei.plugins.vanilla.VanillaRecipeWrapper; -public class ShapedOreRecipeWrapper implements IShapedCraftingRecipeWrapper { +public class ShapedOreRecipeWrapper extends VanillaRecipeWrapper implements IShapedCraftingRecipeWrapper { @Nonnull private final ShapedOreRecipe recipe; private final int width; private final int height; - public ShapedOreRecipeWrapper(@Nonnull Object recipe) { - this.recipe = (ShapedOreRecipe) recipe; + public ShapedOreRecipeWrapper(@Nonnull ShapedOreRecipe recipe) { + this.recipe = recipe; for (Object input : this.recipe.getInput()) { if (input instanceof ItemStack) { ItemStack itemStack = (ItemStack) input; diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesHandler.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesHandler.java index 5d3d201ba..1e69ffb6a 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesHandler.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesHandler.java @@ -8,11 +8,11 @@ import mezz.jei.api.recipe.IRecipeHandler; import mezz.jei.api.recipe.IRecipeWrapper; -public class ShapedRecipesHandler implements IRecipeHandler { +public class ShapedRecipesHandler implements IRecipeHandler { @Nonnull @Override - public Class getRecipeClass() { + public Class getRecipeClass() { return ShapedRecipes.class; } @@ -23,7 +23,7 @@ public Class getRecipeCategoryClass() { } @Override - public IRecipeWrapper getRecipeWrapper(@Nonnull Object recipe) { + public IRecipeWrapper getRecipeWrapper(@Nonnull ShapedRecipes recipe) { return new ShapedRecipesWrapper(recipe); } diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesWrapper.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesWrapper.java index 7fbbbdb84..048782dab 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesWrapper.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapedRecipesWrapper.java @@ -10,14 +10,15 @@ import net.minecraft.item.crafting.ShapedRecipes; import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper; +import mezz.jei.plugins.vanilla.VanillaRecipeWrapper; -public class ShapedRecipesWrapper implements IShapedCraftingRecipeWrapper { +public class ShapedRecipesWrapper extends VanillaRecipeWrapper implements IShapedCraftingRecipeWrapper { @Nonnull private final ShapedRecipes recipe; - public ShapedRecipesWrapper(@Nonnull Object recipe) { - this.recipe = (ShapedRecipes) recipe; + public ShapedRecipesWrapper(@Nonnull ShapedRecipes recipe) { + this.recipe = recipe; for (ItemStack itemStack : this.recipe.recipeItems) { if (itemStack != null && itemStack.stackSize > 1) { itemStack.stackSize = 1; diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeHandler.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeHandler.java index a91050d1a..338f67951 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeHandler.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeHandler.java @@ -8,11 +8,11 @@ import mezz.jei.api.recipe.IRecipeHandler; import mezz.jei.api.recipe.IRecipeWrapper; -public class ShapelessOreRecipeHandler implements IRecipeHandler { +public class ShapelessOreRecipeHandler implements IRecipeHandler { @Nonnull @Override - public Class getRecipeClass() { + public Class getRecipeClass() { return ShapelessOreRecipe.class; } @@ -23,7 +23,7 @@ public Class getRecipeCategoryClass() { } @Override - public IRecipeWrapper getRecipeWrapper(@Nonnull Object recipe) { + public IRecipeWrapper getRecipeWrapper(@Nonnull ShapelessOreRecipe recipe) { return new ShapelessOreRecipeWrapper(recipe); } diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeWrapper.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeWrapper.java index beb8e3934..3f8539707 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeWrapper.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessOreRecipeWrapper.java @@ -10,14 +10,15 @@ import net.minecraftforge.oredict.ShapelessOreRecipe; import mezz.jei.api.recipe.wrapper.ICraftingRecipeWrapper; +import mezz.jei.plugins.vanilla.VanillaRecipeWrapper; -public class ShapelessOreRecipeWrapper implements ICraftingRecipeWrapper { +public class ShapelessOreRecipeWrapper extends VanillaRecipeWrapper implements ICraftingRecipeWrapper { @Nonnull private final ShapelessOreRecipe recipe; - public ShapelessOreRecipeWrapper(@Nonnull Object recipe) { - this.recipe = (ShapelessOreRecipe) recipe; + public ShapelessOreRecipeWrapper(@Nonnull ShapelessOreRecipe recipe) { + this.recipe = recipe; for (Object input : this.recipe.getInput()) { if (input instanceof ItemStack) { ItemStack itemStack = (ItemStack) input; diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesHandler.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesHandler.java index d4fd907e6..669d7b5b4 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesHandler.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesHandler.java @@ -8,11 +8,11 @@ import mezz.jei.api.recipe.IRecipeHandler; import mezz.jei.api.recipe.IRecipeWrapper; -public class ShapelessRecipesHandler implements IRecipeHandler { +public class ShapelessRecipesHandler implements IRecipeHandler { @Nonnull @Override - public Class getRecipeClass() { + public Class getRecipeClass() { return ShapelessRecipes.class; } @@ -24,7 +24,7 @@ public Class getRecipeCategoryClass() { @Nonnull @Override - public IRecipeWrapper getRecipeWrapper(@Nonnull Object recipe) { + public IRecipeWrapper getRecipeWrapper(@Nonnull ShapelessRecipes recipe) { return new ShapelessRecipesWrapper(recipe); } diff --git a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesWrapper.java b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesWrapper.java index 7edb9fdd6..557445dbe 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesWrapper.java +++ b/src/main/java/mezz/jei/plugins/vanilla/crafting/ShapelessRecipesWrapper.java @@ -9,14 +9,15 @@ import net.minecraft.item.crafting.ShapelessRecipes; import mezz.jei.api.recipe.wrapper.ICraftingRecipeWrapper; +import mezz.jei.plugins.vanilla.VanillaRecipeWrapper; -public class ShapelessRecipesWrapper implements ICraftingRecipeWrapper { +public class ShapelessRecipesWrapper extends VanillaRecipeWrapper implements ICraftingRecipeWrapper { @Nonnull private final ShapelessRecipes recipe; - public ShapelessRecipesWrapper(@Nonnull Object recipe) { - this.recipe = (ShapelessRecipes) recipe; + public ShapelessRecipesWrapper(@Nonnull ShapelessRecipes recipe) { + this.recipe = recipe; for (Object input : this.recipe.recipeItems) { if (input instanceof ItemStack) { ItemStack itemStack = (ItemStack) input; diff --git a/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipe.java b/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipe.java index 542bb2606..a8c1dda39 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipe.java +++ b/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipe.java @@ -12,16 +12,16 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; -import mezz.jei.api.recipe.IRecipeWrapper; +import mezz.jei.plugins.vanilla.VanillaRecipeWrapper; -public class FuelRecipe implements IRecipeWrapper { +public class FuelRecipe extends VanillaRecipeWrapper { @Nonnull private final List input; @Nullable private final String burnTimeString; public FuelRecipe(@Nonnull Collection input, int burnTime) { - this.input = new ArrayList(input); + this.input = new ArrayList<>(input); this.burnTimeString = StatCollector.translateToLocalFormatted("gui.jei.furnaceBurnTime", burnTime); } diff --git a/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeHandler.java b/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeHandler.java index 67ddc6e25..b443a1e8d 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeHandler.java +++ b/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeHandler.java @@ -6,10 +6,10 @@ import mezz.jei.api.recipe.IRecipeHandler; import mezz.jei.api.recipe.IRecipeWrapper; -public class FuelRecipeHandler implements IRecipeHandler { +public class FuelRecipeHandler implements IRecipeHandler { @Nonnull @Override - public Class getRecipeClass() { + public Class getRecipeClass() { return FuelRecipe.class; } @@ -20,8 +20,8 @@ public Class getRecipeCategoryClass() { } @Override - public IRecipeWrapper getRecipeWrapper(@Nonnull Object recipe) { - return (FuelRecipe) recipe; + public IRecipeWrapper getRecipeWrapper(@Nonnull FuelRecipe recipe) { + return recipe; } } diff --git a/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeMaker.java b/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeMaker.java index e57580e59..4f241b26b 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeMaker.java +++ b/src/main/java/mezz/jei/plugins/vanilla/furnace/FuelRecipeMaker.java @@ -21,8 +21,8 @@ public class FuelRecipeMaker { @Nonnull public static List getFuelRecipes() { List fuelStacks = JEIManager.itemRegistry.getFuels(); - Set oreDictNames = new HashSet(); - List fuelRecipes = new ArrayList(fuelStacks.size()); + Set oreDictNames = new HashSet<>(); + List fuelRecipes = new ArrayList<>(fuelStacks.size()); for (ItemStack fuelStack : fuelStacks) { if (fuelStack == null) { continue; diff --git a/src/main/java/mezz/jei/plugins/vanilla/furnace/FurnaceRecipeCategory.java b/src/main/java/mezz/jei/plugins/vanilla/furnace/FurnaceRecipeCategory.java index aeb656be8..43f1474e5 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/furnace/FurnaceRecipeCategory.java +++ b/src/main/java/mezz/jei/plugins/vanilla/furnace/FurnaceRecipeCategory.java @@ -35,20 +35,20 @@ public IDrawable getBackground() { @Override public void init(@Nonnull IGuiItemStacks guiItemStacks) { - guiItemStacks.initItemStack(inputSlot, 0, 0); - guiItemStacks.initItemStack(fuelSlot, 0, 36); - guiItemStacks.initItemStack(outputSlot, 60, 18); + guiItemStacks.init(inputSlot, 0, 0); + guiItemStacks.init(fuelSlot, 0, 36); + guiItemStacks.init(outputSlot, 60, 18); } @Override public void setRecipe(@Nonnull IGuiItemStacks guiItemStacks, @Nonnull IRecipeWrapper recipeWrapper) { if (recipeWrapper instanceof FuelRecipe) { FuelRecipe fuelRecipeWrapper = (FuelRecipe) recipeWrapper; - guiItemStacks.setItemStack(fuelSlot, fuelRecipeWrapper.getInputs()); + guiItemStacks.set(fuelSlot, fuelRecipeWrapper.getInputs()); } else if (recipeWrapper instanceof SmeltingRecipe) { SmeltingRecipe smeltingRecipeWrapper = (SmeltingRecipe) recipeWrapper; - guiItemStacks.setItemStack(inputSlot, smeltingRecipeWrapper.getInputs()); - guiItemStacks.setItemStack(outputSlot, smeltingRecipeWrapper.getOutputs()); + guiItemStacks.set(inputSlot, smeltingRecipeWrapper.getInputs()); + guiItemStacks.set(outputSlot, smeltingRecipeWrapper.getOutputs()); } } diff --git a/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipe.java b/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipe.java index 7a731bea6..55efcb5cd 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipe.java +++ b/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipe.java @@ -11,9 +11,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; -import mezz.jei.api.recipe.IRecipeWrapper; +import mezz.jei.plugins.vanilla.VanillaRecipeWrapper; -public class SmeltingRecipe implements IRecipeWrapper { +public class SmeltingRecipe extends VanillaRecipeWrapper { @Nonnull private final List input; @Nonnull diff --git a/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeHandler.java b/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeHandler.java index 9a95286dd..ec564ddd5 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeHandler.java +++ b/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeHandler.java @@ -6,11 +6,11 @@ import mezz.jei.api.recipe.IRecipeHandler; import mezz.jei.api.recipe.IRecipeWrapper; -public class SmeltingRecipeHandler implements IRecipeHandler { +public class SmeltingRecipeHandler implements IRecipeHandler { @Nonnull @Override - public Class getRecipeClass() { + public Class getRecipeClass() { return SmeltingRecipe.class; } @@ -21,8 +21,8 @@ public Class getRecipeCategoryClass() { } @Override - public IRecipeWrapper getRecipeWrapper(@Nonnull Object recipe) { - return (SmeltingRecipe) recipe; + public IRecipeWrapper getRecipeWrapper(@Nonnull SmeltingRecipe recipe) { + return recipe; } } diff --git a/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeMaker.java b/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeMaker.java index b6941a9cd..c1ed1454f 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeMaker.java +++ b/src/main/java/mezz/jei/plugins/vanilla/furnace/SmeltingRecipeMaker.java @@ -17,7 +17,7 @@ public static List getFurnaceRecipes() { FurnaceRecipes furnaceRecipes = FurnaceRecipes.instance(); Map smeltingMap = getSmeltingMap(furnaceRecipes); - List recipes = new ArrayList(); + List recipes = new ArrayList<>(); for (Map.Entry itemStackItemStackEntry : smeltingMap.entrySet()) { ItemStack input = itemStackItemStackEntry.getKey(); diff --git a/src/main/java/mezz/jei/util/Commands.java b/src/main/java/mezz/jei/util/Commands.java index ede3be373..f0c51cbe2 100644 --- a/src/main/java/mezz/jei/util/Commands.java +++ b/src/main/java/mezz/jei/util/Commands.java @@ -30,7 +30,7 @@ public static void giveStack(@Nonnull ItemStack itemStack, int amount) { EntityPlayerSP sender = Minecraft.getMinecraft().thePlayer; String senderName = sender.getCommandSenderName(); - List commandStrings = new ArrayList(); + List commandStrings = new ArrayList<>(); commandStrings.add("/give"); commandStrings.add(senderName); commandStrings.add((String) Item.itemRegistry.getNameForObject(itemStack.getItem())); diff --git a/src/main/java/mezz/jei/util/CycleTimer.java b/src/main/java/mezz/jei/util/CycleTimer.java new file mode 100644 index 000000000..95833d68d --- /dev/null +++ b/src/main/java/mezz/jei/util/CycleTimer.java @@ -0,0 +1,23 @@ +package mezz.jei.util; + +import java.util.List; + +public class CycleTimer { + /* the amount of time in ms to display one thing before cycling to the next one */ + private static final int cycleTime = 1000; + private long drawTime = 0; + + public T getCycledItem(List list) { + if (list.isEmpty()) { + return null; + } + Long stackIndex = (drawTime / cycleTime) % list.size(); + return list.get(stackIndex.intValue()); + } + + public void onDraw(boolean cycleEnabled) { + if (cycleEnabled) { + drawTime = System.currentTimeMillis(); + } + } +} diff --git a/src/main/java/mezz/jei/util/RecipeCategoryComparator.java b/src/main/java/mezz/jei/util/RecipeCategoryComparator.java new file mode 100644 index 000000000..709debd04 --- /dev/null +++ b/src/main/java/mezz/jei/util/RecipeCategoryComparator.java @@ -0,0 +1,24 @@ +package mezz.jei.util; + +import com.google.common.collect.ImmutableList; + +import javax.annotation.Nonnull; +import java.util.Comparator; + +import mezz.jei.api.recipe.IRecipeCategory; + +public class RecipeCategoryComparator implements Comparator { + @Nonnull + private final ImmutableList recipeCategories; + + public RecipeCategoryComparator(@Nonnull ImmutableList recipeCategories) { + this.recipeCategories = recipeCategories; + } + + @Override + public int compare(IRecipeCategory recipeCategory1, IRecipeCategory recipeCategory2) { + Integer index1 = recipeCategories.indexOf(recipeCategory1); + Integer index2 = recipeCategories.indexOf(recipeCategory2); + return index1.compareTo(index2); + } +} diff --git a/src/main/java/mezz/jei/util/RecipeMap.java b/src/main/java/mezz/jei/util/RecipeMap.java index dc005f648..dd55c5392 100644 --- a/src/main/java/mezz/jei/util/RecipeMap.java +++ b/src/main/java/mezz/jei/util/RecipeMap.java @@ -3,22 +3,20 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.HashBasedTable; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import com.google.common.collect.Table; import javax.annotation.Nonnull; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import java.util.Map; import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; -import mezz.jei.RecipeRegistry; import mezz.jei.api.recipe.IRecipeCategory; /** @@ -33,56 +31,52 @@ public class RecipeMap { @Nonnull private final Ordering recipeCategoryOrdering; - public RecipeMap(final RecipeRegistry recipeRegistry) { - Comparator recipeCategoryComparator = new Comparator() { - public int compare(IRecipeCategory recipeCategory1, IRecipeCategory recipeCategory2) { - Integer index1 = recipeRegistry.getRecipeCategoryIndex(recipeCategory1); - Integer index2 = recipeRegistry.getRecipeCategoryIndex(recipeCategory2); - return index1.compareTo(index2); - } - }; + public RecipeMap(final RecipeCategoryComparator recipeCategoryComparator) { this.recipeCategoryOrdering = Ordering.from(recipeCategoryComparator); } @Nonnull public ImmutableList getRecipeCategories(@Nonnull ItemStack itemStack) { - ImmutableSet.Builder recipeCategoriesBuilder = ImmutableSet.builder(); + List recipeCategories = new ArrayList<>(); for (String stackKey : getNamesWithWildcard(itemStack)) { - recipeCategoriesBuilder.addAll(categoryMap.get(stackKey)); + recipeCategories.addAll(categoryMap.get(stackKey)); } - ImmutableSet recipeCategories = recipeCategoriesBuilder.build(); return recipeCategoryOrdering.immutableSortedCopy(recipeCategories); } + @Nonnull + public ImmutableList getRecipeCategories(@Nonnull Fluid fluid) { + String key = getKeyForFluid(fluid); + return recipeCategoryOrdering.immutableSortedCopy(categoryMap.get(key)); + } + private void addRecipeCategory(@Nonnull IRecipeCategory recipeCategory, @Nonnull ItemStack itemStack) { - String stackKey = getName(itemStack); + String stackKey = StackUtil.uniqueIdentifierForStack(itemStack, false); List recipeCategories = categoryMap.get(stackKey); if (!recipeCategories.contains(recipeCategory)) { recipeCategories.add(recipeCategory); } } - @Nonnull - private List getNamesWithWildcard(@Nonnull ItemStack itemStack) { - List names = new ArrayList(2); - names.add(getName(itemStack)); - names.add(getWildcardName(itemStack)); - return names; + private void addRecipeCategory(@Nonnull IRecipeCategory recipeCategory, @Nonnull Fluid fluid) { + String key = getKeyForFluid(fluid); + List recipeCategories = categoryMap.get(key); + if (!recipeCategories.contains(recipeCategory)) { + recipeCategories.add(recipeCategory); + } } @Nonnull - private String getName(@Nonnull ItemStack itemStack) { - int meta = itemStack.getItemDamage(); - if (meta == OreDictionary.WILDCARD_VALUE) { - return getWildcardName(itemStack); - } else { - return itemStack.getUnlocalizedName() + ':' + meta; - } + private List getNamesWithWildcard(@Nonnull ItemStack itemStack) { + List names = new ArrayList<>(2); + names.add(StackUtil.uniqueIdentifierForStack(itemStack, false)); + names.add(StackUtil.uniqueIdentifierForStack(itemStack, true)); + return names; } @Nonnull - private String getWildcardName(@Nonnull ItemStack itemStack) { - return itemStack.getItem().getUnlocalizedName() + ':' + OreDictionary.WILDCARD_VALUE; + private String getKeyForFluid(Fluid fluid) { + return "fluid:" + fluid.getID(); } @Nonnull @@ -99,7 +93,19 @@ public ImmutableList getRecipes(@Nonnull IRecipeCategory recipeCategory, return listBuilder.build(); } - public void addRecipe(@Nonnull Object recipe, @Nonnull IRecipeCategory recipeCategory, @Nonnull Iterable itemStacks) { + @Nonnull + public ImmutableList getRecipes(@Nonnull IRecipeCategory recipeCategory, @Nonnull Fluid fluid) { + Map> recipesForType = recipeTable.row(recipeCategory); + + String name = getKeyForFluid(fluid); + List recipes = recipesForType.get(name); + if (recipes == null) { + return ImmutableList.of(); + } + return ImmutableList.copyOf(recipes); + } + + public void addRecipe(@Nonnull Object recipe, @Nonnull IRecipeCategory recipeCategory, @Nonnull Iterable itemStacks, @Nonnull Iterable fluidStacks) { Map> recipesForType = recipeTable.row(recipeCategory); for (ItemStack itemStack : itemStacks) { @@ -107,7 +113,7 @@ public void addRecipe(@Nonnull Object recipe, @Nonnull IRecipeCategory recipeCat continue; } - String stackKey = getName(itemStack); + String stackKey = StackUtil.uniqueIdentifierForStack(itemStack, false); List recipes = recipesForType.get(stackKey); if (recipes == null) { recipes = Lists.newArrayList(); @@ -117,5 +123,25 @@ public void addRecipe(@Nonnull Object recipe, @Nonnull IRecipeCategory recipeCat addRecipeCategory(recipeCategory, itemStack); } + + for (FluidStack fluidStack : fluidStacks) { + if (fluidStack == null) { + continue; + } + Fluid fluid = fluidStack.getFluid(); + if (fluid == null) { + continue; + } + + String fluidKey = getKeyForFluid(fluid); + List recipes = recipesForType.get(fluidKey); + if (recipes == null) { + recipes = Lists.newArrayList(); + recipesForType.put(fluidKey, recipes); + } + recipes.add(recipe); + + addRecipeCategory(recipeCategory, fluid); + } } } diff --git a/src/main/java/mezz/jei/util/StackUtil.java b/src/main/java/mezz/jei/util/StackUtil.java index fd718ea7d..4e8277b68 100644 --- a/src/main/java/mezz/jei/util/StackUtil.java +++ b/src/main/java/mezz/jei/util/StackUtil.java @@ -10,13 +10,14 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.registry.GameData; import net.minecraftforge.oredict.OreDictionary; public class StackUtil { @Nonnull public static List removeDuplicateItemStacks(Iterable stacks) { - List newStacks = new ArrayList(); + List newStacks = new ArrayList<>(); if (stacks == null) { return newStacks; } @@ -72,7 +73,7 @@ public static boolean isIdentical(@Nullable ItemStack lhs, @Nullable ItemStack r @Nonnull public static List getSubtypes(@Nonnull ItemStack itemStack) { - List itemStacks = new ArrayList(); + List itemStacks = new ArrayList<>(); Item item = itemStack.getItem(); if (item == null) { @@ -87,7 +88,7 @@ public static List getSubtypes(@Nonnull ItemStack itemStack) { return Collections.singletonList(new ItemStack(item)); } - List subItems = new ArrayList(); + List subItems = new ArrayList<>(); for (CreativeTabs itemTab : item.getCreativeTabs()) { subItems.clear(); item.getSubItems(item, itemTab, subItems); @@ -104,7 +105,7 @@ public static List getSubtypes(@Nonnull ItemStack itemStack) { } public static List getAllSubtypes(Iterable stacks) { - List allSubtypes = new ArrayList(); + List allSubtypes = new ArrayList<>(); getAllSubtypes(allSubtypes, stacks); return allSubtypes; } @@ -124,8 +125,11 @@ private static void getAllSubtypes(List subtypesList, Iterable stacks } @Nonnull - public static List toItemStackList(@Nonnull Iterable stacks) { - List itemStacksList = new ArrayList(); + public static List toItemStackList(@Nullable Iterable stacks) { + if (stacks == null) { + return Collections.emptyList(); + } + List itemStacksList = new ArrayList<>(); toItemStackList(itemStacksList, stacks); return removeDuplicateItemStacks(itemStacksList); } @@ -142,4 +146,20 @@ private static void toItemStackList(@Nonnull List itemStackList, @Non } } + @Nonnull + public static String uniqueIdentifierForStack(@Nonnull ItemStack stack, boolean wildcard) { + Item item = stack.getItem(); + Object itemName = GameData.getItemRegistry().getNameForObject(item); + String itemNameString = String.valueOf(itemName); + if (wildcard) { + return itemNameString; + } + + StringBuilder itemKey = new StringBuilder(itemNameString).append(':').append(stack.getItemDamage()); + if (stack.hasTagCompound()) { + itemKey.append(':').append(stack.getTagCompound()); + } + + return itemKey.toString(); + } }