/
CauldronContentHelper.java
84 lines (72 loc) · 2.55 KB
/
CauldronContentHelper.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
package knightminer.inspirations.plugins.jei.cauldron;
import knightminer.inspirations.Inspirations;
import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes;
import knightminer.inspirations.library.recipe.cauldron.contents.CauldronContentType;
import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents;
import mezz.jei.api.ingredients.IIngredientHelper;
import javax.annotation.Nullable;
/**
* Content helper for all cauldron ingredient types
*/
public class CauldronContentHelper implements IIngredientHelper<ICauldronContents> {
public static final CauldronContentHelper INSTANCE = new CauldronContentHelper();
private CauldronContentHelper() {}
/**
* Helper that aliases some types as another in JEI
* @param contents Contents containing type
* @return Aliased type if relevant
*/
private static CauldronContentType<?> getType(ICauldronContents contents) {
// TODO: consider making this more generic so addons can add more aliases
CauldronContentType<?> type = contents.getType();
// if unfermented, treat as potion for recipe lookups
if (type == CauldronContentTypes.UNFERMENTED_POTION) {
return CauldronContentTypes.POTION;
}
return type;
}
@Nullable
@Override
public ICauldronContents getMatch(Iterable<ICauldronContents> options, ICauldronContents match) {
CauldronContentType<?> type = getType(match);
String name = match.getName();
for (ICauldronContents content : options) {
if (type == getType(content) && name.equals(content.getName())) {
return content;
}
}
return null;
}
@Override
public ICauldronContents copyIngredient(ICauldronContents contents) {
return contents;
}
@Override
public String getDisplayName(ICauldronContents contents) {
return contents.getDisplayName().getString();
}
@Override
public String getUniqueId(ICauldronContents contents) {
return CauldronContentTypes.getName(getType(contents)).toString() + ":" + contents.getName();
}
@Override
public String getWildcardId(ICauldronContents contents) {
return getUniqueId(contents);
}
@Override
public String getResourceId(ICauldronContents contents) {
return contents.getName();
}
@Override
public String getModId(ICauldronContents contents) {
String modId = contents.getModId();
return modId == null ? Inspirations.modID : modId;
}
@Override
public String getErrorInfo(@Nullable ICauldronContents contents) {
if (contents == null) {
return "null";
}
return getUniqueId(contents);
}
}