/
ShapelessOreRecipeHandler.java
71 lines (62 loc) · 2 KB
/
ShapelessOreRecipeHandler.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package mezz.jei.plugins.vanilla.crafting;
import java.util.List;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import mezz.jei.util.ErrorUtil;
import mezz.jei.util.Log;
import net.minecraftforge.oredict.ShapelessOreRecipe;
public class ShapelessOreRecipeHandler implements IRecipeHandler<ShapelessOreRecipe> {
private final IGuiHelper guiHelper;
public ShapelessOreRecipeHandler(IGuiHelper guiHelper) {
this.guiHelper = guiHelper;
}
@Override
public Class<ShapelessOreRecipe> getRecipeClass() {
return ShapelessOreRecipe.class;
}
@Override
public String getRecipeCategoryUid() {
return VanillaRecipeCategoryUid.CRAFTING;
}
@Override
public String getRecipeCategoryUid(ShapelessOreRecipe recipe) {
return VanillaRecipeCategoryUid.CRAFTING;
}
@Override
public IRecipeWrapper getRecipeWrapper(ShapelessOreRecipe recipe) {
return new ShapelessOreRecipeWrapper(guiHelper, recipe);
}
@Override
public boolean isRecipeValid(ShapelessOreRecipe recipe) {
if (recipe.getRecipeOutput() == null) {
String recipeInfo = ErrorUtil.getInfoFromBrokenRecipe(recipe, this);
Log.error("Recipe has no outputs. {}", recipeInfo);
return false;
}
int inputCount = 0;
for (Object input : recipe.getInput()) {
if (input instanceof List) {
if (((List) input).isEmpty()) {
// missing items for an oreDict name. This is normal behavior, but the recipe is invalid.
return false;
}
}
if (input != null) {
inputCount++;
}
}
if (inputCount > 9) {
String recipeInfo = ErrorUtil.getInfoFromBrokenRecipe(recipe, this);
Log.error("Recipe has too many inputs. {}", recipeInfo);
return false;
}
if (inputCount == 0) {
String recipeInfo = ErrorUtil.getInfoFromBrokenRecipe(recipe, this);
Log.error("Recipe has no inputs. {}", recipeInfo);
return false;
}
return true;
}
}