Integrating Your Mod with Links
Compact Universe exposes a standalone public Java API in io.github.jmgilman.compactuniverse.api.link so third-party mods can forward capabilities or bridge block networks across Machine I/O and Room Port links without depending on Compact Universe internals.
For full method signatures and event contracts, see the Link Extension API Reference.
Choose an integration level
Section titled “Choose an integration level”Pick the simplest level that fits your mod:
| Level | When to use it | Dependency on Compact Universe |
|---|---|---|
| 1. Mark proxyable | Standard sided BlockCapability<T, Direction> that is safe to proxy across dimensions |
None |
| 2. Forward explicitly | Sided BlockCapability<T, Direction> that should cross Compact Universe links without being marked globally proxyable |
Optional (compileOnly against -api jar) |
| 3. Custom provider / topology events | Capabilities that need wrapping or filtering, or grid/network mods (such as storage networks) that discover neighbors instead of using plain capabilities | Optional (compileOnly against -api jar) |
Level 1: Mark a capability proxyable (zero dependency)
Section titled “Level 1: Mark a capability proxyable (zero dependency)”At EventPriority.LOWEST during RegisterCapabilitiesEvent, Compact Universe automatically forwards every sided block capability (contextClass() == Direction.class) returned by BlockCapability.getAllProxyable() that no other listener has registered for its link blocks.
If your mod already marks its sided capability proxyable through NeoForge’s RegisterCapabilitiesEvent#setProxyable, Compact Universe forwards it automatically with no code that references Compact Universe.
Level 2: Forward a sided capability explicitly
Section titled “Level 2: Forward a sided capability explicitly”If your capability is safe through Compact Universe links but you do not want to mark it globally proxyable, call LinkCapabilities.forward from your own RegisterCapabilitiesEvent listener (at default priority or higher) when Compact Universe is loaded:
import io.github.jmgilman.compactuniverse.api.link.LinkCapabilities;import net.neoforged.bus.api.IEventBus;import net.neoforged.fml.ModList;import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
public final class MyModCompactUniverseCompat { public static void init(IEventBus modBus) { if (ModList.get().isLoaded("compact_universe")) { modBus.addListener(MyModCompactUniverseCompat::registerCapabilities); } }
private static void registerCapabilities(RegisterCapabilitiesEvent event) { LinkCapabilities.forward(event, MyCapabilities.MY_SIDED_HANDLER); }}Keep references to LinkCapabilities inside the gated class or lambda so your mod still loads when Compact Universe is absent.
Level 3: Custom provider or network bridge
Section titled “Level 3: Custom provider or network bridge”Wrap or filter a capability
Section titled “Wrap or filter a capability”Use LinkCapabilities.register with a LinkCapabilityProvider<T, C> when you need to wrap, filter, or transform the far target’s capability, or when your capability uses a context type other than Direction:
import io.github.jmgilman.compactuniverse.api.link.LinkCapabilities;import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
private static void registerCapabilities(RegisterCapabilitiesEvent event) { LinkCapabilities.register(event, MyCapabilities.MY_HANDLER, (target, context) -> { var handler = target.level().getCapability( MyCapabilities.MY_HANDLER, target.pos(), target.side()); return handler == null ? null : new MyWrappedHandler(handler); });}Because your listener runs before Compact Universe’s LOWEST-priority fallback, registering a custom provider replaces default pass-through for that capability.
When your provider is called:
- It runs on the server thread only.
- Both the far link block and
target.pos()intarget.level()are guaranteed to be loaded. - Compact Universe enforces a forwarding depth cap of
8and automatically watchestarget.pos()for capability invalidation.
Bridge a neighbor-discovering network
Section titled “Bridge a neighbor-discovering network”Storage and cable networks that connect by scanning neighboring block entities rather than querying sided capabilities need two tools:
- Resolve the far block on demand: Call
LinkCapabilities.target(blockEntity, side)to get anOptional<LinkTarget>. It never loads a chunk and returns empty unless both the far link block and its adjacent target are loaded. - React to topology changes: Subscribe to
LinkChangedEventonNeoForge.EVENT_BUS. Compact Universe posts this event on the server after updating its link record and invalidating both endpoints whenever a Machine I/O block or Room Port is linked, unlinked, moved, broken, or disconnected by removing a machine.
import io.github.jmgilman.compactuniverse.api.link.LinkChangedEvent;import net.neoforged.neoforge.common.NeoForge;
NeoForge.EVENT_BUS.addListener((LinkChangedEvent event) -> { event.io().ifPresent(ioPos -> rebuildNodeIfLoaded(event.server(), ioPos)); event.port().ifPresent(portPos -> rebuildNodeIfLoaded(event.server(), portPos));});Compile against the standalone API jar
Section titled “Compile against the standalone API jar”Compact Universe builds a dedicated compact_universe-<version>-api.jar containing only io.github.jmgilman.compactuniverse.api.*. Its build enforces with jdeps that the API bytecode never references internal mod classes, so you can depend on the API jar at compile time without pulling in mod internals or Compact Machines.
Not an official Minecraft website. Not approved by or associated with Mojang or Microsoft.