/
CraftingRecipeCategory.java
92 lines (74 loc) · 3.01 KB
/
CraftingRecipeCategory.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package mezz.jei.plugins.vanilla.crafting;
import java.util.List;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.ICraftingGridHelper;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import mezz.jei.api.recipe.wrapper.ICustomCraftingRecipeWrapper;
import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper;
import mezz.jei.config.Constants;
import mezz.jei.util.Translator;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public class CraftingRecipeCategory implements IRecipeCategory<IRecipeWrapper> {
private static final int craftOutputSlot = 0;
private static final int craftInputSlot1 = 1;
public static final int width = 116;
public static final int height = 54;
private final IDrawable background;
private final String localizedName;
private final ICraftingGridHelper craftingGridHelper;
public CraftingRecipeCategory(IGuiHelper guiHelper) {
ResourceLocation location = Constants.RECIPE_GUI_VANILLA;
background = guiHelper.createDrawable(location, 0, 60, width, height);
localizedName = Translator.translateToLocal("gui.jei.category.craftingTable");
craftingGridHelper = guiHelper.createCraftingGridHelper(craftInputSlot1, craftOutputSlot);
}
@Override
public String getUid() {
return VanillaRecipeCategoryUid.CRAFTING;
}
@Override
public String getTitle() {
return localizedName;
}
@Override
public String getModName() {
return Constants.minecraftModName;
}
@Override
public IDrawable getBackground() {
return background;
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, IRecipeWrapper recipeWrapper, IIngredients ingredients) {
IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
guiItemStacks.init(craftOutputSlot, false, 94, 18);
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 3; ++x) {
int index = craftInputSlot1 + x + (y * 3);
guiItemStacks.init(index, true, x * 18, y * 18);
}
}
if (recipeWrapper instanceof ICustomCraftingRecipeWrapper) {
ICustomCraftingRecipeWrapper customWrapper = (ICustomCraftingRecipeWrapper) recipeWrapper;
customWrapper.setRecipe(recipeLayout, ingredients);
return;
}
List<List<ItemStack>> inputs = ingredients.getInputs(ItemStack.class);
List<List<ItemStack>> outputs = ingredients.getOutputs(ItemStack.class);
if (recipeWrapper instanceof IShapedCraftingRecipeWrapper) {
IShapedCraftingRecipeWrapper wrapper = (IShapedCraftingRecipeWrapper) recipeWrapper;
craftingGridHelper.setInputs(guiItemStacks, inputs, wrapper.getWidth(), wrapper.getHeight());
} else {
craftingGridHelper.setInputs(guiItemStacks, inputs);
recipeLayout.setShapeless();
}
guiItemStacks.set(craftOutputSlot, outputs.get(0));
}
}