From 9c89f85dc84bd6769a13d088b254d205aa6c6fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 22:32:20 -0700 Subject: [PATCH 1/4] begin v0.2.3 --- changelog.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index 5ece566..b7c6eb6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,3 @@ -- Player camera now leans while their train is on a slope. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/11) - - Also, camera now rolls when facing sideways on a slope. - - (hopefully this feature doesn't break other mods) -- Player legs are now locked forward while seated on a train. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/13) -- Players standing on a train will now be affected the same way as players sitting. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/14) - - This does not fix the Create mod issue where standing players may be ejected from the train if it is traveling at high speeds. -- Players riding taller trains now lean correctly. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/16) Known issues: - The mod's leaning is a bit jittery. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22) @@ -12,7 +5,7 @@ Known issues: - The easing back to normal posture after jumping off a train on a slope could use some work. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/23) - The third-person camera is janky while on a train currently on a slope. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/24) -[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.2.1...v0.2.2) +[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.2.2...v0.2.3) --- From 1cc6d27b95856b27dc05a31e3450e693826ad704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 12 May 2024 11:20:40 -0700 Subject: [PATCH 2/4] fix: apply roll first --- .../create/trainperspective/mixin/GameRendererMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java index a288f09..8263453 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java @@ -16,7 +16,7 @@ public class GameRendererMixin { @Shadow @Final private Camera mainCamera; - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", ordinal = 3, shift = At.Shift.AFTER)) + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", ordinal = 2, shift = At.Shift.BEFORE)) public void applyZRotation(float f, long l, PoseStack poseStack, CallbackInfo ci) { poseStack.mulPose(Axis.ZP.rotationDegrees(MixinUtil.asCamera3D(mainCamera).getZRot())); } From d70799192f4f7e5e9f7fd70feb036ad9567cf18b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 12 May 2024 11:24:06 -0700 Subject: [PATCH 3/4] feat: compatibility with "do a barrel roll" --- .../create/trainperspective/Camera3D.java | 1 - .../trainperspective/mixin/CameraMixin.java | 36 +++++++------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java index c9975c0..394a6bc 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java @@ -2,5 +2,4 @@ public interface Camera3D { float getZRot(); - void setRotation3D(float y, float x, float z); } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java index 515608e..5f8b735 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java @@ -7,40 +7,26 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; -import org.joml.Quaternionf; -import org.joml.Vector3f; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(Camera.class) -@Implements({@Interface(iface = Camera3D.class, prefix = "ctp$")}) +@Implements({@Interface(iface = Camera3D.class, prefix = "c3d$")}) public abstract class CameraMixin { @Shadow private Entity entity; - @Shadow private float xRot; - @Shadow private float yRot; @Unique private float ctp$zRot; - @Shadow @Final private Quaternionf rotation; - @Shadow @Final private Vector3f forwards; - @Shadow @Final private Vector3f up; - @Shadow @Final private Vector3f left; - @Shadow protected abstract void setRotation(float f, float g); - @Unique - public void ctp$setRotation3D(float y, float x, float z) { - this.xRot = x; - this.yRot = y; - this.ctp$zRot = z; - this.rotation.rotationYXZ(-y * 0.017453292F, x * 0.017453292F, z * 0.017453292F); - this.forwards.set(0.0F, 0.0F, 1.0F).rotate(this.rotation); - this.up.set(0.0F, 1.0F, 0.0F).rotate(this.rotation); - this.left.set(1.0F, 0.0F, 0.0F).rotate(this.rotation); + @ModifyArg(method = "setRotation", at = @At(value = "INVOKE", target = "Lorg/joml/Quaternionf;rotationYXZ(FFF)Lorg/joml/Quaternionf;"), index = 2) + private float modifyRoll(float original) { + return original + ctp$zRot; } @Unique - public float ctp$getZRot() { + public float c3d$getZRot() { return this.ctp$zRot; } @@ -48,9 +34,11 @@ public abstract class CameraMixin { public void modifyRotationsPrimary(Camera instance, float y, float x) { if(entity instanceof LocalPlayer player) { var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - ctp$setRotation3D(y, - x - persp.getLean() * Mth.sin((persp.getYaw() - y) * Mth.DEG_TO_RAD), - persp.getLean() * Mth.cos((persp.getYaw() - y) * Mth.DEG_TO_RAD)); - } else setRotation(y, x); + ctp$zRot = persp.getLean() * Mth.cos((persp.getYaw() - y) * Mth.DEG_TO_RAD); + setRotation(y, x - persp.getLean() * Mth.sin((persp.getYaw() - y) * Mth.DEG_TO_RAD)); + } else { + ctp$zRot = 0; + setRotation(y, x); + } } } From ca383998f3e0e207da66af5ac5b337577d2a4a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 12 May 2024 13:03:59 -0700 Subject: [PATCH 4/4] #24 greatly improve camera movement in third-person MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit still not perfect, but much better Signed-off-by: der_frühling --- .../minecraft/create/trainperspective/mixin/CameraMixin.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java index 5f8b735..0143203 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java @@ -1,5 +1,6 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; +import com.llamalad7.mixinextras.sugar.Local; import net.derfruhling.minecraft.create.trainperspective.Camera3D; import net.derfruhling.minecraft.create.trainperspective.Perspective; import net.minecraft.client.Camera; @@ -31,8 +32,8 @@ private float modifyRoll(float original) { } @Redirect(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V")) - public void modifyRotationsPrimary(Camera instance, float y, float x) { - if(entity instanceof LocalPlayer player) { + public void modifyRotationsPrimary(Camera instance, float y, float x, @Local(argsOnly = true, ordinal = 1) boolean isThirdPerson) { + if(entity instanceof LocalPlayer player && !isThirdPerson) { var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); ctp$zRot = persp.getLean() * Mth.cos((persp.getYaw() - y) * Mth.DEG_TO_RAD); setRotation(y, x - persp.getLean() * Mth.sin((persp.getYaw() - y) * Mth.DEG_TO_RAD));