/
ICauldronContents.java
80 lines (65 loc) · 2.25 KB
/
ICauldronContents.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
package knightminer.inspirations.library.recipe.cauldron.contents;
import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.ResourceLocation;
import java.util.Optional;
/**
* Base interface for all cauldron contents
*/
public interface ICauldronContents {
/**
* Gets this value as the given type
* @param type Type to get
* @param <T> Type of return
* @return Value, or empty optional if this does not have the given type
*/
<T> Optional <T> get(CauldronContentType<T> type);
/**
* Gets the main type of these contents, used for serializing
* @return Main content type
*/
CauldronContentType<?> getType();
/* Display */
/**
* Gets the name of the texture for these contents. Should generally delegate to the type
* @return Texture location for this contents
*/
ResourceLocation getTextureName();
/**
* Gets the color for this content type for tinting. Should generally delegate to the type
* @return Tint color
*/
int getTintColor();
/* Mapping */
/**
* Checks if these cauldron contents match the given arguments. Use this for {@link #equals(Object)} implementations
* @param type Content type
* @param value Value of the content
* @param <T> Content class
* @return True if they match
*/
<T> boolean matches(CauldronContentType<T> type, T value);
/**
* For consistency, hash code should be {@code 31 * type.hashCode() + value.hashCode()}
* @return Hash code for the given type and value
*/
@Override
int hashCode();
/**
* Checks if the contents contain the given value. Unlike {@link #matches(CauldronContentType, Object)}, supports overrides.
* @param type Content type
* @param value Value of the content
* @param <T> Content class
* @return True if get would return this value
*/
default <T> boolean contains(CauldronContentType<T> type, T value) {
return get(type).map(value::equals).orElse(false);
}
/**
* If true, this is a simple content type, meaning it can be held in the vanilla cauldron
* @return True if the content type is simple
*/
default boolean isSimple() {
return contains(CauldronContentTypes.FLUID, Fluids.WATER);
}
}