Repository navigation
Installation
Enable Digitally Networked Storage on the world if you want the client to talk to it. The client does not require DNS: waitReady() is false when it isn’t there.
- Download
dns-peer-client.jsfrom mcbe-dns-peer-client Releases. - Put Omniac’s
mcbe-ipcmodule in the same folder, namedmcbe-ipc.js. The client imports./mcbe-ipc.js. - Import the client from your pack’s entry script.
import { createBedrockClient } from "./dns-peer-client.js";npm install @mcbe-dns-peer/client mcbe-ipcimport { createBedrockClient } from "@mcbe-dns-peer/client/bedrock";Call waitReady() once when the world loads. It finds DNS if that pack is already up, or when it comes up after you.
| Situation | waitReady() |
|---|---|
| DNS is on the world and matches this client | true |
| DNS missing, or no reply within 5 seconds (~100 ticks) |
false, no chat |
| DNS pack is older than this client |
false, once: Digitally Networked Storage is outdated. (content log + yellow chat) |
| This client is older than the DNS pack |
false, once: This addon is using an outdated DNS client.
|
Later calls (stock, register, energy subscribe, …) return undefined while not ready, or if the call timed out. That is not { ok: false, err }.
Create one client. Omit onEnergyOffer / onEnergyCollect if you do not pull or push watts (Energy).
import { createBedrockClient } from "./dns-peer-client.js";
const dns = createBedrockClient({
onEnergyOffer(items) {
// store what you can; return unused watts per machine / Adapter
return [];
},
onEnergyCollect(items) {
// return watts you actually send (≤ allocated)
return items.map((line) => ({ at: line.at, n: Math.min(line.n, surplusAt(line.at)) }));
},
});
if (!(await dns.waitReady())) {
// DNS is off this world, or the packs don't match — keep your own storage
} else {
dns.clearAdapters();
dns.addAdapter({
ids: ["example:crusher"],
in: [0],
out: [2],
signal: true,
energyProtocol: "ipc",
});
await dns.register({ source: "example-pack" });
dns.onPair((at) => {
// new pair this world load
});
dns.onUnpair((at) => {
// keep the job; do not drop Adapter energy
});
dns.onWake((at) => {
// insert landed, or a drain actually moved items
});
// After world reload, onPair does not fire for machines that were already paired.
// Energy subscriptions are gone — re-subscribe yourself. Inspect your blocks for jobs; wake is not replayed.
for (const at of myMachines) {
if (dns.isPaired(at) && tankHasRoom(at)) {
void dns.subscribeEnergyPull(at, wantPerTick(at));
}
}
}source is a stable string you choose for this pack (for example "example-pack"). You need register({ source }) for Interface ipc energy and for Power Adapter pull/push, even if you never advertise a machine (you can register an empty list).
Pair entries live in your pack’s world dynamic properties (each pack has its own). Call forgetPair when your machine breaks — DNS cannot clear that entry. Details: Pairing, wake, outputs.
Start
Using DNS
Reference