コンテンツにスキップ

AllCandidateUIDesigner について

AllCandidateUIDesigner は、UseMultipleResultCandidateFeature が有効なときに合致するレシピの候補を一覧表示する AllCandidateUI の外観をカスタマイズするためのインターフェースです。 実装したデザイナーを CustomCrafterAPI.setAllCandidateUIDesigner(designer) で設定することで、タイトル・ボタン位置・レシピスロットレイアウト・プレースホルダーアイテムを変更できます。

カスタマイズできる要素は以下の 7 つです:

メソッド概要
title(context)AllCandidateUI のインベントリタイトル
previousPageButton(context)前のページに戻るボタンのスロット座標とアイコンアイテム
nextPageButton(context)次のページへ進むボタンのスロット座標とアイコンアイテム
backToCraftUIButton(context)クラフト画面へ戻るボタンのスロット座標とアイコンアイテム
recipeSlots(context)レシピアイコンを配置できるスロット座標の集合
noDisplayableItem(context)表示可能なアイテムを提供できないレシピのスロットに表示されるアイコン
ungeneratedIconPlaceholderItem(context)レシピアイコン生成中に使用するプレースホルダーアイコンを作成するラムダ

すべてのメソッドにデフォルト実装が存在するため、カスタマイズが必要な部分だけをオーバーライドすれば足ります。 すべてのメソッドは AllCandidateUIDesigner.Context を受け取り、context.searchResultcontext.crafterId を参照できます。


デフォルト設定のレイアウトは以下のとおりです:

  • 前のページボタン: インデックス 45
  • 次のページボタン: インデックス 53
  • クラフト画面へ戻るボタン: インデックス 49 (作業台アイコン)
  • レシピスロット: インデックス 0〜44 (5 行 × 9 列)

設定をリセットしたい場合は以下を呼び出します:

CustomCrafterAPI.setAllCandidateUIDesigner(CustomCrafterAPI.DEFAULT_ALL_CANDIDATE_UI_DESIGNER)

val myDesigner = object : AllCandidateUIDesigner {
override fun title(context: AllCandidateUIDesigner.Context): Component {
return Component.text("全候補")
}
override fun recipeSlots(context: AllCandidateUIDesigner.Context): Set<CoordinateComponent> {
// 上 3 行 (インデックス 0〜26) のみをレシピスロットとして使用する
return (0..<27).map { CoordinateComponent.fromIndex(it) }.toSet()
}
override fun noDisplayableItem(context: AllCandidateUIDesigner.Context): ItemStack {
return ItemStack.of(Material.BARRIER).apply {
editMeta { meta -> meta.displayName(Component.text("表示不可")) }
}
}
}
CustomCrafterAPI.setAllCandidateUIDesigner(myDesigner)

プレイヤーごとのカスタマイズ

Section titled “プレイヤーごとのカスタマイズ”

context.crafterIdcontext.searchResult を使うことでプレイヤーや検索結果に応じたカスタマイズが可能です:

val myDesigner = object : AllCandidateUIDesigner {
override fun title(context: AllCandidateUIDesigner.Context): Component {
val playerName = Bukkit.getPlayer(context.crafterId)?.name ?: "Unknown"
return Component.text("${playerName} の候補一覧 (${context.searchResult.size()} 件)")
}
}
CustomCrafterAPI.setAllCandidateUIDesigner(myDesigner)
class MyPlugin : JavaPlugin() {
override fun onEnable() {
val designer = MyAllCandidateDesigner()
CustomCrafterAPI.setAllCandidateUIDesigner(designer)
}
override fun onDisable() {
// 他のプラグインへの影響を避けるためデフォルトに戻す
CustomCrafterAPI.setAllCandidateUIDesigner(CustomCrafterAPI.DEFAULT_ALL_CANDIDATE_UI_DESIGNER)
}
}

AllCandidateUIDesigner.BakedAllCandidateUIDesigner の各メソッドを特定のコンテキストで評価した結果をイミュータブルに保持するクラスです。 designer.bake(context) または designer.bakeWithEmptyContext() を呼び出すことで取得できます。

val context = AllCandidateUIDesigner.Context.emptyContext()
val baked: AllCandidateUIDesigner.Baked = myDesigner.bake(context)
メソッド / プロパティ概要
isValid()Result<Unit>bake された値を検証する。成功なら Result.success、失敗なら説明付きの Result.failure を返す
ungeneratedIcon(recipe)ItemStackrecipe のプレースホルダーアイコンを返す。生成されたアイテムが表示不可の場合はデフォルトのプレースホルダーへフォールバックする
recipeSlotsIndexSet<Int>recipeSlots と同じスロット座標をインデックス (Set<Int>) で表したもの