/
ShapelessRecipesHandler.java
53 lines (45 loc) · 1.3 KB
/
ShapelessRecipesHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package mezz.jei.plugins.vanilla.crafting;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapelessRecipes;
import javax.annotation.Nonnull;
public class ShapelessRecipesHandler implements IRecipeHandler<ShapelessRecipes> {
@Nonnull
private final IGuiHelper guiHelper;
public ShapelessRecipesHandler(@Nonnull IGuiHelper guiHelper) {
this.guiHelper = guiHelper;
}
@Override
@Nonnull
public Class<ShapelessRecipes> getRecipeClass() {
return ShapelessRecipes.class;
}
@Nonnull
@Override
public String getRecipeCategoryUid() {
return VanillaRecipeCategoryUid.CRAFTING;
}
@Override
@Nonnull
public IRecipeWrapper getRecipeWrapper(@Nonnull ShapelessRecipes recipe) {
return new ShapelessRecipesWrapper(guiHelper, recipe);
}
@Override
public boolean isRecipeValid(@Nonnull ShapelessRecipes recipe) {
if (recipe.getRecipeOutput() == null) {
return false;
}
int inputCount = 0;
for (Object input : recipe.recipeItems) {
if (input instanceof ItemStack) {
inputCount++;
} else {
return false;
}
}
return inputCount > 0;
}
}