-
Notifications
You must be signed in to change notification settings - Fork 18
/
CauldronContents.java
67 lines (57 loc) · 1.68 KB
/
CauldronContents.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
package knightminer.inspirations.recipes.recipe.cauldron.contents;
import knightminer.inspirations.library.recipe.cauldron.contents.CauldronContentType;
import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents;
import net.minecraft.util.ResourceLocation;
import java.util.Optional;
/**
* Content type implementation. Mainly out of the library as no one should be directly constructing this class
* @param <C> Content value type
*/
public class CauldronContents<C> implements ICauldronContents {
private final CauldronContentType<C> type;
private final C value;
/**
* Creates a new instance
* @param type Content type
* @param value Content value
*/
public CauldronContents(CauldronContentType<C> type, C value) {
this.type = type;
this.value = value;
}
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(CauldronContentType<T> type) {
if (type == this.type) {
return Optional.of((T)this.value);
}
return type.getOverrideValue(this);
}
@Override
public CauldronContentType<?> getType() {
return type;
}
@Override
public ResourceLocation getTextureName() {
return type.getTexture(value);
}
@Override
public int getTintColor() {
return type.getColor(value);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CauldronContents)) {
return false;
}
CauldronContents<?> contents = (CauldronContents<?>)other;
return this.type == contents.type && this.value.equals(contents.value);
}
@Override
public int hashCode() {
return 31 * type.hashCode() + value.hashCode();
}
}