/
Focus.java
52 lines (45 loc) · 1.34 KB
/
Focus.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
package mezz.jei.gui;
import mezz.jei.Internal;
import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.util.ErrorUtil;
import mezz.jei.util.LegacyUtil;
import net.minecraft.item.ItemStack;
public class Focus<V> implements IFocus<V> {
private final Mode mode;
private final V value;
public Focus(Mode mode, V value) {
this.mode = mode;
IIngredientHelper<V> ingredientHelper = Internal.getIngredientRegistry().getIngredientHelper(value);
this.value = LegacyUtil.getIngredientCopy(value, ingredientHelper);
checkInternal(this);
}
@Override
public V getValue() {
return value;
}
@Override
public Mode getMode() {
return mode;
}
/**
* Make sure any IFocus coming in through API calls is validated and turned into JEI's Focus.
*/
public static <V> Focus<V> check(IFocus<V> focus) {
ErrorUtil.checkNotNull(focus, "focus");
if (focus instanceof Focus) {
checkInternal(focus);
return (Focus<V>) focus;
}
return new Focus<V>(focus.getMode(), focus.getValue());
}
private static void checkInternal(IFocus<?> focus) {
ErrorUtil.checkNotNull(focus.getMode(), "focus mode");
Object value = focus.getValue();
ErrorUtil.checkNotNull(value, "focus value");
if (value instanceof ItemStack) {
ItemStack itemStack = (ItemStack) value;
ErrorUtil.checkNotEmpty(itemStack);
}
}
}