An IPC1 system for MCBE Script API projects
Name | Version |
---|---|
@minecraft/server |
Any |
JavaScript
- Download
ipc.js
andipc.d.ts
from the latest release - Copy the files into your project
TypeScript
- Download
ipc.ts
from the latest release - Copy file into your project
IPC.send()
and IPC.on()
can be used to send messages or data between packs.
Pack 1
import IPC from 'ipc.js'
IPC.on('message_channel', (args) => {
console.log(`Message: ${args}`)
})
IPC.on('data_channel', (args) => {
console.log(`Data: ${args.example_bool}, ${args.example_number}`)
})
Pack 2
import IPC from 'ipc.js'
IPC.send('message_channel', 'Example Message')
IPC.send('data_channel', { example_number: 100, example_bool: true })
Console Output
Message: Example Message
Data: true, 100
IPC.invoke()
and IPC.handle()
can be used to request and serve data between packs.
Pack 1
import IPC from 'ipc.js'
IPC.handle('request_channel', (args) => {
switch (args) {
case 'status':
return 'inactive'
case 'size':
return 100
}
})
Pack 2
import IPC from 'ipc.js'
IPC.invoke('request_channel', 'status').then(result => {
console.log(`Status: ${result}`)
})
IPC.invoke('request_channel', 'size').then(result => {
console.log(`Size: ${result}`)
})
Console Output
Status: inactive
Size: 100
Footnotes
-
Inter-Pack Communication ↩