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) --- 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); + } } } 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())); }