Interface CRecipe
-
- All Implemented Interfaces:
public interface CRecipeThis interface's implementing types can be used as recipes for CustomCrafter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumCRecipe.TypeType of CRecipe
-
Method Summary
Modifier and Type Method Description UnitisValidRecipe()Validates this CRecipe. List<MatchGroup>matchGroups()Groups of recipe slots used by CRecipe.Type.SHAPELESS matching. IntegerrequiresInputItemAmountMin()Minimal requires input items amountDefault implementation derives this from matchGroups (sum of each group's MatchGroup.min). IntegerrequiresInputItemAmountMax()Maximum requires input items amount. BooleangetRecipePredicateResults(CRecipePredicate.Context context, Boolean whenEmptyDefault)Returns CRecipePredicate inspection result Pair<Integer, CRecipePredicate>firstFailedRecipePredicate(CRecipePredicate.Context context)Returns the first CRecipePredicate that rejects context, or nullwhen all of them pass.CompletableFuture<Boolean>asyncGetRecipePredicateResults(CRecipePredicate.Context context, Boolean whenEmptyDefault)Returns CRecipePredicate inspection result on async. List<ItemStack>getResults(ResultSupplier.Context context)Returns results of suppliers made CompletableFuture<List<ItemStack>>asyncGetResults(ResultSupplier.Context context)Returns results of suppliers made asynchronously. IntegergetTimes(Map<CoordinateComponent, ItemStack> map, MappedRelation relation, Boolean shift, Boolean withoutMass)Returns the minimum craft count calculated from input item amounts and recipe requirements. abstract StringgetName()Name of this recipe. abstract Map<CoordinateComponent, CMatter>getItems()Mapping of CMatter to their coordinates on the crafting slots. abstract List<CRecipePredicate>getPredicates()List of CRecipePredicate that run during recipe matching. abstract List<ResultSupplier>getResults()List of ResultSupplier that provide items to players. abstract CRecipe.TypegetType()Type of this recipe. -
-
Method Detail
-
isValidRecipe
Unit isValidRecipe()
Validates this CRecipe.
CRecipe's default implementation checks below conditions.
CRecipe.items size is in range 1 to 36
All contained CMatter pass CMatter.isValidMatter
// (Usage) val recipe: CRecipe = ~~~ recipe.isValidRecipe()- Since:
5.0.15
-
matchGroups
List<MatchGroup> matchGroups()
Groups of recipe slots used by CRecipe.Type.SHAPELESS matching.
Each MatchGroup states how many of its members must actually be filled by an input item; a slot whose coordinate is not covered is simply never assigned an input, no
Material.AIRplaceholder candidate required (contrast GroupRecipe).The default implementation treats every entry of items as its own mandatory group (
min == max == 1), which reproduces plain full-matching SHAPELESS behaviour and keeps requiresInputItemAmountMin / requiresInputItemAmountMax correct without any extra overrides. Implementations that override this to express optional/aggregate slots (e.g. ShapelessGroupRecipe) do not need to separately override those two methods.Ignored by CRecipe.Type.SHAPED matching, which stays purely coordinate-based.
Contract: every MatchGroup.members coordinate returned here must be a key of items; violating this causes an exception during search.
- Returns:
List Match groups covering (all or part of) items.
- Since:
5.3.0
-
requiresInputItemAmountMin
Integer requiresInputItemAmountMin()
Minimal requires input items amount
Default implementation derives this from matchGroups (sum of each group's MatchGroup.min).
- Returns:
Int Minimal requires input items amount
- Since:
5.0.15
-
requiresInputItemAmountMax
Integer requiresInputItemAmountMax()
Maximum requires input items amount. Inclusive
Default implementation derives this from matchGroups (sum of each group's MatchGroup.max).
- Returns:
Int Maximum requires input items amount
- Since:
5.0.15
-
getRecipePredicateResults
Boolean getRecipePredicateResults(CRecipePredicate.Context context, Boolean whenEmptyDefault)
Returns CRecipePredicate inspection result
- Parameters:
context- Context of inspectionwhenEmptyDefault- Result returned when CRecipe.predicates is null or empty (default = true)- Returns:
Boolean Result of run tests
- Since:
5.0.17
-
firstFailedRecipePredicate
Pair<Integer, CRecipePredicate> firstFailedRecipePredicate(CRecipePredicate.Context context)
Returns the first CRecipePredicate that rejects context, or
nullwhen all of them pass.Evaluates predicates in order and stops at the first failure, exactly as getRecipePredicateResults does, so this can be used in its place when the caller needs to report which predicate failed rather than only whether one did. The returned index is the position within predicates and identifies a predicate that did not override CRecipePredicate.name.
- Parameters:
context- Context of inspection- Returns:
Pair The failing predicate's index paired with the predicate itself, or
nullwhen nothing failed- Since:
5.3.0
-
asyncGetRecipePredicateResults
CompletableFuture<Boolean> asyncGetRecipePredicateResults(CRecipePredicate.Context context, Boolean whenEmptyDefault)
Returns CRecipePredicate inspection result on async.
Each predicate runs on a virtual thread (off the main thread). Even if the given CRecipePredicate.Context.asyncContext is null, an async context is set internally before predicates run.
- Parameters:
context- Context of inspectionwhenEmptyDefault- Result returned when CRecipe.predicates is null or empty (default = true)- Returns:
CompletableFuture Result of run tests
- Since:
5.0.17
-
getResults
List<ItemStack> getResults(ResultSupplier.Context context)
Returns results of suppliers made
- Parameters:
context- Context of ResultSupplier- Returns:
List Generated items list. If no item supplier applied, returns an empty list.
-
asyncGetResults
CompletableFuture<List<ItemStack>> asyncGetResults(ResultSupplier.Context context)
Returns results of suppliers made asynchronously.
Each supplier runs on a virtual thread (off the main thread). Even if ResultSupplier.Context.asyncContext is null, an async context is set internally before suppliers run.
- Parameters:
context- Context of ResultSupplier- Returns:
CompletableFuture Future of generated items list. If no supplier applied, completes with an empty list.
-
getTimes
Integer getTimes(Map<CoordinateComponent, ItemStack> map, MappedRelation relation, Boolean shift, Boolean withoutMass)
Returns the minimum craft count calculated from input item amounts and recipe requirements.
- Parameters:
map- Input items mappingrelation- Coordinate relations in input items and recipe mattersshift- Use Shift-Key (Batch Crafting) or notwithoutMass- Exclude CMatter.anyAmount-marked matters from the calculation or not- Returns:
Int Minimum craft count. Returns 1 if no constraining matter exists.
- Since:
5.0.10
-
getItems
abstract Map<CoordinateComponent, CMatter> getItems()
Mapping of CMatter to their coordinates on the crafting slots.
-
getPredicates
abstract List<CRecipePredicate> getPredicates()
List of CRecipePredicate that run during recipe matching.
nullor empty means no additional conditions.
-
getResults
abstract List<ResultSupplier> getResults()
List of ResultSupplier that provide items to players.
nullor empty means no items are produced.
-
getType
abstract CRecipe.Type getType()
Type of this recipe. See CRecipe.Type.
-
-
-
-