Link Extension API
Package: io.github.jmgilman.compactuniverse.api.link
Artifact: compact_universe-<version>-api.jar (contains only io.github.jmgilman.compactuniverse.api.*; verified by jdeps at build time to reference zero internal mod classes).
For usage patterns and examples, see Integrating Your Mod with Links.
Built-in capability forwarding
Section titled “Built-in capability forwarding”Compact Universe registers a RegisterCapabilitiesEvent listener on the mod event bus at EventPriority.LOWEST.
For every BlockCapability<?, ?> returned by BlockCapability.getAllProxyable():
- Skips capabilities whose
contextClass()is notnet.minecraft.core.Direction.class. - Skips capabilities already registered on
compact_universe:machine_ioorcompact_universe:room_portby an earlier listener. - Calls
LinkCapabilities.forward(event, capability).
With NeoForge alone, this forwards neoforge:item_handler, neoforge:fluid_handler, and neoforge:energy. Any listener registered at default priority or higher overrides built-in pass-through for that capability.
LinkCapabilities
Section titled “LinkCapabilities”Final utility class providing the registration and lookup entry points for Machine I/O (compact_universe:machine_io) and Room Port (compact_universe:room_port) block entities.
forward
Section titled “forward”public static <T> void forward( RegisterCapabilitiesEvent event, BlockCapability<T, @Nullable Direction> capability)Registers pass-through forwarding for capability on both link block entity types. A request at a link face returns target.level().getCapability(capability, target.pos(), target.side()).
register
Section titled “register”public static <T, C> void register( RegisterCapabilitiesEvent event, BlockCapability<T, C> capability, LinkCapabilityProvider<T, C> provider)Registers a custom provider for capability on both link block entity types.
- Throws
NullPointerExceptionifproviderisnull. - Invokes
provideron the server thread only, and only when the far link block andtarget.pos()are both loaded. - Registers capability invalidation watches on the far link block and far target (even when unloaded) so caching callers are notified when chunks load or target blocks change.
- Enforces a per-thread forwarding recursion cap of
8.
target
Section titled “target”public static Optional<LinkTarget> target(BlockEntity linkBlock, @Nullable Direction side)Returns the block on the other side of linkBlock reached by a request at side, or Optional.empty() if:
linkBlockis not a link block entity, is removed, or is not on aServerLevel.- The link has no matching far endpoint in the link record.
- Either the far link block’s chunk or the target block’s chunk is unloaded (never loads chunks).
For Machine I/O blocks, side selects the linked Room Port (null returns empty). Room Ports ignore side.
LinkCapabilityProvider<T, C>
Section titled “LinkCapabilityProvider<T, C>”@FunctionalInterfacepublic interface LinkCapabilityProvider<T, C> { @Nullable T getCapability(LinkTarget target, C context);}target: The resolved block on the other side of the link. Its chunk intarget.level()is guaranteed to be loaded.context: The capability context passed to the near link block.- Return value: The capability instance to expose at the near link face, or
nullfor none.
LinkTarget
Section titled “LinkTarget”public record LinkTarget(ServerLevel level, BlockPos pos, Direction side) {}| Component | Meaning |
|---|---|
level |
The target block’s ServerLevel. Guaranteed loaded at pos inside a LinkCapabilityProvider call. |
pos |
Position of the block in front of the far link block (room side of a Room Port, or outside face F of a Machine I/O). |
side |
The face of the target block pointing back toward the far link block—the Direction context to pass when querying the target’s capabilities. |
LinkChangedEvent
Section titled “LinkChangedEvent”Game-bus event (NeoForge.EVENT_BUS, extends net.neoforged.bus.api.Event) posted on the server after the link record is updated and loaded endpoints have been invalidated. Unchanged or refused link actions post nothing.
| Method | Return type | Meaning |
|---|---|---|
server() |
MinecraftServer |
The server whose link record changed. |
room() |
String |
Compact Machines room code whose link changed. |
face() |
Optional<Direction> |
Machine I/O face the port links through. Empty only when a Machine I/O links or unlinks in a room that has no ports. |
io() |
Optional<GlobalPos> |
Position and dimension of the room’s Machine I/O block. Empty when a Room Port changes in a room with no Machine I/O. |
port() |
Optional<GlobalPos> |
Position (in Compact Machines’ dimension) of the Room Port for face(). Empty when face() is empty. |
connected() |
boolean |
true when the change added the claim; false when it removed the claim. |
Event sequences
Section titled “Event sequences”- Machine I/O linked or unlinked: Posts one event per existing Room Port in the room (with
face,io, andportpresent), or a single event with emptyface/portif the room currently has no ports. Replacing a Machine I/O’s previous room posts disconnect events for the old room followed by connect events for the new room. - Room Port face selected or cleared: Posts one disconnect event for the previous face (if the port was moving from another face) and one connect event for the new face, or one disconnect event when unlinked or broken.
- Stored machine removed: Releases both the Machine I/O claim and all Room Port claims for the room, invalidates loaded endpoints, and posts disconnect events (
connected() == false) for each released link.
Internal API types
Section titled “Internal API types”LinkEndpoint (@ApiStatus.Internal) is implemented by Compact Universe’s link block entities so LinkCapabilities can dispatch without depending on mod internals. Third-party mods should use LinkCapabilities rather than calling or implementing LinkEndpoint.
Not an official Minecraft website. Not approved by or associated with Mojang or Microsoft.