@mcbe-mods/discover
v1.0.0-beta.6
Published
Service discovery for MCBE Script API — heartbeat-based in-world registry
Maintainers
Readme
@mcbe-mods/discover
Service discovery for Minecraft Bedrock Edition Script API.
Scripts in the same world can discover each other. Pick a name for your service — the .discover suffix is internal and never appears in your code.
Names support multiple levels — for example, if your addon is called aaa with sub-modules chat and sync, name them chat.aaa and sync.aaa. query('aaa') matches everything under aaa, and query('_tcp') matches all services with the _tcp suffix.
Each service can carry arbitrary metadata — just pass any JSON-serializable object as the second argument to register(). Other addons receive this metadata when they find your service.
Install
npm install @mcbe-mods/discoverUsage
import { Discover } from '@mcbe-mods/discover'
const discover = new Discover()
// Register with any name
const stop = discover.register('chat.my-addon', {
prefix: '!',
lang: 'zh-CN',
version: '2.0',
})
// Find a service by name — pass a meta type for type-safe access
const cancel = discover.query<{ prefix: string, lang: string, version: string }>('my-addon', (event) => {
if (event.type === 'service-resolved') {
console.log('Found:', event.service.serviceType)
console.log('Meta:', event.service.meta.lang)
}
else if (event.type === 'service-removed') {
console.log('Lost:', event.serviceType)
}
})
// Cleanup when done
stop()
cancel()
discover.dispose()