Package wtf.choco.alchema.crafting
Interface CauldronIngredient
- All Known Implementing Classes:
CauldronIngredientEntityEssence
,CauldronIngredientItemStack
,CauldronIngredientMaterial
public interface CauldronIngredient
Represents an ingredient usable in an
AlchemicalCauldron
defined by a
CauldronRecipe
.
CauldronIngredient is meant to be extendible. Should a plugin choose to add a new
implementation of CauldronIngredient, the CauldronIngredientAddEvent
should
be listened to in order to inject custom implementations into a cauldron based on
the item being thrown in. All implementations need to be registered with
CauldronRecipeRegistry.registerIngredientType(NamespacedKey, Function)
with the getKey()
matching that of the registered key.
It is advised that implementations also implement Object.hashCode()
,
Object.equals(Object)
and Object.toString()
. While not required,
it may improve the performance of hash-based collections.
- Author:
- Parker Hawke - Choco
-
Method Summary
Modifier and Type Method Description @NotNull CauldronIngredient
adjustAmountBy(int amount)
Return a new cauldron ingredient with the amount changed by the specified amount.@Nullable org.bukkit.inventory.ItemStack
asItemStack()
Get this ingredient represented as anItemStack
, if possible.default @NotNull java.util.List<@NotNull org.bukkit.entity.Item>
drop(@NotNull AlchemicalCauldron cauldron, @NotNull org.bukkit.World world, @NotNull org.bukkit.Location location)
Drop this ingredient as one or moreItem
from the provided cauldron.int
getAmount()
Get the amount of this ingredient.@NotNull org.bukkit.NamespacedKey
getKey()
Get the key for this ingredient type.boolean
isSimilar(@NotNull CauldronIngredient other)
Check whether this ingredient is similar to the provided ingredient.@NotNull CauldronIngredient
merge(@NotNull CauldronIngredient other)
Merge this ingredient with another ingredient.@NotNull com.google.gson.JsonObject
toJson()
Serialize this ingredient to aJsonObject
.
-
Method Details
-
getKey
@NotNull @NotNull org.bukkit.NamespacedKey getKey()Get the key for this ingredient type.- Returns:
- the ingredient key
-
getAmount
int getAmount()Get the amount of this ingredient.- Returns:
- the ingredient amount
-
asItemStack
@Nullable @Nullable org.bukkit.inventory.ItemStack asItemStack()Get this ingredient represented as anItemStack
, if possible.- Returns:
- the item stack. null if no item stack representation
-
isSimilar
Check whether this ingredient is similar to the provided ingredient. The ingredient amount is not taken into consideration when comparing.- Parameters:
other
- the other ingredient against which to compare- Returns:
- true if similar, false otherwise
-
merge
Merge this ingredient with another ingredient. The result of this method should be a new ingredient with the combined amounts of this ingredient and the one passed.- Parameters:
other
- the other ingredient- Returns:
- the merged ingredient
-
adjustAmountBy
Return a new cauldron ingredient with the amount changed by the specified amount. The amount can be either negative or positive but must not result in a negative or zero amount (i.e. ifgetAmount() - amount
is 0 or negative, an exception will be thrown).- Parameters:
amount
- the change in amount to apply- Returns:
- the new ingredient
-
drop
@NotNull default @NotNull java.util.List<@NotNull org.bukkit.entity.Item> drop(@NotNull @NotNull AlchemicalCauldron cauldron, @NotNull @NotNull org.bukkit.World world, @NotNull @NotNull org.bukkit.Location location)Drop this ingredient as one or moreItem
from the provided cauldron.Default implementation of this method will, if not null, drop the result of
asItemStack()
.- Parameters:
cauldron
- the cauldron from which to drop the ingredientsworld
- the world in which the cauldron resideslocation
- the location at which the items should be dropped- Returns:
- the list of Item entities that were dropped. If none, the returned list should be empty, never null
-
toJson
@NotNull @NotNull com.google.gson.JsonObject toJson()Serialize this ingredient to aJsonObject
.- Returns:
- the serialized json
-