/
GuiIngredientGroup.java
69 lines (59 loc) · 1.88 KB
/
GuiIngredientGroup.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
package mezz.jei.gui.ingredients;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.client.Minecraft;
import mezz.jei.api.gui.IGuiIngredientGroup;
import mezz.jei.gui.Focus;
public abstract class GuiIngredientGroup<V, T extends GuiIngredient<V>> implements IGuiIngredientGroup<V> {
@Nonnull
protected final Map<Integer, T> guiIngredients = new HashMap<>();
@Nonnull
protected Focus focus = new Focus();
@Nonnull
protected Focus.Mode focusMode = Focus.Mode.OUTPUT;
/**
* If focus is set and any of the guiIngredients contains focus
* they will only display focus instead of rotating through all their values.
*/
public void setFocus(@Nonnull Focus focus, @Nonnull Focus.Mode focusMode) {
this.focus = focus;
this.focusMode = focusMode;
}
@Override
public void set(int slotIndex, @Nonnull Collection<V> values) {
guiIngredients.get(slotIndex).set(values, focus, focusMode);
}
@Override
public void set(int slotIndex, @Nonnull V value) {
guiIngredients.get(slotIndex).set(value, focus, focusMode);
}
@Nonnull
public Map<Integer, T> getGuiIngredients() {
return guiIngredients;
}
@Nullable
public Focus getFocusUnderMouse(int mouseX, int mouseY) {
for (T widget : guiIngredients.values()) {
if (widget != null && widget.isMouseOver(mouseX, mouseY)) {
return new Focus(widget.get());
}
}
return null;
}
public void draw(@Nonnull Minecraft minecraft, int mouseX, int mouseY) {
T hovered = null;
for (T ingredient : guiIngredients.values()) {
if (hovered == null && ingredient.isMouseOver(mouseX, mouseY)) {
hovered = ingredient;
} else {
ingredient.draw(minecraft);
}
}
if (hovered != null) {
hovered.drawHovered(minecraft, mouseX, mouseY);
}
}
}