コンテンツにスキップ

CVanillaRecipe

CVanillaRecipe はバニラ Bukkit の Recipe インスタンスを CRecipe としてラップするクラスです。 バニラのクラフトレシピを CRecipe として扱えるようにすることで、PartialSearch などの CustomCrafter 機能と組み合わせられるようになります。

コンストラクタは internal のため直接呼び出すことはできません。以下のファクトリメソッドを使用してください。


バニラの CraftingRecipeCVanillaRecipe に変換します。 実行時の型に応じて fromShaped()fromShapeless()fromTransmute() のいずれかに処理を委譲します。 対応していないレシピ型の場合は null を返します。

@JvmStatic
fun fromVanilla(recipe: CraftingRecipe): CVanillaRecipe?

バニラの ShapedRecipe を変換します。

@JvmStatic
fun fromShaped(recipe: ShapedRecipe): CVanillaRecipe

レシピのシェイプと素材マップを Map<CoordinateComponent, CMatter> へ変換します。 各 CMatterRecipeChoice.test() を使用した CMatterPredicate を持つため、NBT や完全一致の素材条件も正しく評価されます。


バニラの ShapelessRecipe を変換します。

@JvmStatic
fun fromShapeless(recipe: ShapelessRecipe): CVanillaRecipe

素材は CoordinateComponent.fromIndex() で順番に座標へ割り当てられます。 各 CMatterRecipeChoice.test() を使用した CMatterPredicate を持ちます。


バニラの TransmuteRecipe を変換します。5.0.21 で追加されました。

@JvmStatic
fun fromTransmute(recipe: TransmuteRecipe): CVanillaRecipe

TransmuteRecipe は、ソースアイテム (input) とカタリスト (material) を組み合わせることでソースのアイテムタイプが result に変化するクラフトレシピです。 変換後の CVanillaRecipeSHAPELESS 型で、ソース用とカタリスト用の 2 スロットを持ちます。

ResultSupplier はクラフトグリッド内から recipe.input にマッチするアイテムを探し、そのタイプを recipe.result.type に置き換えたコピーを返します。

// 例: バニラの TransmuteRecipe をすべてラップして登録する
Bukkit.recipeIterator().asSequence()
.filterIsInstance<TransmuteRecipe>()
.mapNotNull { CVanillaRecipe.fromTransmute(it) }
.forEach { CustomCrafterAPI.registerVanillaRecipe(it) }

このレシピのスロットを指定した CraftView とインデックス順に対応付けた MappedRelation を構築します。

fun relateWith(view: CraftView): MappedRelation
条件挙動
view の非 Air アイテム数がレシピのスロット数と一致しないIllegalArgumentException をスロー
ビューが 4 列または 4 行を超えるIllegalArgumentException をスロー

元の Bukkit Recipe インスタンスは original プロパティからアクセスできます。

val original: Recipe

CVanillaRecipeCRecipe を実装しているため、PartialSearch と組み合わせることができます。 これにより、Bukkit API では提供されていないバニラレシピの部分一致検索が可能になります。

val vanillaRecipes: List<CVanillaRecipe> = Bukkit.recipeIterator().asSequence()
.filterIsInstance<CraftingRecipe>()
.mapNotNull { CVanillaRecipe.fromVanilla(it) }
.toList()
// バニラレシピに対して非同期で部分一致検索
val result: PartialSearch.PartialSearchResult = PartialSearch.asyncPartialSearch(
recipes = vanillaRecipes,
view = currentView,
query = SearchQuery(asyncContext = ctx)
).await()