KairoStartupBeforeEvent
import { router } from '@kairo-js/router'
router.beforeEvents.startup의 이벤트 객체입니다. 직접 인스턴스화할 수 없습니다.
Minecraft의 worldLoad보다 먼저 발생합니다. API 등록, 훅 선언, 커스텀 커맨드 등록, 커스텀 컴포넌트 등록, 애드온 이벤트 구독은 이 이벤트 핸들러 안에서만 유효합니다.
프로퍼티
addonApi
readonly addonApi: ApiRegistration
API 및 훅을 등록합니다.
addonEvents
readonly addonEvents: AddonEventRegistration
router.emit()으로 발행되는 애드온 이벤트를 구독합니다.
blockComponentRegistry
readonly blockComponentRegistry: BlockComponentRegistry
Minecraft block custom component를 등록합니다.
customCommandRegistry
readonly customCommandRegistry: KairoCustomCommandRegistry
커스텀 커맨드를 등록합니다.
itemComponentRegistry
readonly itemComponentRegistry: ItemComponentRegistry
Minecraft item custom component를 등록합니다.
api
readonly api: ApiRegistration
ev.api는 addonApi의 deprecated alias입니다.
events
readonly events: AddonEventRegistration
ev.events는 addonEvents의 deprecated alias입니다.
사용 예시
typescript
import { router } from '@kairo-js/router'
router.beforeEvents.startup.subscribe((ev) => {
// Register an API
ev.addonApi.register<{ playerId: string }, { balance: number }>(
'economy/getBalance',
async ({ playerId }) => {
return { balance: getBalance(playerId) }
},
)
// Subscribe to another addon's event
ev.addonEvents.on('other-addon', 'someEvent', (payload) => {
console.log('Event received:', payload)
})
// Register Minecraft custom components
ev.itemComponentRegistry.registerCustomComponent('my:addon_item', {
onUse(event) {
console.log(event.source?.name)
},
})
// Register a custom command
ev.customCommandRegistry.registerCommand(
{ name: 'mycommand', description: 'My command' },
(origin) => {
console.log('Command executed')
},
)
})