-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
58 lines (50 loc) · 1.6 KB
/
Item.java
File metadata and controls
58 lines (50 loc) · 1.6 KB
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
package game;
import java.util.List;
import java.util.ArrayList;
public class Item {
public Item[] recipe;
public String displayName;
public static List<Item> registeredItems = new ArrayList<>();
public static List<Item> craftableItems = new ArrayList<>();
// If recipe returns Null, there is no way to synthesize the item
public Item(String displayName, Item[] recipe) {
this.recipe = recipe;
this.displayName = displayName;
}
public static void itemReg(Item newItem) {
registeredItems.add(newItem);
if (newItem.recipe != null) {
craftableItems.add(newItem);
}
}
public static Item stringToDisplay(String checkName) {
for (int i = 0; i < registeredItems.size(); i++) {
registeredItems.get(i);
if (registeredItems.get(i).displayName.equals(checkName)) {
return registeredItems.get(i);
}
}
return null;
}
public static String displayNameToItemName(String item) {
String[] splitString = item.split(" ");
if (item != validIDs.stick.displayName) {
String strItemName = splitString[0] + "_" + splitString[1];
return strItemName.toLowerCase();
} else if (item == validIDs.stick.displayName) {
return validIDs.stick.displayName.toLowerCase();
}
return null;
}
@SuppressWarnings("unused")
public static Item stringToItem(String checkName) {
for (int i = 0; i < craftableItems.size(); i++) {
Item currentItem = craftableItems.get(i);
String registeredItem = displayNameToItemName(currentItem.displayName);
if (checkName.equals(registeredItem)) {
return currentItem;
}
}
return null;
}
}