-
Notifications
You must be signed in to change notification settings - Fork 18
/
NamedContentType.java
43 lines (37 loc) · 1.08 KB
/
NamedContentType.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
package knightminer.inspirations.library.recipe.cauldron.contents;
import net.minecraft.util.IStringSerializable;
import javax.annotation.Nullable;
import java.util.function.Function;
/**
* Cauldron content type based on an {@link IStringSerializable} object, typically an enum
* @param <T> Type class
*/
public abstract class NamedContentType<T extends IStringSerializable> extends CauldronContentType<T> {
private final Function<String, ? extends T> lookup;
/**
* Creates a new type instance
* @param lookup Function to lookup a value from a string
*/
public NamedContentType(Function<String,? extends T> lookup) {
this.lookup = lookup;
}
/**
* Gets the name of the given value for writing to JSON and NBT
* @param value Value
* @return Name of the value
*/
@Override
public String getName(T value) {
return value.getString();
}
/**
* Gets the entry for a given value
* @param name Name
* @return Entry, or null if missing
*/
@Override
@Nullable
public T getEntry(String name) {
return lookup.apply(name);
}
}