diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java index fb082afb..a131378c 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java @@ -31,4 +31,9 @@ public ResourceLocation getTextureName() { public int getTintColor() { return -1; } + + @Override + public boolean matches(CauldronContentType type, T value) { + return type == CauldronContentTypes.EMPTY; + } } diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java index 7477dc8a..e71a09e2 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java @@ -37,4 +37,34 @@ public interface ICauldronContents { * @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 Content class + * @return True if they match + */ + boolean matches(CauldronContentType 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 Content class + * @return True if get would return this value + */ + default boolean contains(CauldronContentType type, T value) { + return get(type).map(value::equals).orElse(false); + } } diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java index 8d0e2801..de3a0d8b 100644 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java +++ b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java @@ -48,16 +48,21 @@ public int getTintColor() { return type.getColor(value); } + @Override + public boolean matches(CauldronContentType type, T value) { + return this.type == type && this.value == value; + } + @Override public boolean equals(Object other) { if (this == other) { return true; } - if (!(other instanceof CauldronContents)) { + if (!(other instanceof ICauldronContents)) { return false; } - CauldronContents contents = (CauldronContents)other; - return this.type == contents.type && this.value.equals(contents.value); + ICauldronContents contents = (ICauldronContents)other; + return contents.matches(type, value); } @Override