/
CraftingRecipeCategory.java
113 lines (92 loc) · 4.17 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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.BlankRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import mezz.jei.api.recipe.wrapper.ICraftingRecipeWrapper;
import mezz.jei.api.recipe.wrapper.ICustomCraftingRecipeWrapper;
import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper;
import mezz.jei.util.Translator;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public class CraftingRecipeCategory extends BlankRecipeCategory<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 = new ResourceLocation("minecraft", "textures/gui/container/crafting_table.png");
background = guiHelper.createDrawable(location, 29, 16, 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 IDrawable getBackground() {
return background;
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, IRecipeWrapper recipeWrapper) {
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 IShapedCraftingRecipeWrapper) {
IShapedCraftingRecipeWrapper wrapper = (IShapedCraftingRecipeWrapper) recipeWrapper;
craftingGridHelper.setInput(guiItemStacks, wrapper.getInputs(), wrapper.getWidth(), wrapper.getHeight());
craftingGridHelper.setOutput(guiItemStacks, wrapper.getOutputs());
} else if (recipeWrapper instanceof ICraftingRecipeWrapper) {
craftingGridHelper.setInput(guiItemStacks, recipeWrapper.getInputs());
craftingGridHelper.setOutput(guiItemStacks, ((ICraftingRecipeWrapper) recipeWrapper).getOutputs());
} else {
craftingGridHelper.setInput(guiItemStacks, recipeWrapper.getInputs());
guiItemStacks.setFromRecipe(craftOutputSlot, recipeWrapper.getOutputs());
}
}
@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<ItemStack> outputs = ingredients.getOutputs(ItemStack.class);
if (recipeWrapper instanceof IShapedCraftingRecipeWrapper) {
IShapedCraftingRecipeWrapper wrapper = (IShapedCraftingRecipeWrapper) recipeWrapper;
craftingGridHelper.setInputStacks(guiItemStacks, inputs, wrapper.getWidth(), wrapper.getHeight());
craftingGridHelper.setOutput(guiItemStacks, outputs);
} else {
craftingGridHelper.setInputStacks(guiItemStacks, inputs);
craftingGridHelper.setOutput(guiItemStacks, outputs);
}
}
}