/
CraftingGridHelper.java
86 lines (73 loc) · 2.29 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
package mezz.jei.gui;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import mezz.jei.api.gui.ICraftingGridHelper;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.util.StackUtil;
public class CraftingGridHelper implements ICraftingGridHelper {
private final int craftInputSlot1;
private final int craftOutputSlot;
public CraftingGridHelper(int craftInputSlot1, int craftOutputSlot) {
this.craftInputSlot1 = craftInputSlot1;
this.craftOutputSlot = craftOutputSlot;
}
@Override
public void setInput(@Nonnull IGuiItemStackGroup guiItemStacks, @Nonnull 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
public void setInput(@Nonnull IGuiItemStackGroup guiItemStacks, @Nonnull List input, int width, int height) {
for (int i = 0; i < input.size(); i++) {
Object recipeItem = input.get(i);
int index;
if (width == 1) {
if (height == 3) {
index = (i * 3) + 1;
} else if (height == 2) {
index = (i * 3) + 4;
} else {
index = 4;
}
} else if (height == 1) {
index = i + 6;
} else if (width == 2) {
index = i;
if (i > 1) {
index++;
if (i > 3) {
index++;
}
}
} else if (height == 2) {
index = i + 3;
} else {
index = i;
}
if (recipeItem instanceof ItemStack) {
List<ItemStack> itemStacks = Collections.singletonList((ItemStack) recipeItem);
setInput(guiItemStacks, index, itemStacks);
} else if (recipeItem instanceof Iterable) {
List<ItemStack> itemStacks = StackUtil.toItemStackList((Iterable) recipeItem);
setInput(guiItemStacks, index, itemStacks);
}
}
}
@Override
public void setOutput(@Nonnull IGuiItemStackGroup guiItemStacks, @Nonnull List<ItemStack> output) {
guiItemStacks.set(craftOutputSlot, output);
}
private void setInput(@Nonnull IGuiItemStackGroup guiItemStacks, int inputIndex, @Nonnull Collection<ItemStack> input) {
guiItemStacks.set(craftInputSlot1 + inputIndex, input);
}
}