CraftView
What is CraftView
Section titled “What is 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.
Class Definition
Section titled “Class Definition”data class CraftView( val materials: Map<CoordinateComponent, ItemStack>, val result: ItemStack)| Field | Type | Description |
|---|---|---|
materials | Map<CoordinateComponent, ItemStack> | Mapping of items placed in the crafting slots |
result | ItemStack | Item in the result slot |
Methods
Section titled “Methods”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)clone()
Section titled “clone()”Returns a deep copy of the CraftView.
Each ItemStack in materials is also clone()d.
drop(world, location)
Section titled “drop(world, location)”Drops all non-empty items in materials and result at the specified world coordinates.
craftView.drop(player.world, player.location)excludeAir()
Section titled “excludeAir()”Returns a CraftView with air (empty slots) excluded.
val filtered: CraftView = craftView.excludeAir()Usage Examples
Section titled “Usage Examples”Combining with Search.search()
Section titled “Combining with Search.search()”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)Usage in CRecipePredicate
Section titled “Usage in CRecipePredicate”val predicate = CRecipePredicate { ctx -> // ctx.input is the current CraftView val placedCount = ctx.input.materials.values.count { !it.type.isAir } placedCount >= 3}