Skip to content

MappedRelation / MappedRelationComponent

MappedRelation and MappedRelationComponent are data classes that hold the correspondence between recipe coordinates and the actual input slot coordinates.

For shaped recipes (SHAPED), a match is found regardless of where on the grid the player places the items as long as the shape matches. MappedRelation records the mapping between those “coordinates in the recipe definition” and “the coordinates where items are actually placed.”


data class MappedRelation(
val components: Set<MappedRelationComponent>
)
data class MappedRelationComponent(
val recipe: CoordinateComponent,
val input: CoordinateComponent
)
FieldTypeDescription
MappedRelation.componentsSet<MappedRelationComponent>Set of correspondence components
MappedRelationComponent.recipeCoordinateComponentCoordinate in the recipe definition
MappedRelationComponent.inputCoordinateComponentCoordinate of the actually placed slot

MappedRelation is passed in the following contexts:

ContextField Name
ResultSupplier.Contextrelation
CRecipePredicate.Contextrelations
SearchResultrelation (via getter method)

An example of checking which slot contains which item inside a ResultSupplier:

val supplier = ResultSupplier { ctx ->
// Get the input coordinate that corresponds to recipe coordinate (0,0)
val recipeCoord = CoordinateComponent(0, 0)
val inputCoord: CoordinateComponent? = ctx.relation.components
.firstOrNull { it.recipe == recipeCoord }
?.input
val inputItem: ItemStack = inputCoord?.let { ctx.mapped[it] } ?: ItemStack.empty()
listOf(ItemStack.of(Material.DIAMOND, inputItem.amount))
}