Link preview camera to player movement
Build / build (push) Canceled after 0s

This commit is contained in:
dnorberg committed 2026-09-22 05:49:43 -04:00
1 parent 00ed05e51a
commit d878c89ba4
3 files changed
+69 -25

No files matched your search

+6
View File
@@ -306,6 +306,12 @@ screens while Explore mode is active. Movement, jump, and sneak now move the
remote camera even though Minecraft suspends normal gameplay key states while remote camera even though Minecraft suspends normal gameplay key states while
a GUI is open. a GUI is open.
Version 0.2.16.8 links Explore mode to real player movement in the current
dimension. Entering Explore anchors the source player and destination camera;
walking, jumping, falling, or being moved shifts the snapshot camera by the
same displacement while the book remains open and normal collision still
applies.
The preview code is separated behind a renderer interface and uses an isolated The preview code is separated behind a renderer interface and uses an isolated
Ponder level populated from server-authoritative destination snapshots. Ponder level populated from server-authoritative destination snapshots.
+1 -1
View File
@@ -35,7 +35,7 @@ mod_name=Rivencraft
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=LGPL-3.0-or-later mod_license=LGPL-3.0-or-later
# The mod version. Rivencraft uses the x.y.z.b policy documented in README.md. # The mod version. Rivencraft uses the x.y.z.b policy documented in README.md.
mod_version=0.2.16.7 mod_version=0.2.16.8
immersive_portals_version=6.0.7 immersive_portals_version=6.0.7
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources. # This should match the base package used for the mod sources.
@@ -24,6 +24,8 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
private final Minecraft minecraft = Minecraft.getInstance(); private final Minecraft minecraft = Minecraft.getInstance();
private LinkPreviewPayload destination; private LinkPreviewPayload destination;
private Vec3 cameraPosition; private Vec3 cameraPosition;
private Vec3 explorationPlayerOrigin;
private Vec3 explorationCameraOrigin;
private float yaw; private float yaw;
private float pitch; private float pitch;
private int ticks; private int ticks;
@@ -48,17 +50,8 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
if (!exploring || cameraPosition == null) { if (!exploring || cameraPosition == null) {
return; return;
} }
double forward = (movingForward ? 1.0D : 0.0D) - (movingBackward ? 1.0D : 0.0D); if (minecraft.player != null && explorationPlayerOrigin != null && explorationCameraOrigin != null) {
double strafe = (movingRight ? 1.0D : 0.0D) - (movingLeft ? 1.0D : 0.0D); cameraPosition = explorationCameraOrigin.add(minecraft.player.position().subtract(explorationPlayerOrigin));
double vertical = (movingUp ? 1.0D : 0.0D) - (movingDown ? 1.0D : 0.0D);
double radians = Math.toRadians(yaw);
Vec3 motion = new Vec3(
-Math.sin(radians) * forward + Math.cos(radians) * strafe,
vertical,
Math.cos(radians) * forward + Math.sin(radians) * strafe
);
if (motion.lengthSqr() > 0.0D) {
cameraPosition = cameraPosition.add(motion.normalize().scale(0.22D));
} }
} }
@@ -128,7 +121,18 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
@Override public boolean supportsExploration() { return true; } @Override public boolean supportsExploration() { return true; }
@Override public boolean isExploring() { return exploring; } @Override public boolean isExploring() { return exploring; }
@Override public void setExploring(boolean exploring) { this.exploring = exploring; } @Override
public void setExploring(boolean exploring) {
this.exploring = exploring;
if (exploring && minecraft.player != null) {
explorationPlayerOrigin = minecraft.player.position();
explorationCameraOrigin = cameraPosition;
} else {
clearMovement();
explorationPlayerOrigin = null;
explorationCameraOrigin = null;
}
}
@Override @Override
public void rotate(double deltaX, double deltaY) { public void rotate(double deltaX, double deltaY) {
@@ -143,12 +147,25 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
if (!exploring) { if (!exploring) {
return false; return false;
} }
if (minecraft.options.keyUp.matches(keyCode, scanCode)) movingForward = true; if (minecraft.options.keyUp.matches(keyCode, scanCode)) {
else if (minecraft.options.keyDown.matches(keyCode, scanCode)) movingBackward = true; movingForward = true;
else if (minecraft.options.keyLeft.matches(keyCode, scanCode)) movingLeft = true; minecraft.options.keyUp.setDown(true);
else if (minecraft.options.keyRight.matches(keyCode, scanCode)) movingRight = true; } else if (minecraft.options.keyDown.matches(keyCode, scanCode)) {
else if (minecraft.options.keyJump.matches(keyCode, scanCode)) movingUp = true; movingBackward = true;
else if (minecraft.options.keyShift.matches(keyCode, scanCode)) movingDown = true; minecraft.options.keyDown.setDown(true);
} else if (minecraft.options.keyLeft.matches(keyCode, scanCode)) {
movingLeft = true;
minecraft.options.keyLeft.setDown(true);
} else if (minecraft.options.keyRight.matches(keyCode, scanCode)) {
movingRight = true;
minecraft.options.keyRight.setDown(true);
} else if (minecraft.options.keyJump.matches(keyCode, scanCode)) {
movingUp = true;
minecraft.options.keyJump.setDown(true);
} else if (minecraft.options.keyShift.matches(keyCode, scanCode)) {
movingDown = true;
minecraft.options.keyShift.setDown(true);
}
else return false; else return false;
return true; return true;
} }
@@ -156,12 +173,25 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
@Override @Override
public boolean keyReleased(int keyCode, int scanCode) { public boolean keyReleased(int keyCode, int scanCode) {
boolean handled = true; boolean handled = true;
if (minecraft.options.keyUp.matches(keyCode, scanCode)) movingForward = false; if (minecraft.options.keyUp.matches(keyCode, scanCode)) {
else if (minecraft.options.keyDown.matches(keyCode, scanCode)) movingBackward = false; movingForward = false;
else if (minecraft.options.keyLeft.matches(keyCode, scanCode)) movingLeft = false; minecraft.options.keyUp.setDown(false);
else if (minecraft.options.keyRight.matches(keyCode, scanCode)) movingRight = false; } else if (minecraft.options.keyDown.matches(keyCode, scanCode)) {
else if (minecraft.options.keyJump.matches(keyCode, scanCode)) movingUp = false; movingBackward = false;
else if (minecraft.options.keyShift.matches(keyCode, scanCode)) movingDown = false; minecraft.options.keyDown.setDown(false);
} else if (minecraft.options.keyLeft.matches(keyCode, scanCode)) {
movingLeft = false;
minecraft.options.keyLeft.setDown(false);
} else if (minecraft.options.keyRight.matches(keyCode, scanCode)) {
movingRight = false;
minecraft.options.keyRight.setDown(false);
} else if (minecraft.options.keyJump.matches(keyCode, scanCode)) {
movingUp = false;
minecraft.options.keyJump.setDown(false);
} else if (minecraft.options.keyShift.matches(keyCode, scanCode)) {
movingDown = false;
minecraft.options.keyShift.setDown(false);
}
else handled = false; else handled = false;
return handled; return handled;
} }
@@ -173,12 +203,20 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
movingRight = false; movingRight = false;
movingUp = false; movingUp = false;
movingDown = false; movingDown = false;
minecraft.options.keyUp.setDown(false);
minecraft.options.keyDown.setDown(false);
minecraft.options.keyLeft.setDown(false);
minecraft.options.keyRight.setDown(false);
minecraft.options.keyJump.setDown(false);
minecraft.options.keyShift.setDown(false);
} }
@Override @Override
public void resetView() { public void resetView() {
exploring = false; exploring = false;
clearMovement(); clearMovement();
explorationPlayerOrigin = null;
explorationCameraOrigin = null;
if (destination != null) { if (destination != null) {
cameraPosition = Vec3.atCenterOf(destination.origin()).add(0.0D, 2.0D, ORBIT_RADIUS); cameraPosition = Vec3.atCenterOf(destination.origin()).add(0.0D, 2.0D, ORBIT_RADIUS);
yaw = destination.yaw(); yaw = destination.yaw();