Interface Recipe
-
- All Superinterfaces:
Keyed
,ResourceKeyed
- All Known Subinterfaces:
CookingRecipe
,CraftingRecipe
,ShapedCraftingRecipe
,ShapelessCraftingRecipe
,SmithingRecipe
,SpecialCraftingRecipe
,StoneCutterRecipe
public interface Recipe extends ResourceKeyed
A general interface for recipes.Currently supported recipe types are:
ShapelessCraftingRecipe
for recipes with simple ingredients/result without pattern in aCraftingInventory
ShapedCraftingRecipe
for recipes with simple ingredients/result in a pattern in aCraftingInventory
SpecialCraftingRecipe
for recipes with complex ingredients and result in aCraftingInventory
CookingRecipe
for recipes inFurnace
,BlastFurnace
,Smoker
andCampfire
StoneCutterRecipe
for recipes in aBlockTypes.STONECUTTER
blockSmithingRecipe
for recipes in aBlockTypes.SMITHING_TABLE
block
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ItemStackSnapshot
exemplaryResult()
A general result of this recipe.List<Ingredient>
ingredients()
Gets the ingredients for this recipe.boolean
isDynamic()
Returns true if the recipe is dynamic.boolean
isValid(Inventory inventory, ServerWorld world)
Checks if the given inventory fits the required constraints to make a valid recipeList<ItemStackSnapshot>
remainingItems(Inventory inventory)
The remaining items result of this recipe.ItemStackSnapshot
result(Inventory inventory)
The result of this recipe.default Optional<RecipeResult>
result(Inventory inventory, ServerWorld world)
Returns theRecipeResult
for the given inventory and world.RecipeType<? extends Recipe>
type()
Gets theRecipeType
of this recipe.-
Methods inherited from interface org.spongepowered.api.ResourceKeyed
key
-
-
-
-
Method Detail
-
isValid
boolean isValid(Inventory inventory, ServerWorld world)
Checks if the given inventory fits the required constraints to make a valid recipe- Parameters:
inventory
- The inventory to check for validityworld
- The world this recipe would be used in- Returns:
- True if the given input matches this recipe's requirements
-
result
ItemStackSnapshot result(Inventory inventory)
The result of this recipe. This method should only be called ifisValid(Inventory, ServerWorld)
returnstrue
.This method is preferred over the
exemplaryResult()
method, as it may customize the result further depending on the context.- Parameters:
inventory
- The input inventory- Returns:
- The result of this recipe
-
exemplaryResult
ItemStackSnapshot exemplaryResult()
A general result of this recipe. This result may be customized depending on the context. Seeresult(Inventory)
- Returns:
- The exemplary result of this recipe
-
remainingItems
List<ItemStackSnapshot> remainingItems(Inventory inventory)
The remaining items result of this recipe. This method should only be called ifisValid(Inventory, ServerWorld)
returnstrue
.A list of items to be added to the inventory of the player when they craft the result. For example, if a player crafts a
ItemTypes.CAKE
, the empty buckets are returned to their inventory.- Parameters:
inventory
- The input inventory- Returns:
- The list of items to be added to the inventory of the player when the recipe has been fulfilled (possibly empty)
-
result
default Optional<RecipeResult> result(Inventory inventory, ServerWorld world)
Returns theRecipeResult
for the given inventory and world.Returns
Optional.empty()
if the arguments do not satisfyisValid(Inventory, ServerWorld)
.- Parameters:
inventory
- The input inventoryworld
- The world this recipe would be used in- Returns:
- A
RecipeResult
if the arguments satisfyisValid(Inventory, ServerWorld)
, orOptional.empty()
if not
-
ingredients
List<Ingredient> ingredients()
Gets the ingredients for this recipe.- Returns:
- An unmodifiable list of the ingredients.
-
isDynamic
boolean isDynamic()
Returns true if the recipe is dynamic.Dynamic recipes are not displayed in the recipe book.
- Returns:
- Whether this recipe is dynamic.
-
type
RecipeType<? extends Recipe> type()
Gets theRecipeType
of this recipe.- Returns:
- The recipe type.
-
-