コンテンツにスキップ

CraftView

CraftView はクラフト UI の現在の状態を表すデータクラスです。 プレイヤーがスロットに配置したアイテムのマッピングと、結果スロットに表示されているアイテムを保持します。

Search.search() の戻り値の一部として渡されるほか、CRecipePredicate.Contextinput フィールドとしても利用されます。


data class CraftView(
val materials: Map<CoordinateComponent, ItemStack>,
val result: ItemStack
)
フィールド概要
materialsMap<CoordinateComponent, ItemStack>クラフトスロットに配置されたアイテムのマッピング
resultItemStack結果スロットのアイテム

getDecremented(shiftUsed, recipe, relations)

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

クラフト実行後のスロット状態 (消費後の CraftView) を返します。 mass = false の CMatter に対応するアイテムは amount 分消費され、mass = true は 1 個消費されます。 一括作成時 (shiftUsed = true) は消費量が calledTimes 倍になります。

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

CraftView の深いコピーを返します。 materials の各 ItemStackclone() されます。

materialsresult に含まれる空でないアイテムをすべて指定したワールドの座標にドロップします。

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

Air (空スロット) を除外した CraftView を返します。

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 は現在の CraftView
val placedCount = ctx.input.materials.values.count { !it.type.isAir }
placedCount >= 3
}