Geometry types
The API describes portals with the engine’s own types, from the net.night.ipreforged.core
packages. They are plain Java: no Minecraft classes, immutable and safe to share between threads.
The same types are used by every algorithm of the mod (crossing, rendering, chunk loading), so what
you compute with them matches what the mod does.
Converting from Minecraft types
Section titled “Converting from Minecraft types”The engine has its own vector type, Vec3D. Converting is a one-liner each way:
package com.example.portals;
import net.minecraft.world.phys.Vec3;import net.night.ipreforged.core.math.Vec3D;
public final class Vectors {
private Vectors() { }
public static Vec3D toEngine(Vec3 v) { return new Vec3D(v.x, v.y, v.z); }
public static Vec3 toMinecraft(Vec3D v) { return new Vec3(v.x(), v.y(), v.z()); }}Dimensions are identified by their id as a string, such as "minecraft:the_nether". To compare
with a ResourceKey<Level>, convert the key: key.location().toString() on Minecraft 1.20.1 and
1.21.1, key.identifier().toString() on 26.1.2.
PortalSnapshot
Section titled “PortalSnapshot”One portal surface at one moment: where it is, its outline, where it leads and how it maps space.
Events and PortalBuilder.preview() give you snapshots.
| Member | Returns |
|---|---|
id() |
The surface’s id (for the primary surface, also the group id). |
dimension(), targetDimension() |
Ids of the dimension it is in and of the one it leads to. |
frame() |
Its Frame3D: position and orientation. |
shape() |
Its outline, a Shape2D. |
warp() |
The Warp that carries space to the other side. |
flags(), hasFlag(int) |
Its flags. |
plane() |
The plane of the surface, normal pointing to the front. |
bounds(), exitBounds() |
Axis-aligned boxes around the surface, here and at the destination. |
exitOrigin() |
Where the surface’s centre maps to. |
isInFront(Vec3D) |
Whether a point is on the front side. |
projectsInside(Vec3D) |
Whether a point, projected on the plane, falls inside the outline. |
crossingFraction(Vec3D from, Vec3D to, double tolerance) |
Where along a movement it passes through from front to back, inside the outline, as a fraction from 0 to 1; NaN if it does not. |
distanceTo(Vec3D) |
Distance to the surface’s bounding rectangle. |
reverse(UUID), flipped(UUID) |
The surface leading back, and the same surface seen from behind. |
withShape, withFlags, withFrame, withWarp |
Copies with one part changed. |
PortalSnapshot.create(...) builds one from scratch, the way the builder does.
A similarity transform: a rotation (possibly with a reflection), a uniform scale and a translation. Every portal carries one, mapping its entrance side onto its exit side.
| Member | Does |
|---|---|
applyPoint(Vec3D) |
Carries a position through: rotation, scale and translation. |
applyVector(Vec3D) |
Carries a displacement or a velocity: rotation and scale, no translation. |
applyDirection(Vec3D) |
Carries a direction: rotation only, length kept. |
applyBox, applyPlane, applyFrame |
The same for boxes, planes and frames. |
inverse() |
The way back. |
then(Warp) |
This warp followed by another. |
scale(), mirrored() |
The scale, and whether it reverses handedness. |
For example, to find where an entity’s eyes, and the direction it looks in, would be on the other side of a portal:
package com.example.portals;
import net.minecraft.world.entity.Entity;import net.minecraft.world.phys.Vec3;import net.night.ipreforged.core.math.Vec3D;import net.night.ipreforged.core.math.Warp;import net.night.ipreforged.core.portal.PortalSnapshot;
public final class ThroughPortal {
private ThroughPortal() { }
/** Where the entity's eyes would be on the other side of the portal. */ public static Vec3 eyesOnTheOtherSide(Entity entity, PortalSnapshot portal) { Vec3 eyes = entity.getEyePosition(); Vec3D there = portal.warp().applyPoint(new Vec3D(eyes.x, eyes.y, eyes.z)); return new Vec3(there.x(), there.y(), there.z()); }
/** The direction the entity would be looking in on the other side. */ public static Vec3D lookOnTheOtherSide(Entity entity, PortalSnapshot portal) { Vec3 look = entity.getLookAngle(); Warp warp = portal.warp(); return warp.applyDirection(new Vec3D(look.x, look.y, look.z)); }}Frame3D
Section titled “Frame3D”A position plus two unit axes: axisU() along the surface’s width and axisV() along its height.
The front direction is normal(), which is axisU × axisV.
toLocal(Vec3D)gives a world point’s coordinates(u, v, n)in the frame;toWorld(u, v, n)goes back.signedDistance(Vec3D)is positive in front of the surface.reversed()is the same place facing the other way.Frame3D.fromOrientation(origin, quat)builds one from a rotation, asPortalBuilder.orientationdoes.
Quat and Vec3D
Section titled “Quat and Vec3D”Quat is a rotation stored as a unit quaternion, (w, x, y, z), in double precision.
Quat.IDENTITY,Quat.axisAngle(axis, radians),Quat.axisAngleDegrees(axis, degrees),Quat.between(from, to).rotate(Vec3D)turns a vector;a.mul(b)appliesbfirst, thena;inverse();Quat.slerp(a, b, t)interpolates.- Positive angles turn counter-clockwise when you look from the tip of the axis towards the origin.
Vec3D is a record (x, y, z) with the usual operations: add, sub, mul, dot, cross,
length, normalized, lerp, and the constants ZERO, UNIT_X, UNIT_Y, UNIT_Z.
Shapes
Section titled “Shapes”An outline lives in the surface’s own plane, in blocks, with u along the width and v along the
height. Shape2D is a sealed interface with three kinds:
| Kind | kind() |
Create with |
|---|---|---|
RectShape |
"rect" |
RectShape.centered(width, height), new RectShape(new Rect2D(minU, minV, maxU, maxV)) |
PolygonShape |
"polygon" |
PolygonShape.ellipse(width, height, segments), PolygonShape.of(double[] coords), PolygonShape.of(List<Vec2D>) |
RectUnionShape |
"rect_union" |
RectUnionShape.of(List<Rect2D>), from rectangles that do not overlap |
Polygons must be simple (no self-intersections, no holes); the vertex order does not matter. Every
shape offers contains(u, v), bounds(), area(), triangles(), scaled(su, sv) and
translated(du, dv).
Group roles
Section titled “Group roles”GroupRole names the members of a group: PRIMARY, BACKFACE, REVERSE, REVERSE_BACKFACE.
See Groups and roles. PortalGroupLayout.memberId(group, role)
gives the id of any member from the group id.
Portal flags
Section titled “Portal flags”PortalFlags holds bit flags, combined into one int. Bits 0 to 15 are reserved for the mod; bits
16 to 31 are free for add-ons. PortalFlags.has(flags, flag) and PortalFlags.with(flags, flag, on)
read and change them.
Many flags are declared ahead of the features that will use them. This table says which ones have an effect in 0.1.0-alpha:
| Flag | Meaning | In 0.1.0-alpha |
|---|---|---|
VISIBLE |
The other side is drawn through the surface. | Declared, not read yet |
TELEPORTABLE |
Entities crossing the surface are moved to the other side. | Active |
INTERACTABLE |
Players can use blocks and hit entities through the surface. | Declared, not read yet |
MIRROR |
The surface reflects instead of leading elsewhere. | Such surfaces are skipped: not drawn, not crossed |
CROSS_COLLISION |
Collision boxes from the other side count when an entity straddles the surface. | Declared, not read yet |
SHOW_SELF |
You can see yourself through this portal. | Declared, not read yet |
FUSE_VIEW |
The view blends into the world with no visible edge. | Declared, not read yet |
MERGEABLE |
Adjacent portals with the same warp may be drawn in one pass. | Declared, not read yet |
SCALES_ENTITIES |
Going through changes an entity’s size by the portal’s scale. | Declared, not read yet |
ROTATES_GRAVITY |
Going through re-orients gravity. | Declared, not read yet |
OCCLUSION_CULLABLE |
The portal may be skipped when something hides it. | Declared, not read yet |
PLAYER_SPECIFIC |
Only one player can see and use the portal. | Declared, not read yet |
FRAME_BOUND |
The portal breaks when its block frame is damaged. | Active (set on lit Nether frames) |
PortalFlags.DEFAULTS is VISIBLE | TELEPORTABLE | INTERACTABLE | CROSS_COLLISION | MERGEABLE | SCALES_ENTITIES | OCCLUSION_CULLABLE.
