Class AdjacentRecipe
-
- All Implemented Interfaces:
-
io.github.sakaki_aruka.customcrafter.recipe.CRecipe
public final class AdjacentRecipe implements CRecipe
A semi-shaped recipe that sits between fully shaped and fully shapeless recipes.
Like a shapeless recipe, items may be placed anywhere in the crafting grid with no fixed positional constraints. Unlike a shapeless recipe, the directions in which neighbouring items may appear are restricted by RelationType:
RelationType.CROSS: all neighbouring items must be directly above, below, left, or right; diagonally adjacent items are forbidden (↑ ↓ ← → only).
RelationType.DIAGONAL: all neighbouring items must be at a diagonal corner; cross-adjacent items are forbidden (↖ ↗ ↙ ↘ only).
RelationType.BOTH: all eight surrounding directions are allowed; no restriction is applied.
Two items are considered "neighbours" if both their x-distance and y-distance are ≤ 1 (i.e. they fall inside the 3×3 area centred on either item). The predicate fails if any item has a neighbour in a direction not included in the chosen RelationType.
Valid (no pair of items is diagonally adjacent):
_ _ # _ _ _ _ _ # _ _ _ _ _ # # # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _Invalid (the
#at(0,0)and the#at(1,1)are diagonal neighbours):# _ _ _ _ _ ← (0,0) # # _ _ _ _ ← (0,1) and (1,1): (0,0) is diagonal to (1,1) → forbidden for CROSS _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _At least 2 items are required; isValidRecipe rejects recipes with fewer items.
- Since:
5.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumAdjacentRecipe.RelationTypeDefines which neighbouring directions are permitted between placed items.
-
Field Summary
Fields Modifier and Type Field Description private final Stringnameprivate final AdjacentRecipe.RelationTyperelationTypeprivate final List<ResultSupplier>resultsprivate final Map<CoordinateComponent, CMatter>itemsprivate final CRecipe.Typetypeprivate final List<CRecipePredicate>predicates
-
Constructor Summary
Constructors Constructor Description AdjacentRecipe(String name, List<CMatter> matters, AdjacentRecipe.RelationType relationType, List<CRecipePredicate> customPredicates, List<ResultSupplier> results)AdjacentRecipe(String name, List<CMatter> matters, AdjacentRecipe.RelationType relationType, List<CRecipePredicate> customPredicates)AdjacentRecipe(String name, List<CMatter> matters, AdjacentRecipe.RelationType relationType)AdjacentRecipe(String name, List<CMatter> matters)
-
Method Summary
Modifier and Type Method Description StringgetName()final AdjacentRecipe.RelationTypegetRelationType()List<ResultSupplier>getResults()Map<CoordinateComponent, CMatter>getItems()Mapping of CMatter to their coordinates on the crafting slots. CRecipe.TypegetType()Type of this recipe. List<CRecipePredicate>getPredicates()List of CRecipePredicate that run during recipe matching. UnitisValidRecipe()Validates this recipe's configuration. final static CRecipePredicatechecker(AdjacentRecipe.RelationType relationType)Returns a CRecipePredicate that enforces the direction constraint for the given relationType. -
Methods inherited from class io.github.sakaki_aruka.customcrafter.recipe.CRecipe
asyncGetRecipePredicateResults, asyncGetResults, firstFailedRecipePredicate, getRecipePredicateResults, getResults, getTimes, matchGroups, requiresInputItemAmountMax, requiresInputItemAmountMin -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
AdjacentRecipe
AdjacentRecipe(String name, List<CMatter> matters, AdjacentRecipe.RelationType relationType, List<CRecipePredicate> customPredicates, List<ResultSupplier> results)
- Parameters:
name- Unique identifier for this recipe.matters- List of CMatter entries that make up the ingredients.relationType- Adjacency rule applied to every placed item.customPredicates- Additional CRecipePredicate conditions evaluated before the adjacency check.results- ResultSupplier list that produces the craft output.
-
AdjacentRecipe
AdjacentRecipe(String name, List<CMatter> matters, AdjacentRecipe.RelationType relationType, List<CRecipePredicate> customPredicates)
- Parameters:
name- Unique identifier for this recipe.matters- List of CMatter entries that make up the ingredients.relationType- Adjacency rule applied to every placed item.customPredicates- Additional CRecipePredicate conditions evaluated before the adjacency check.
-
AdjacentRecipe
AdjacentRecipe(String name, List<CMatter> matters, AdjacentRecipe.RelationType relationType)
- Parameters:
name- Unique identifier for this recipe.matters- List of CMatter entries that make up the ingredients.relationType- Adjacency rule applied to every placed item.
-
-
Method Detail
-
getRelationType
final AdjacentRecipe.RelationType getRelationType()
-
getResults
List<ResultSupplier> getResults()
-
getItems
Map<CoordinateComponent, CMatter> getItems()
Mapping of CMatter to their coordinates on the crafting slots.
-
getType
CRecipe.Type getType()
Type of this recipe. See CRecipe.Type.
-
getPredicates
List<CRecipePredicate> getPredicates()
List of CRecipePredicate that run during recipe matching.
nullor empty means no additional conditions.
-
isValidRecipe
Unit isValidRecipe()
Validates this recipe's configuration.
Throws IllegalArgumentException if fewer than 2 items are registered, since a single item can never satisfy any adjacency condition. Otherwise, delegates to CRecipe.isValidRecipe.
- Since:
5.1.0
-
checker
final static CRecipePredicate checker(AdjacentRecipe.RelationType relationType)
Returns a CRecipePredicate that enforces the direction constraint for the given relationType.
The predicate passes if and only if no item in the player's input has a neighbouring item in a direction not included in relationType. Items whose x-distance or y-distance exceeds 1 are not considered neighbours and impose no constraint on each other.
- Parameters:
relationType- The permitted-direction rule to enforce.- Returns:
A CRecipePredicate implementing the direction constraint check.
- Since:
5.1.0
-
-
-
-