Creating portals
Portals are created on the server, a whole group at a time. You describe the primary surface
with a PortalBuilder; the builder derives every other member of the group (its back face, the way
back and the back face of the way back) and spawns them all together.
PortalBuilder builder = ReforgedApi.get().portals().builder(serverLevel);PortalService.builder(ServerLevel) starts a description whose primary surface lives in that
level. PortalService is @Stable; PortalBuilder is @Experimental and may still change.
The builder
Section titled “The builder”| Method | What it sets | Default |
|---|---|---|
origin(Vec3) |
Centre of the primary surface. Required. | — |
facing(Direction) |
Axis-aligned orientation: the surface’s front faces this direction. | SOUTH |
orientation(Quat) |
Any orientation (replaces facing). |
— |
size(double width, double height) |
A rectangle of width × height blocks, centred on the origin. |
1 × 2 |
shape(Shape2D) |
Any outline, in blocks, in the surface’s own plane. | — |
destination(ResourceKey<Level>, Vec3) |
The level it leads to and where the surface’s centre ends up there. Required. | — |
rotation(Quat) |
Rotation applied to everything that goes through. | none |
scale(double) |
Uniform scale applied to everything that goes through. | 1 |
flags(int) |
Behaviour flags, see PortalFlags. |
PortalFlags.DEFAULTS |
twoWay() |
Also creates the surface at the destination that leads back. | one-way |
twoSided() |
Makes every surface enterable from both faces. | one-sided |
groupId(UUID) |
Uses this id for the group instead of a random one. | random |
Then finish with one of:
preview()returns the surfaces as aMap<GroupRole, PortalSnapshot>and changes nothing in the world. It throwsIllegalStateExceptionwhenoriginordestinationis missing.build()spawns every surface in its level, loading the chunks it needs, and returns the group’s id. It then firesPortalEvents.CREATED. It throwsIllegalArgumentExceptionwhen a destination dimension does not exist. Call it on the server thread.
size and scale reject values that are not positive. A mirror (the MIRROR flag) cannot be
two-way.
Position and orientation
Section titled “Position and orientation”A surface has a front: the side its facing direction points to. You see the other side and
enter the portal from the front. With facing(Direction.SOUTH) the front looks south, so you walk
north into it, coming from the south.
facing(Direction.NORTH | SOUTH | EAST | WEST)makes an upright portal, like a door.facing(Direction.UP)makes a portal lying on the floor, entered from above by falling in;facing(Direction.DOWN)one on the ceiling, entered from below.orientation(Quat)places the surface any way you like. The rotation takes the X axis to the surface’s width direction, Y to its height direction and Z to its front direction. The identity rotation is the same asfacing(Direction.SOUTH).
The origin is the centre of the surface. For an upright rectangle whose bottom edge should rest
on a floor at height y, use y + height / 2.
Outline
Section titled “Outline”size(width, height) is a shortcut for a centred rectangle. shape(Shape2D) takes any outline from
the engine, measured in blocks in the surface’s own plane, with (0, 0) at the origin, u along
the width and v along the height:
| Shape | Created with | Use |
|---|---|---|
RectShape |
RectShape.centered(width, height) |
Rectangles (fastest everywhere). |
PolygonShape |
PolygonShape.ellipse(width, height, segments), PolygonShape.of(double[]) |
Round portals, any simple polygon. |
RectUnionShape |
RectUnionShape.of(List<Rect2D>) |
Unions of non-overlapping rectangles, such as the openings of block frames. |
Where it leads
Section titled “Where it leads”destination(level, exit) says which level the portal opens into and where the centre of the
surface appears there. Everything else follows from the surface: the exit has the same shape and,
without a rotation, the same orientation.
rotation(Quat) turns space on the way through. With
rotation(Quat.axisAngleDegrees(Vec3D.UNIT_Y, 90)), a portal you enter heading north lets you out
heading west: your movement, your view and the exit surface are all turned by 90 degrees around the
vertical axis.
scale(s) multiplies distances on the way through by s: the exit, and everything you see through
it, is s times the size of the entrance. It is not the 1:8 coordinate ratio of the Nether: for
that, choose the exit coordinates yourself (divide by 8) and keep the scale at 1, as lit Nether
frames do. Resizing the entities that go through a scaled portal is not implemented yet.
Groups and roles
Section titled “Groups and roles”| Role | Present when | What it is |
|---|---|---|
PRIMARY |
always | The surface you described. Its id is the group id. |
BACKFACE |
twoSided() |
The same surface, entered from behind. |
REVERSE |
twoWay() |
At the destination: leads back to the primary. |
REVERSE_BACKFACE |
twoWay() and twoSided() |
The way back, entered from behind. |
The ids of the other members are derived from the group id
(PortalGroupLayout.memberId(group, role)), so the same group id always gives the same member ids.
The map returned by preview() iterates in this order.
A group is created as a whole. Removing it from code is not part of API level 1 yet; players can
remove one with /ipr remove.
Examples
Section titled “Examples”A round portal into the End
Section titled “A round portal into the End”A one-way portal, two blocks across, that you can enter from both faces. The exit hangs in the air above the End’s main island.
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 net.night.ipreforged.core.geom.PolygonShape;
import java.util.UUID;
public final class EndPortals {
private EndPortals() { }
public static UUID roundWindow(ServerLevel level, Vec3 centre) { return ReforgedApi.get().portals() .builder(level) .origin(centre) .facing(Direction.EAST) .shape(PolygonShape.ellipse(2, 2, 32)) // a circle with 32 sides .destination(Level.END, new Vec3(0.5, 90, 0.5)) .twoSided() .build(); }}A trapdoor to the Nether
Section titled “A trapdoor to the Nether”A portal lying over a hole in the floor. Fall into it and you come out under the exit, in the Nether, still falling. Being two-way, it can be taken back by going up into the exit from below.
Leave the hole open under the portal: there is no collision across portals yet, so a solid floor under the surface would stop you before you cross.
package com.example.portals;
import net.minecraft.core.BlockPos;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 Trapdoors {
private Trapdoors() { }
/** Covers the 2 × 2 hole whose north-west block is {@code corner}. */ public static UUID toNether(ServerLevel overworld, BlockPos corner) { // Middle of the hole, level with the top of the floor around it. Vec3 centre = new Vec3(corner.getX() + 1.0, corner.getY() + 1.0, corner.getZ() + 1.0); Vec3 exit = new Vec3(centre.x / 8.0, 100, centre.z / 8.0); return ReforgedApi.get().portals() .builder(overworld) .origin(centre) .facing(Direction.UP) // entered from above .size(2, 2) .destination(Level.NETHER, exit) .twoWay() .build(); }}Turning on the way through
Section titled “Turning on the way through”A doorway whose exit is turned by 90 degrees. You walk in heading north and come out heading west.
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 net.night.ipreforged.core.math.Quat;import net.night.ipreforged.core.math.Vec3D;
import java.util.UUID;
public final class TurningDoor {
private TurningDoor() { }
public static UUID open(ServerLevel level, Vec3 doorCentre, Vec3 exitCentre) { return ReforgedApi.get().portals() .builder(level) .origin(doorCentre) .facing(Direction.SOUTH) .size(1, 2) .destination(Level.NETHER, exitCentre) .rotation(Quat.axisAngleDegrees(Vec3D.UNIT_Y, 90)) .twoWay() .twoSided() .build(); }}Checking a group before building it
Section titled “Checking a group before building it”preview() gives you every surface as an immutable PortalSnapshot, so you
can look at a group before it exists: for example, refuse to build when the exit would land below
the world.
package com.example.portals;
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 net.night.ipreforged.api.portal.PortalBuilder;import net.night.ipreforged.core.math.Box3D;import net.night.ipreforged.core.portal.GroupRole;import net.night.ipreforged.core.portal.PortalSnapshot;
import java.util.Map;import java.util.Optional;import java.util.UUID;
public final class SafePortals {
private SafePortals() { }
/** Builds the portal unless its exit would reach below {@code minY}. */ public static Optional<UUID> openAbove(ServerLevel level, Vec3 origin, Vec3 exit, double minY) { PortalBuilder builder = ReforgedApi.get().portals() .builder(level) .origin(origin) .size(3, 3) .destination(Level.NETHER, exit) .twoWay();
Map<GroupRole, PortalSnapshot> surfaces = builder.preview(); Box3D exitArea = surfaces.get(GroupRole.PRIMARY).exitBounds(); if (exitArea.minY() < minY) { return Optional.empty(); } return Optional.of(builder.build()); }}preview() and build() on the same builder describe the same group as long as you set a group id
with groupId(...); without one, each call picks a new random id. The geometry is the same either
way.
