Skip to content
Compact Universe logoCompact UniverseDownloads
You are viewing upcoming docs from main (unreleased).

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.

Compact Universe registers a RegisterCapabilitiesEvent listener on the mod event bus at EventPriority.LOWEST.

For every BlockCapability<?, ?> returned by BlockCapability.getAllProxyable():

  1. Skips capabilities whose contextClass() is not net.minecraft.core.Direction.class.
  2. Skips capabilities already registered on compact_universe:machine_io or compact_universe:room_port by an earlier listener.
  3. 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.

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.

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()).

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 NullPointerException if provider is null.
  • Invokes provider on the server thread only, and only when the far link block and target.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.
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:

  • linkBlock is not a link block entity, is removed, or is not on a ServerLevel.
  • 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.

@FunctionalInterface
public interface LinkCapabilityProvider<T, C> {
@Nullable T getCapability(LinkTarget target, C context);
}
  • target: The resolved block on the other side of the link. Its chunk in target.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 null for none.
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.

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.
  • Machine I/O linked or unlinked: Posts one event per existing Room Port in the room (with face, io, and port present), or a single event with empty face/port if 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.

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.