/
ItemStackElement.java
59 lines (46 loc) · 1.37 KB
/
ItemStackElement.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
package mezz.jei.util;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Locale;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import mezz.jei.api.JEIManager;
/**
* For getting properties of ItemStacks efficiently
*/
public class ItemStackElement {
@Nonnull
private final ItemStack itemStack;
@Nonnull
private final String localizedName;
@Nonnull
private final String modName;
@Nullable
public static ItemStackElement create(@Nonnull ItemStack itemStack) {
try {
return new ItemStackElement(itemStack);
} catch (RuntimeException e) {
Log.warning("Found broken itemStack.", e);
return null;
}
}
private ItemStackElement(@Nonnull ItemStack itemStack) {
this.itemStack = itemStack;
this.localizedName = itemStack.getDisplayName().toLowerCase();
String modId = GameRegistry.findUniqueIdentifierFor(itemStack.getItem()).modId;
String modName = JEIManager.itemRegistry.getModNameForItem(itemStack.getItem());
this.modName = modId.toLowerCase(Locale.ENGLISH) + ' ' + modName.toLowerCase(Locale.ENGLISH);
}
@Nonnull
public ItemStack getItemStack() {
return itemStack;
}
@Nonnull
public String getLocalizedName() {
return localizedName;
}
@Nonnull
public String getModName() {
return modName;
}
}