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

@@ -24,6 +24,8 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
private final Minecraft minecraft = Minecraft.getInstance();
private LinkPreviewPayload destination;
private Vec3 cameraPosition;
private Vec3 explorationPlayerOrigin;
private Vec3 explorationCameraOrigin;
private float yaw;
private float pitch;
private int ticks;
@@ -48,17 +50,8 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
if (!exploring || cameraPosition == null) {
return;
}
double forward = (movingForward ? 1.0D : 0.0D) - (movingBackward ? 1.0D : 0.0D);
double strafe = (movingRight ? 1.0D : 0.0D) - (movingLeft ? 1.0D : 0.0D);
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));
if (minecraft.player != null && explorationPlayerOrigin != null && explorationCameraOrigin != null) {
cameraPosition = explorationCameraOrigin.add(minecraft.player.position().subtract(explorationPlayerOrigin));
}
}
@@ -128,7 +121,18 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
@Override public boolean supportsExploration() { return true; }
@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
public void rotate(double deltaX, double deltaY) {
@@ -143,12 +147,25 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
if (!exploring) {
return false;
}
if (minecraft.options.keyUp.matches(keyCode, scanCode)) movingForward = true;
else if (minecraft.options.keyDown.matches(keyCode, scanCode)) movingBackward = true;
else if (minecraft.options.keyLeft.matches(keyCode, scanCode)) movingLeft = true;
else if (minecraft.options.keyRight.matches(keyCode, scanCode)) movingRight = true;
else if (minecraft.options.keyJump.matches(keyCode, scanCode)) movingUp = true;
else if (minecraft.options.keyShift.matches(keyCode, scanCode)) movingDown = true;
if (minecraft.options.keyUp.matches(keyCode, scanCode)) {
movingForward = true;
minecraft.options.keyUp.setDown(true);
} else if (minecraft.options.keyDown.matches(keyCode, scanCode)) {
movingBackward = 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;
return true;
}
@@ -156,12 +173,25 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
@Override
public boolean keyReleased(int keyCode, int scanCode) {
boolean handled = true;
if (minecraft.options.keyUp.matches(keyCode, scanCode)) movingForward = false;
else if (minecraft.options.keyDown.matches(keyCode, scanCode)) movingBackward = false;
else if (minecraft.options.keyLeft.matches(keyCode, scanCode)) movingLeft = false;
else if (minecraft.options.keyRight.matches(keyCode, scanCode)) movingRight = false;
else if (minecraft.options.keyJump.matches(keyCode, scanCode)) movingUp = false;
else if (minecraft.options.keyShift.matches(keyCode, scanCode)) movingDown = false;
if (minecraft.options.keyUp.matches(keyCode, scanCode)) {
movingForward = false;
minecraft.options.keyUp.setDown(false);
} else if (minecraft.options.keyDown.matches(keyCode, scanCode)) {
movingBackward = 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;
return handled;
}
@@ -173,12 +203,20 @@ public final class ImmersivePortalsDestinationPreviewRenderer implements Destina
movingRight = false;
movingUp = 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
public void resetView() {
exploring = false;
clearMovement();
explorationPlayerOrigin = null;
explorationCameraOrigin = null;
if (destination != null) {
cameraPosition = Vec3.atCenterOf(destination.origin()).add(0.0D, 2.0D, ORBIT_RADIUS);
yaw = destination.yaw();