Skip to content

API overview

Immersive Portals Reforged has a public Java API for other mods. It is the same on every loader and every supported Minecraft version: it uses Minecraft’s own classes with their official (Mojang) names, and no loader classes.

This is API level 1, shipped with 0.1.0-alpha. With it you can:

  • create portal groups from server code, of any shape, size and orientation;
  • follow and cancel teleports, and know when portal groups appear and disappear;
  • tell, while rendering, whether the current frame is a view through a portal, to keep rendering mods and effects consistent.
  • call a method on the other side of the connection with its arguments, without writing packets: remote calls.
Package Side Contents
net.night.ipreforged.api both ReforgedApi, the entry point.
net.night.ipreforged.api.portal server PortalService and PortalBuilder: creating portals.
net.night.ipreforged.api.event server ApiEvent, TeleportEvents, PortalEvents: events.
net.night.ipreforged.api.client client RenderViews, ViewInfo: rendering.
net.night.ipreforged.api.remote both RemoteCalls, @RemoteEntry, RemoteSide: remote calls.
net.night.ipreforged.api.annotation both @Stable, @Experimental, @Internal: stability.
net.night.ipreforged.core.* both The engine’s immutable value types: PortalSnapshot, Warp, Frame3D, Quat, Vec3D, shapes, GroupRole, PortalFlags: geometry.

Everything else (net.night.ipreforged.impl, .client, .server, .mixin…) is internal and can change in any release.

ReforgedApi api = ReforgedApi.get();

ReforgedApi.get() returns the API implemented by the installed mod. From it, portals() gives the PortalService. Events and the rendering helpers are static and do not need it.

Two numbers tell you which API level you are dealing with:

  • ReforgedApi.API_VERSION is a constant: the level your mod was compiled against.
  • ReforgedApi.get().apiVersion() is the level of the mod installed in the game.

The level goes up with every backwards-compatible addition. If you use something added in a later level, check apiVersion() before calling it.

ReforgedApi.get() works once Immersive Portals Reforged has initialised, which happens in its own mod initialiser. Before that it throws IllegalStateException. Mods initialise in an order you should not rely on, so:

  • register event listeners whenever you like, including in your mod’s initialiser: events are plain static fields;
  • call ReforgedApi.get() later: when the server starts, in a command, in an event handler.
What Where to call it
PortalBuilder.build() Server thread. It spawns entities.
PortalBuilder.preview() Anywhere: it only computes.
TeleportEvents, PortalEvents listeners Called on the server thread.
RenderViews Render thread only.
Engine types (core) Anywhere: they are immutable.

This creates a two-way portal from the spawn area to the Nether. The surface is 3 blocks wide and 4 high, its bottom edge at y = 64, and you walk into it from the south.

FirstPortal.java
package com.example.portals;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.night.ipreforged.api.ReforgedApi;
import java.util.UUID;
public final class FirstPortal {
private FirstPortal() {
}
/** Opens the portal and returns the id of its group. Call it on the server thread. */
public static UUID open(ServerLevel overworld) {
return ReforgedApi.get().portals()
.builder(overworld)
.origin(new Vec3(0.5, 66, 0.5)) // centre of the surface
.facing(Direction.SOUTH) // its front faces south
.size(3, 4)
.destination(Level.NETHER, new Vec3(0.5, 66, 0.5))
.twoWay()
.build();
}
}

Next: add the dependency to your project, then read Creating portals for every option of the builder.