Repository navigation
Energy
Watts are whole numbers. n on subscribe is watts per tick you want (pull) or can give (push).
Create one client with the handlers you need. Pull uses onEnergyOffer. Push uses onEnergyCollect. A pack that does both passes both to the same createBedrockClient — see Installation.
register({ source }) is required for any pull or push, including Power Adapter-only packs with no advertised machines.
Sneak-toggle Power supply on the Interface (that is not the Power Adapter block). You never pass the Interface. Pull is subscribeEnergyPull at your machine's coordinates: store into your tank, return watts you did not store.
| Value | Behavior |
|---|---|
| omit | Items only; no Interface energy |
"dorios" |
DNS writes the paired machine’s dorios:energy_container. You do not subscribe |
"ipc" |
Pull at your machine's coordinates. DNS offers watts; you return what you cannot store |
| anything else |
register fails (unknown_energy_protocol) |
const dns = createBedrockClient({
onEnergyOffer(items) {
const unusedWatts = [];
for (const line of items) {
const unused = storeIntoTank(line.at, line.n);
if (unused > 0) unusedWatts.push({ at: line.at, n: unused });
if (tankIsFull(line.at)) void dns.unsubscribeEnergyPull(line.at);
}
return unusedWatts;
},
});
await dns.subscribeEnergyPull(machine, remainingRoom); // remainingRoom = watts per tick, even with no jobIf you stored a whole offer, omit that machine from the return list. Return { at, n } for unused watts. Returning the whole offer means you took nothing that tick — that is not unpair.
Subscribe ok false / err "unpaired": no Interface facing this machine, or it is not "ipc". Call forgetPair so the pair entry in your pack’s dynamic properties is cleared and machine pull is dropped.
The client unsubscribes machine pull on unpair and on forgetPair. Keep the current job. Unsubscribe yourself when the tank is full. Do not unsubscribe Adapter pull/push when the machine unpairs.
After world reload, pair entries reload but energy subscriptions do not. onPair does not fire for machines that were already paired. Re-subscribe those machines yourself (Installation).
A block is a Power Adapter when block.hasTag("xxdmogxx_dns:energy_port"). It also has dorios:energy for UtilityCraft cables.
Pull, push, and energyStock use that Adapter’s coordinates. DNS does not walk your power cables to pick an Adapter for you. Remember the Adapter you use, or find it again with hasTag. Gateway, Interface, or cables return no_energy_port. Adapter subscriptions are not tied to machine pairing — a machine unpair does not drop them.
Find it the same way as a Gateway (Gateway coordinates snippet).
Pull (DNS → you) uses the same onEnergyOffer as Interface ipc:
await dns.energyStock(adapter);
await dns.subscribeEnergyPull(adapter, wantPerTick);Push (you → DNS). Add onEnergyCollect to the same client as onEnergyOffer (see Installation). Each collect line’s n is room allocated this tick. Reply with watts you actually remove from your tank (≤ allocated). Returning the allocated items unchanged claims the full amount even if you had no surplus.
onEnergyCollect(items) {
return items.map((line) => ({
at: line.at,
n: Math.min(line.n, surplusAt(line.at)),
}));
}
await dns.subscribeEnergyPush(adapter, canPushPerTick);Unsubscribe push when you have no surplus.
Pull: subscribeEnergyPull, then on the next onEnergyOffer for that block store what you can, return leftover, unsubscribeEnergyPull.
Push: subscribeEnergyPush, then in onEnergyCollect send min(allocated, surplus) for that block and unsubscribeEnergyPush.
Start
Using DNS
Reference