Skip to content

Kotlin 界面對照表 ​

plugin world匯入以下主機界面。Kotlin 在 pumpkin 中提供這些界面;例如,WIT boss-bar 會變為 pumpkin.BossBar。每個 WIT 連結都會開啟其源定義。

WIT 定義生成的 Kotlin 名稱空間用途
loggingLogging伺服器日誌記錄。
guiGuiGUI 資源及其物品欄。
scoreboardScoreboard記分板資源。
serverServer全域伺服器和玩家查詢。
textText文字符件。
commandCommand指令樹、傳送者、參數、執行和建議。commands 管理回調 ID。
contextContextContext.Context 註冊、伺服器存取和插件資料資料夾。
i18nI18n翻譯和區域設定支援。
schedulerScheduler延遲/重複任務和取消。PumpkinPlugin.tasks 管理兩種回調形式。
worldWorld世界、方塊、實體、區塊和生成。自訂 AI 和生成器會回調到 PumpkinPlugin。
entityEntity在整個 API 中提供的實體相關類型。
boss-barBossBarBoss 欄類型和資源。
formsForms基岩版表單。
java-dialogsJavaDialogsJava 版對話方塊。
status-effectStatusEffect狀態效果類型和實例。
block-entityBlockEntity方塊實體類型和資源。
ipcIpc向另一個插件傳送訊息;傳入訊息使用 handleIpcMessage。
attributesAttributes實體屬性和修飾符。
playerPlayer玩家資源和操作,包括物品欄存取。
advancementAdvancement進度定義和進展。
recipeRecipe配方定義和註冊。
inventoryInventory物品欄和玩家物品欄資源操作。
datapackDatapack資料包檢查和管理。
enchantmentsEnchantments附魔類型。
damage-typesDamageTypes傷害類型。
screensScreens界面和容器類型。
statisticsStatistics玩家統計類別和類型。
displayDisplay展示實體和互動實體。
game-rulesGameRules遊戲規則定義和值。
game-eventsGameEvents遊戲事件類型。
potionsPotions藥水類型。
entity-statusesEntityStatuses實體狀態和動畫類型。

WIT 名稱對應的 Kotlin 定義 ​

生成的 Kotlin 名稱和類型遵循 WIT 定義:

WITKotlin
context 資源 contextContext.Context;在手寫 API 中也別名為 PluginContext
inventory 資源 inventoryInventory.Inventory
event 變體 eventEvent.Event
world 資源 worldWorld.World
u8、u16、u32、u64UByte、UShort、UInt、ULong
s32、bool、stringInt、Boolean、String
list<u8>、option<T>List<UByte>、可空的 T?
result<T, E>生成的調用邊界處為 Kotlin Result<T>

WIT register-event-with-handle 變為 context.registerEventWithHandle(handlerId, eventType, priority, blocking),並返回一個 ULong。WIT get-item: func(slot: u32) -> option<item-stack> 變為 inventory.getItem(slot: UInt): ItemStack.ItemStack?。IDE 自動完成會顯示你的 API 版本中的成員。

以下操作將生成的 WIT 調用與 Kotlin 註冊 API 連線起來:

WIT 操作生成的 Kotlin 調用Kotlin API
context.register-event-with-handle 和 unregister-eventcontext.registerEventWithHandle(id, type, priority, blocking) 和 context.unregisterEvent(registrationId)events.listen(...) 和 EventSubscription.unregister()
command.execute-with-handler-id 和 context.register-command先調用 command.executeWithHandlerId(id),再調用 context.registerCommand(command, permission)commands.register(...)
command-node.suggest-with-handler-idnode.suggestWithHandlerId(id)commands.onSuggestions(...)
scheduler.schedule-delayed-taskScheduler.scheduleDelayedTask(id, delayTicks)tasks.afterTicks(...)
scheduler.schedule-repeating-task 和 cancel-taskScheduler.scheduleRepeatingTask(id, delayTicks, periodTicks) 和 Scheduler.cancelTask(taskId)tasks.everyTicks(...) 和 ScheduledTask.cancel()
mob.add-custom-ai-goalmob.addCustomAiGoal(priority, goalId)aiGoals.register(...)
world.set-chunk-generatorworld.setChunkGenerator(generatorId)chunkGenerators.set(...)
ipc.send-ipc-messageIpc.sendIpcMessage(recipient, message)傳出 IPC;接收方使用 ipc.onMessage(...)

Kotlin API 會為其註冊方法分配處理器 ID。透過生成的綁定直接調用時,需要自行管理這些 ID。

共享類型界面 ​

這些界面定義主機匯入和插件匯出使用的類型。它們不是 plugin world 中單獨的匯入:

WIT 定義Kotlin 名稱空間
common、uuidCommon、Uuid
biomes、sounds、particlesBiomes、Sounds、Particles
java-packets、bedrock-packetsJavaPackets、BedrockPackets
item-stack、data-componentsItemStack、DataComponents
permission、event、metadata、entity-typesPermission、Event、Metadata、EntityTypes

Inventory.Inventory.getItem 和 setItem 等資源方法不需要回調或處理器 ID。回調參考介紹了需要它們的操作。

基於 MIT 授權條款發布。