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:
ShapelessCraftingRecipefor recipes with simple ingredients/result without pattern in aCraftingInventoryShapedCraftingRecipefor recipes with simple ingredients/result in a pattern in aCraftingInventorySpecialCraftingRecipefor recipes with complex ingredients and result in aCraftingInventoryCookingRecipefor recipes inFurnace,BlastFurnace,SmokerandCampfireStoneCutterRecipefor recipes in aBlockTypes.STONECUTTERblockSmithingRecipefor recipes in aBlockTypes.SMITHING_TABLEblock
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ItemStackSnapshotexemplaryResult()A general result of this recipe.List<Ingredient>ingredients()Gets the ingredients for this recipe.booleanisDynamic()Returns true if the recipe is dynamic.booleanisValid(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.ItemStackSnapshotresult(Inventory inventory)The result of this recipe.default Optional<RecipeResult>result(Inventory inventory, ServerWorld world)Returns theRecipeResultfor the given inventory and world.RecipeType<? extends Recipe>type()Gets theRecipeTypeof 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 theRecipeResultfor 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
RecipeResultif 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 theRecipeTypeof this recipe.- Returns:
- The recipe type.
-
-