/
CraftingGridHelper.java
110 lines (94 loc) · 2.82 KB
/
CraftingGridHelper.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
package mezz.jei.gui;
import java.util.Collection;
import java.util.List;
import mezz.jei.api.gui.ICraftingGridHelper;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.api.recipe.IStackHelper;
import net.minecraft.item.ItemStack;
public class CraftingGridHelper implements ICraftingGridHelper {
private final IStackHelper stackHelper;
private final int craftInputSlot1;
private final int craftOutputSlot;
public CraftingGridHelper(IStackHelper stackHelper, int craftInputSlot1, int craftOutputSlot) {
this.stackHelper = stackHelper;
this.craftInputSlot1 = craftInputSlot1;
this.craftOutputSlot = craftOutputSlot;
}
@Override
public void setInputStacks(IGuiItemStackGroup guiItemStacks, List<List<ItemStack>> input) {
int width, height;
if (input.size() > 4) {
width = height = 3;
} else if (input.size() > 1) {
width = height = 2;
} else {
width = height = 1;
}
setInputStacks(guiItemStacks, input, width, height);
}
@Override
public void setInputStacks(IGuiItemStackGroup guiItemStacks, List<List<ItemStack>> input, int width, int height) {
for (int i = 0; i < input.size(); i++) {
List<ItemStack> recipeItem = input.get(i);
int index = getCraftingIndex(i, width, height);
setInput(guiItemStacks, index, recipeItem);
}
}
@Override
@Deprecated
public void setInput(IGuiItemStackGroup guiItemStacks, List input) {
int width, height;
if (input.size() > 4) {
width = height = 3;
} else if (input.size() > 1) {
width = height = 2;
} else {
width = height = 1;
}
setInput(guiItemStacks, input, width, height);
}
@Override
@Deprecated
public void setInput(IGuiItemStackGroup guiItemStacks, List input, int width, int height) {
for (int i = 0; i < input.size(); i++) {
Object recipeItem = input.get(i);
int index = getCraftingIndex(i, width, height);
List<ItemStack> itemStacks = stackHelper.toItemStackList(recipeItem);
setInput(guiItemStacks, index, itemStacks);
}
}
private int getCraftingIndex(int i, int width, int height) {
int index;
if (width == 1) {
if (height == 3) {
index = (i * 3) + 1;
} else if (height == 2) {
index = (i * 3) + 1;
} else {
index = 4;
}
} else if (height == 1) {
index = i + 3;
} else if (width == 2) {
index = i;
if (i > 1) {
index++;
if (i > 3) {
index++;
}
}
} else if (height == 2) {
index = i + 3;
} else {
index = i;
}
return index;
}
@Override
public void setOutput(IGuiItemStackGroup guiItemStacks, List<ItemStack> output) {
guiItemStacks.set(craftOutputSlot, output);
}
private void setInput(IGuiItemStackGroup guiItemStacks, int inputIndex, Collection<ItemStack> input) {
guiItemStacks.set(craftInputSlot1 + inputIndex, input);
}
}