/
ShapedOreRecipeHandler.java
65 lines (57 loc) · 1.76 KB
/
ShapedOreRecipeHandler.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
package mezz.jei.plugins.vanilla.crafting;
import javax.annotation.Nonnull;
import java.util.List;
import mezz.jei.util.ErrorUtil;
import mezz.jei.util.Log;
import net.minecraftforge.oredict.ShapedOreRecipe;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
public class ShapedOreRecipeHandler implements IRecipeHandler<ShapedOreRecipe> {
@Override
@Nonnull
public Class<ShapedOreRecipe> getRecipeClass() {
return ShapedOreRecipe.class;
}
@Nonnull
@Override
public String getRecipeCategoryUid() {
return VanillaRecipeCategoryUid.CRAFTING;
}
@Override
@Nonnull
public IRecipeWrapper getRecipeWrapper(@Nonnull ShapedOreRecipe recipe) {
return new ShapedOreRecipeWrapper(recipe);
}
@Override
public boolean isRecipeValid(@Nonnull ShapedOreRecipe recipe) {
if (recipe.getRecipeOutput() == null) {
String recipeInfo = ErrorUtil.getInfoFromBrokenRecipe(recipe, this);
Log.error("Recipe has no output. {}", 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;
}
}