Skip to content

Commit

Permalink
Added special cases for EnchantmentData
Browse files Browse the repository at this point in the history
  • Loading branch information
naqaden authored Nov 29, 2018
1 parent c4e7d14 commit f57d55c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/mezz/jei/recipes/RecipeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
import mezz.jei.util.Log;
import net.minecraft.block.Block;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
Expand Down Expand Up @@ -540,6 +542,20 @@ public RecipeClickableArea getRecipeClickableArea(GuiContainer gui, int mouseX,
return null;
}

/**
* Special case for EnchantmentData which replaces enchanted book items.
*/
@Nullable
private static ItemStack getEnchantBookFromEnchantData(IFocus<?> focus) {
Object ingredient = focus.getValue();
if (ingredient instanceof EnchantmentData) {
EnchantmentData enchantData = (EnchantmentData) ingredient;
return ItemEnchantedBook.getEnchantedItemStack(enchantData);
}

return null;
}

/**
* Special case for ItemBlocks containing fluid blocks.
* Nothing crafts those, the player probably wants to look up fluids.
Expand All @@ -566,6 +582,10 @@ private static FluidStack getFluidFromItemBlock(IFocus<?> focus) {
public <V> List<IRecipeCategory> getRecipeCategories(IFocus<V> focus) {
focus = Focus.check(focus);

ItemStack enchantBook = getEnchantBookFromEnchantData(focus);
if (enchantBook != null) {
return getRecipeCategories(createFocus(focus.getMode(), enchantBook));
}
FluidStack fluidStack = getFluidFromItemBlock(focus);
if (fluidStack != null) {
return getRecipeCategories(createFocus(focus.getMode(), fluidStack));
Expand Down Expand Up @@ -599,6 +619,10 @@ public <T extends IRecipeWrapper, V> List<T> getRecipeWrappers(IRecipeCategory<T
ErrorUtil.checkNotNull(recipeCategory, "recipeCategory");
focus = Focus.check(focus);

ItemStack enchantBook = getEnchantBookFromEnchantData(focus);
if (enchantBook != null) {
return getRecipeWrappers(recipeCategory, createFocus(focus.getMode(), enchantBook));
}
FluidStack fluidStack = getFluidFromItemBlock(focus);
if (fluidStack != null) {
return getRecipeWrappers(recipeCategory, createFocus(focus.getMode(), fluidStack));
Expand Down

0 comments on commit f57d55c

Please sign in to comment.