Skip to content

CraftView

CraftView is a data class that represents the current state of the crafting UI. It holds the mapping of items placed by the player in each slot, as well as the item displayed in the result slot.

It is passed as part of the return value of Search.search(), and is also used as the input field of CRecipePredicate.Context.


data class CraftView(
val materials: Map<CoordinateComponent, ItemStack>,
val result: ItemStack
)
FieldTypeDescription
materialsMap<CoordinateComponent, ItemStack>Mapping of items placed in the crafting slots
resultItemStackItem in the result slot

getDecremented(shiftUsed, recipe, relations)

Section titled “getDecremented(shiftUsed, recipe, relations)”

Returns the slot state after a craft is executed (the CraftView after consumption). Items corresponding to CMatter with mass = false are consumed by their amount, while mass = true items are consumed by 1. For bulk crafting (shiftUsed = true), the consumption is multiplied by calledTimes.

val decremented: CraftView = craftView.getDecremented(
shiftUsed = true,
recipe = recipe,
relations = mappedRelation
)

Returns a deep copy of the CraftView. Each ItemStack in materials is also clone()d.

Drops all non-empty items in materials and result at the specified world coordinates.

craftView.drop(player.world, player.location)

Returns a CraftView with air (empty slots) excluded.

val filtered: CraftView = craftView.excludeAir()

val craftView = CraftView(
materials = mapOf(
CoordinateComponent(0, 0) to ItemStack.of(Material.STONE)
),
result = ItemStack.empty()
)
val results: List<SearchResult> = Search.search(craftView, player.uniqueId)
val predicate = CRecipePredicate { ctx ->
// ctx.input is the current CraftView
val placedCount = ctx.input.materials.values.count { !it.type.isAir }
placedCount >= 3
}