From 60feb817d040ab50335c14f2edfb5fe1e6dde984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 01:48:26 -0700 Subject: [PATCH 01/18] add environment attributes to mixins and start v0.3.0 --- .../minecraft/create/trainperspective/mixin/CameraMixin.java | 3 +++ .../trainperspective/mixin/ContraptionColliderMixin.java | 3 +++ .../minecraft/create/trainperspective/mixin/EntityMixin.java | 5 ++++- .../create/trainperspective/mixin/GameRendererMixin.java | 3 +++ .../create/trainperspective/mixin/PlayerRendererMixin.java | 4 ++++ gradle.properties | 2 +- 6 files changed, 18 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 0143203..7808c68 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 @@ -3,6 +3,8 @@ import com.llamalad7.mixinextras.sugar.Local; import net.derfruhling.minecraft.create.trainperspective.Camera3D; import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -15,6 +17,7 @@ @Mixin(Camera.class) @Implements({@Interface(iface = Camera3D.class, prefix = "c3d$")}) +@Environment(EnvType.CLIENT) public abstract class CameraMixin { @Shadow private Entity entity; @Unique private float ctp$zRot; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java index 9fa6864..4b85f2e 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java @@ -4,12 +4,15 @@ import com.simibubi.create.content.contraptions.ContraptionCollider; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ContraptionCollider.class) +@Environment(EnvType.CLIENT) public class ContraptionColliderMixin { @Inject(method = "collideEntities", at = @At("HEAD"), remap = false) private static void saveClientPlayerFromClipping( diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java index d29c011..6cb7afd 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java @@ -1,6 +1,8 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.world.entity.Entity; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -11,7 +13,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Entity.class) -public class EntityMixin { +@Environment(EnvType.CLIENT) +public abstract class EntityMixin { @Shadow @Nullable private Entity vehicle; @Inject(method = "startRiding(Lnet/minecraft/world/entity/Entity;Z)Z", at = @At(value = "RETURN", ordinal = 4)) 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 8263453..d02b082 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 @@ -3,6 +3,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import net.derfruhling.minecraft.create.trainperspective.MixinUtil; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.Camera; import net.minecraft.client.renderer.GameRenderer; import org.spongepowered.asm.mixin.Final; @@ -13,6 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GameRenderer.class) +@Environment(EnvType.CLIENT) public class GameRendererMixin { @Shadow @Final private Camera mainCamera; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java index 8faae07..f219dd5 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java @@ -2,7 +2,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; +import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.util.Mth; @@ -16,6 +19,7 @@ @Mixin(PlayerRenderer.class) @Implements({@Interface(iface = Perspective.class, prefix = "ctp$")}) +@Environment(EnvType.CLIENT) public class PlayerRendererMixin { @Unique private boolean ctp$perspectiveActive = false; @Unique private float ctp$lean = 0.0f, ctp$yaw = 0.0f; diff --git a/gradle.properties b/gradle.properties index 5d0c324..7489ca8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ quilt_loader_version=0.21.2-beta.2 quilt_fabric_api_version=7.4.0+0.90.0-1.20.1 mod_id=create_train_perspective -mod_version=0.2.3 +mod_version=0.3.0 maven_group=net.derfruhling.minecraft archives_base_name=create-train-perspective From 9e5e125ff4a4d70bfcf4ca894ecbad3e910b8ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 01:49:07 -0700 Subject: [PATCH 02/18] add isEnabled() method to Perspective --- .../minecraft/create/trainperspective/Perspective.java | 1 + .../create/trainperspective/mixin/PlayerRendererMixin.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java index cb64c9b..639e35d 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java @@ -3,6 +3,7 @@ public interface Perspective { void enable(float initialLean, float initialYaw); void disable(); + boolean isEnabled(); void setLean(float lean); void setYaw(float yaw); float getLean(); diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java index f219dd5..1cf4461 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java @@ -33,6 +33,11 @@ public class PlayerRendererMixin { public void ctp$disable() { ctp$perspectiveActive = false; ctp$lean = 0.0f; + ctp$yaw = 0.0f; + } + + public boolean ctp$isEnabled() { + return ctp$perspectiveActive; } public void ctp$setLean(float lean) { From c395fa90f10c9be653e0424be1de3ea204127222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 01:50:07 -0700 Subject: [PATCH 03/18] #35 partially implement better block raycasts --- .../trainperspective/mixin/EntityMixin.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java index 6cb7afd..cd0ec52 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java @@ -1,14 +1,18 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; +import com.llamalad7.mixinextras.sugar.Local; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; +import net.derfruhling.minecraft.create.trainperspective.Perspective; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -16,6 +20,7 @@ @Environment(EnvType.CLIENT) public abstract class EntityMixin { @Shadow @Nullable private Entity vehicle; + @Shadow private Level level; @Inject(method = "startRiding(Lnet/minecraft/world/entity/Entity;Z)Z", at = @At(value = "RETURN", ordinal = 4)) public void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable cir) { @@ -28,4 +33,14 @@ public void onRemoveVehicle(CallbackInfo ci) { CreateTrainPerspectiveMod.INSTANCE.onEntityMount(false, (Entity)(Object)this, vehicle); } } + + @SuppressWarnings("UnreachableCode") + @ModifyVariable(method = "calculateViewVector", at = @At(value = "LOAD"), index = 1, argsOnly = true) + public float adjustViewVector(float original, @Local(argsOnly = true, index = 2) float yRot) { + if (this.level.isClientSide) { + if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { + return original - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + } else return original; + } else return original; + } } From 82ff9ae536cc1818f83adbc19e0e51bcb3a58d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 02:05:18 -0700 Subject: [PATCH 04/18] #35 jerry-rig fix for create's custom raycasting --- .../create/trainperspective/MixinUtil.java | 5 +++++ .../mixin/CreateRaycastHelperMixin.java | 20 +++++++++++++++++++ .../trainperspective/mixin/EntityMixin.java | 4 ++-- .../create_train_perspective.mixins.json | 3 ++- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index 79f8b09..314ff96 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -1,6 +1,7 @@ package net.derfruhling.minecraft.create.trainperspective; import net.minecraft.client.Camera; +import net.minecraft.util.Mth; public class MixinUtil { private MixinUtil() {} @@ -8,4 +9,8 @@ private MixinUtil() {} public static Camera3D asCamera3D(Camera camera) { return (Camera3D) camera; } + + public static float applyDirectionXRotChange(Perspective persp, float original, float yRot) { + return original - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java new file mode 100644 index 0000000..8386aeb --- /dev/null +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java @@ -0,0 +1,20 @@ +package net.derfruhling.minecraft.create.trainperspective.mixin; + +import com.simibubi.create.foundation.utility.RaycastHelper; +import net.derfruhling.minecraft.create.trainperspective.MixinUtil; +import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.minecraft.client.Minecraft; +import net.minecraft.world.entity.player.Player; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(RaycastHelper.class) +public class CreateRaycastHelperMixin { + @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 4) + private static float modifyXRot(float value, Player player) { + if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { + return MixinUtil.applyDirectionXRotChange(persp, value, player.getYRot()); + } else return value; + } +} diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java index cd0ec52..d796cad 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java @@ -2,11 +2,11 @@ import com.llamalad7.mixinextras.sugar.Local; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; +import net.derfruhling.minecraft.create.trainperspective.MixinUtil; import net.derfruhling.minecraft.create.trainperspective.Perspective; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; -import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; @@ -39,7 +39,7 @@ public void onRemoveVehicle(CallbackInfo ci) { public float adjustViewVector(float original, @Local(argsOnly = true, index = 2) float yRot) { if (this.level.isClientSide) { if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { - return original - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + return MixinUtil.applyDirectionXRotChange(persp, original, yRot); } else return original; } else return original; } diff --git a/common/src/main/resources/create_train_perspective.mixins.json b/common/src/main/resources/create_train_perspective.mixins.json index 4c8eb29..1a93dd3 100644 --- a/common/src/main/resources/create_train_perspective.mixins.json +++ b/common/src/main/resources/create_train_perspective.mixins.json @@ -6,9 +6,10 @@ "client": [ "CameraMixin", "ContraptionColliderMixin", + "EntityMixin", "GameRendererMixin", "PlayerRendererMixin", - "EntityMixin" + "CreateRaycastHelperMixin" ], "injectors": { "defaultRequire": 1 From 9c9dcbc5ba6ba7870413442c5aafffafaa276de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 02:13:08 -0700 Subject: [PATCH 05/18] #32 begin fix for bad floors with locked perspective --- .../minecraft/create/trainperspective/MixinUtil.java | 8 ++++++-- .../create/trainperspective/mixin/CameraMixin.java | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index 314ff96..c2ad60c 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -10,7 +10,11 @@ public static Camera3D asCamera3D(Camera camera) { return (Camera3D) camera; } - public static float applyDirectionXRotChange(Perspective persp, float original, float yRot) { - return original - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + public static float applyDirectionXRotChange(Perspective persp, float xRot, float yRot) { + return xRot - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + } + + public static float applyDirectionYRotChange(Perspective persp, float xRot, float yRot) { + return yRot + persp.getLean() * Mth.sin(xRot * Mth.DEG_TO_RAD); } } 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 7808c68..912b52e 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 @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.sugar.Local; import net.derfruhling.minecraft.create.trainperspective.Camera3D; +import net.derfruhling.minecraft.create.trainperspective.MixinUtil; import net.derfruhling.minecraft.create.trainperspective.Perspective; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -39,7 +40,10 @@ public void modifyRotationsPrimary(Camera instance, float y, float x, @Local(arg 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)); + setRotation( + MixinUtil.applyDirectionYRotChange(persp, x, y), + MixinUtil.applyDirectionXRotChange(persp, x, y) + ); } else { ctp$zRot = 0; setRotation(y, x); From 49be26419373497def02836591b9aa1df8820b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 02:44:32 -0700 Subject: [PATCH 06/18] #32 it's better now?? --- .../create/trainperspective/Camera3D.java | 1 + .../create/trainperspective/MixinUtil.java | 10 ++++++++- .../trainperspective/mixin/CameraMixin.java | 22 +++++++++++++++++-- .../mixin/GameRendererMixin.java | 1 + 4 files changed, 31 insertions(+), 3 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 394a6bc..7675707 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,4 +2,5 @@ public interface Camera3D { float getZRot(); + float getExtraYRot(); } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index c2ad60c..717ed8d 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -10,11 +10,19 @@ public static Camera3D asCamera3D(Camera camera) { return (Camera3D) camera; } + private static float invCos(float x) { + return Mth.cos(x + Mth.PI); + } + public static float applyDirectionXRotChange(Perspective persp, float xRot, float yRot) { return xRot - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); } public static float applyDirectionYRotChange(Perspective persp, float xRot, float yRot) { - return yRot + persp.getLean() * Mth.sin(xRot * Mth.DEG_TO_RAD); + return yRot - getExtraYRot(persp, xRot, yRot); + } + + public static float getExtraYRot(Perspective persp, float xRot, float yRot) { + return (persp.getLean() * Mth.sin(xRot * Mth.DEG_TO_RAD)) * invCos((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); } } 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 912b52e..612ae92 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 @@ -11,10 +11,13 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; +import org.joml.Quaternionf; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Camera.class) @Implements({@Interface(iface = Camera3D.class, prefix = "c3d$")}) @@ -22,30 +25,45 @@ public abstract class CameraMixin { @Shadow private Entity entity; @Unique private float ctp$zRot; + @Unique private float ctp$extraYRot; @Shadow protected abstract void setRotation(float f, float g); + @Shadow @Final private Quaternionf 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; } + @Inject(method = "setRotation", at = @At(value = "INVOKE", target = "Lorg/joml/Quaternionf;rotationYXZ(FFF)Lorg/joml/Quaternionf;", shift = At.Shift.AFTER)) + private void modifyQuaternion(float f, float g, CallbackInfo ci) { + this.rotation.rotateY(ctp$extraYRot); + } + @Unique public float c3d$getZRot() { return this.ctp$zRot; } + @Unique + public float c3d$getExtraYRot() { + return this.ctp$extraYRot; + } + @Redirect(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V")) - public void modifyRotationsPrimary(Camera instance, float y, float x, @Local(argsOnly = true, ordinal = 1) boolean isThirdPerson) { + public void modifyRotationsPrimary(Camera instance, float y, float x, @Local(argsOnly = true, ordinal = 0) 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); + ctp$extraYRot = MixinUtil.getExtraYRot(persp, x, y); setRotation( - MixinUtil.applyDirectionYRotChange(persp, x, y), + y, MixinUtil.applyDirectionXRotChange(persp, x, y) ); } else { ctp$zRot = 0; + ctp$extraYRot = 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 d02b082..18e6ff9 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 @@ -22,5 +22,6 @@ public class GameRendererMixin { @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())); + poseStack.mulPose(Axis.YP.rotationDegrees(MixinUtil.asCamera3D(mainCamera).getExtraYRot())); } } From 089cb9a38c79a01e9fd94c8df794a433d7c49b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 14:24:13 -0700 Subject: [PATCH 07/18] #32 simplify and improve by not using sin() --- .../minecraft/create/trainperspective/MixinUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index 717ed8d..96c5804 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -23,6 +23,6 @@ public static float applyDirectionYRotChange(Perspective persp, float xRot, floa } public static float getExtraYRot(Perspective persp, float xRot, float yRot) { - return (persp.getLean() * Mth.sin(xRot * Mth.DEG_TO_RAD)) * invCos((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + return persp.getLean() * (xRot / 90.0f) * invCos((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); } } From 8da50f0e2633384782d430019e96866fcf99e275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 14:56:23 -0700 Subject: [PATCH 08/18] #32 close enough --- .../create/trainperspective/MixinUtil.java | 4 ---- .../mixin/CreateRaycastHelperMixin.java | 7 +++++++ .../trainperspective/mixin/EntityMixin.java | 18 ++++++++++++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index 96c5804..c71ca25 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -18,10 +18,6 @@ public static float applyDirectionXRotChange(Perspective persp, float xRot, floa return xRot - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); } - public static float applyDirectionYRotChange(Perspective persp, float xRot, float yRot) { - return yRot - getExtraYRot(persp, xRot, yRot); - } - public static float getExtraYRot(Perspective persp, float xRot, float yRot) { return persp.getLean() * (xRot / 90.0f) * invCos((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java index 8386aeb..1af50a9 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java @@ -17,4 +17,11 @@ private static float modifyXRot(float value, Player player) { return MixinUtil.applyDirectionXRotChange(persp, value, player.getYRot()); } else return value; } + + @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 5) + private static float modifyYRot(float value, Player player) { + if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { + return value + MixinUtil.getExtraYRot(persp, player.getXRot(), value); + } else return value; + } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java index d796cad..404a889 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java @@ -36,11 +36,21 @@ public void onRemoveVehicle(CallbackInfo ci) { @SuppressWarnings("UnreachableCode") @ModifyVariable(method = "calculateViewVector", at = @At(value = "LOAD"), index = 1, argsOnly = true) - public float adjustViewVector(float original, @Local(argsOnly = true, index = 2) float yRot) { + public float adjustXRot(float xRot, @Local(argsOnly = true, index = 2) float yRot) { if (this.level.isClientSide) { if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { - return MixinUtil.applyDirectionXRotChange(persp, original, yRot); - } else return original; - } else return original; + return MixinUtil.applyDirectionXRotChange(persp, xRot, yRot); + } else return xRot; + } else return xRot; + } + + @SuppressWarnings("UnreachableCode") + @ModifyVariable(method = "calculateViewVector", at = @At(value = "LOAD"), index = 2, argsOnly = true) + public float adjustYRot(float yRot, @Local(argsOnly = true, index = 1) float xRot) { + if (this.level.isClientSide) { + if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { + return yRot + MixinUtil.getExtraYRot(persp, xRot, yRot); + } else return yRot; + } else return yRot; } } From 74b9df0d5f4a37f80aa28eaaacd825a18f787861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 15:18:02 -0700 Subject: [PATCH 09/18] #22 implement frame interpolation to smooth movements --- .../create/trainperspective/MixinUtil.java | 8 ++++---- .../create/trainperspective/Perspective.java | 8 ++++---- .../create/trainperspective/mixin/CameraMixin.java | 12 ++++++++---- .../mixin/CreateRaycastHelperMixin.java | 4 ++-- .../create/trainperspective/mixin/EntityMixin.java | 4 ++-- .../mixin/PlayerRendererMixin.java | 14 +++++++++----- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index c71ca25..e55be63 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -14,11 +14,11 @@ private static float invCos(float x) { return Mth.cos(x + Mth.PI); } - public static float applyDirectionXRotChange(Perspective persp, float xRot, float yRot) { - return xRot - persp.getLean() * Mth.sin((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + public static float applyDirectionXRotChange(Perspective persp, float xRot, float yRot, float f) { + return xRot - persp.getLean(f) * Mth.sin((persp.getYaw(f) - yRot) * Mth.DEG_TO_RAD); } - public static float getExtraYRot(Perspective persp, float xRot, float yRot) { - return persp.getLean() * (xRot / 90.0f) * invCos((persp.getYaw() - yRot) * Mth.DEG_TO_RAD); + public static float getExtraYRot(Perspective persp, float xRot, float yRot, float f) { + return persp.getLean(f) * (xRot / 90.0f) * invCos((persp.getYaw(f) - yRot) * Mth.DEG_TO_RAD); } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java index 639e35d..62afb57 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java @@ -6,11 +6,11 @@ public interface Perspective { boolean isEnabled(); void setLean(float lean); void setYaw(float yaw); - float getLean(); - float getYaw(); + float getLean(float f); + float getYaw(float f); default void diminish() { - setLean(getLean() * 0.97f); - setYaw(getYaw() * 0.97f); + setLean(getLean(1.0f) * 0.97f); + setYaw(getYaw(1.0f) * 0.97f); } } 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 612ae92..6bb219e 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 @@ -52,14 +52,18 @@ private void modifyQuaternion(float f, float g, CallbackInfo ci) { } @Redirect(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V")) - public void modifyRotationsPrimary(Camera instance, float y, float x, @Local(argsOnly = true, ordinal = 0) boolean isThirdPerson) { + public void modifyRotationsPrimary(Camera instance, + float y, + float x, + @Local(argsOnly = true, ordinal = 0) boolean isThirdPerson, + @Local(argsOnly = true) float f) { 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); - ctp$extraYRot = MixinUtil.getExtraYRot(persp, x, y); + ctp$zRot = persp.getLean(f) * Mth.cos((persp.getYaw(f) - y) * Mth.DEG_TO_RAD); + ctp$extraYRot = MixinUtil.getExtraYRot(persp, x, y, f); setRotation( y, - MixinUtil.applyDirectionXRotChange(persp, x, y) + MixinUtil.applyDirectionXRotChange(persp, x, y, f) ); } else { ctp$zRot = 0; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java index 1af50a9..86defd0 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java @@ -14,14 +14,14 @@ public class CreateRaycastHelperMixin { @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 4) private static float modifyXRot(float value, Player player) { if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { - return MixinUtil.applyDirectionXRotChange(persp, value, player.getYRot()); + return MixinUtil.applyDirectionXRotChange(persp, value, player.getYRot(), 1.0f); } else return value; } @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 5) private static float modifyYRot(float value, Player player) { if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { - return value + MixinUtil.getExtraYRot(persp, player.getXRot(), value); + return value + MixinUtil.getExtraYRot(persp, player.getXRot(), value, 1.0f); } else return value; } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java index 404a889..c067f41 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java @@ -39,7 +39,7 @@ public void onRemoveVehicle(CallbackInfo ci) { public float adjustXRot(float xRot, @Local(argsOnly = true, index = 2) float yRot) { if (this.level.isClientSide) { if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { - return MixinUtil.applyDirectionXRotChange(persp, xRot, yRot); + return MixinUtil.applyDirectionXRotChange(persp, xRot, yRot, 1.0f); } else return xRot; } else return xRot; } @@ -49,7 +49,7 @@ public float adjustXRot(float xRot, @Local(argsOnly = true, index = 2) float yRo public float adjustYRot(float yRot, @Local(argsOnly = true, index = 1) float xRot) { if (this.level.isClientSide) { if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { - return yRot + MixinUtil.getExtraYRot(persp, xRot, yRot); + return yRot + MixinUtil.getExtraYRot(persp, xRot, yRot, 1.0f); } else return yRot; } else return yRot; } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java index 1cf4461..f38f6a9 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java @@ -22,7 +22,7 @@ @Environment(EnvType.CLIENT) public class PlayerRendererMixin { @Unique private boolean ctp$perspectiveActive = false; - @Unique private float ctp$lean = 0.0f, ctp$yaw = 0.0f; + @Unique private float ctp$lean = 0.0f, ctp$yaw = 0.0f, ctp$oldLean = 0.0f, ctp$oldYaw = 0.0f; public void ctp$enable(float initialLean, float initialYaw) { ctp$perspectiveActive = true; @@ -41,19 +41,23 @@ public class PlayerRendererMixin { } public void ctp$setLean(float lean) { + ctp$oldLean = ctp$lean; ctp$lean = lean; } public void ctp$setYaw(float yaw) { + ctp$oldYaw = ctp$yaw; ctp$yaw = yaw; } - public float ctp$getLean() { - return ctp$lean; + public float ctp$getLean(float f) { + if(f == 1.0f) return ctp$lean; + return Mth.lerp(f, ctp$oldLean, ctp$lean); } - public float ctp$getYaw() { - return ctp$yaw; + public float ctp$getYaw(float f) { + if(f == 1.0f) return ctp$yaw; + return Mth.lerp(f, ctp$oldYaw, ctp$yaw); } @Inject( From 463e4c635e1ba84000c3404f0d9d3d44b8dd7e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 15:33:41 -0700 Subject: [PATCH 10/18] v0.3.0: update changelog --- changelog.md | 16 ++++++++-------- changelog.txt | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index 6be8101..2f5565d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,14 +1,14 @@ -- Fixed incorrect rolling when looking certain directions -- Now compatible with [do a barrel roll](https://modrinth.com/mod/do-a-barrel-roll) and hopefully other camera roll kinds of mods. -- The third-person camera while seated on a train is now improved. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/24) +- Players now look at their perceived down (e.g. the seat they're sitting in) rather than the real ground. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/32) +- Fixed jittery leaning. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22) +- When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35) + - This is probably incompatible with anti-cheat mods/plugins. + - The feature is also still _ever so slightly_ janky, but for most purposes it should be very usable. Known issues: -- The mod's leaning is a bit jittery. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22) - - This is probably more of a limitation of Minecraft itself. It might be fixable with a config option to emulate pitch, but that wouldn't make the player appear correctly to other players. - - Update: it's most definitely possible to fix this up. -- 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) +- No known issues. Nice! +- If you find any bugs, be sure to report them in the Discord server or issue tracker, both listed below. -[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.2.2...v0.2.3) +[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0) --- diff --git a/changelog.txt b/changelog.txt index 37dffd7..5317b41 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,16 +1,16 @@ -Minor update to fix some issues. +Major update to fix major problems. The mod is in a pretty good state now. -- Fixed incorrect rolling when looking certain directions -- Now compatible with [do a barrel roll] and hopefully other camera roll kinds of mods. -- The third-person camera while seated on a train is now improved. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/24 +- Players now look at their perceived down (e.g. the seat they're sitting in) rather than the real ground. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/32 +- Fixed jittery leaning. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22 +- When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35 + - This is probably incompatible with anti-cheat mods/plugins. + - The feature is also still *ever so slightly* janky, but for most purposes it should be very usable. Known issues: -- The mod's leaning is a bit jittery. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22 - - This is probably more of a limitation of Minecraft itself. It might be fixable with a config option to emulate pitch, but that wouldn't make the player appear correctly to other players. - - Update: it's most definitely possible to fix this up. -- The easing back to normal posture after jumping off a train on a slope could use some work. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/23 +- No known issues. Nice! +- If you find any bugs, be sure to report them in the Discord server or issue tracker, both listed below. -https://github.com/der-fruhling/create-train-perspective/compare/v0.2.2...v0.2.3 +Changelog: https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0 --- From e745984b29597d87e90b9d8833f7585b6532ba45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 15:33:49 -0700 Subject: [PATCH 11/18] v0.3.0: add email to fabric mod --- fabric/src/main/resources/fabric.mod.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 14206af..3e7d648 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -7,7 +7,8 @@ "contact": { "homepage": "https://github.com/der-fruhling-entertainment/create-train-perspective", "issues": "https://github.com/der-fruhling-entertainment/create-train-perspective/issues", - "sources": "https://github.com/der-fruhling-entertainment/create-train-perspective" + "sources": "https://github.com/der-fruhling-entertainment/create-train-perspective", + "email": "works-on-my-machine@der-fruhling.mozmail.com" }, "license": "MIT", "environment": "client", From eee9420f7a9907f9c441356160c52bdf16f97181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 16:18:57 -0700 Subject: [PATCH 12/18] fix: no more spinning please, thanks --- .../trainperspective/CreateTrainPerspectiveMod.java | 9 ++++----- .../minecraft/create/trainperspective/Perspective.java | 9 +++++++-- .../trainperspective/mixin/PlayerRendererMixin.java | 4 ++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java index 61bae09..5313160 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java @@ -115,12 +115,11 @@ public void onTickPlayer(final Player player) { } else { var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); persp.diminish(); - } - if(localPlayer.onGround() && state.standingState) { - var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - states.remove(player.getUUID()); - persp.disable(); + if(persp.diminished()) { + states.remove(player.getUUID()); + persp.disable(); + } } } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java index 62afb57..e456e32 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java @@ -1,5 +1,7 @@ package net.derfruhling.minecraft.create.trainperspective; +import net.minecraft.util.Mth; + public interface Perspective { void enable(float initialLean, float initialYaw); void disable(); @@ -10,7 +12,10 @@ public interface Perspective { float getYaw(float f); default void diminish() { - setLean(getLean(1.0f) * 0.97f); - setYaw(getYaw(1.0f) * 0.97f); + setLean(getLean(1.0f) * 0.9f); + } + + default boolean diminished() { + return Mth.abs(getLean(1.0f)) < 0.02f; } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java index f38f6a9..09d4a51 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java @@ -28,12 +28,16 @@ public class PlayerRendererMixin { ctp$perspectiveActive = true; ctp$lean = initialLean; ctp$yaw = initialYaw; + ctp$oldLean = initialLean; + ctp$oldYaw = initialYaw; } public void ctp$disable() { ctp$perspectiveActive = false; ctp$lean = 0.0f; ctp$yaw = 0.0f; + ctp$oldLean = 0.0f; + ctp$oldYaw = 0.0f; } public boolean ctp$isEnabled() { From cfd75ac8ad5cccb49751c915bf2aefdb8f4a2a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 18:14:18 -0700 Subject: [PATCH 13/18] fix: frantically repair broken sanity (fixes issue with create not necessarily providing collisions through the same function) --- .../CreateTrainPerspectiveMod.java | 60 +++++++++---------- .../create/trainperspective/Perspective.java | 2 +- ...va => AbstractContraptionEntityMixin.java} | 18 +++--- .../create_train_perspective.mixins.json | 2 +- 4 files changed, 42 insertions(+), 40 deletions(-) rename common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/{ContraptionColliderMixin.java => AbstractContraptionEntityMixin.java} (59%) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java index 5313160..4ee8a72 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java @@ -10,9 +10,7 @@ import org.apache.commons.lang3.mutable.MutableInt; import org.slf4j.Logger; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; // The value here should match an entry in the META-INF/mods.toml file public class CreateTrainPerspectiveMod { @@ -30,7 +28,10 @@ public CreateTrainPerspectiveMod() { private static class RotationState { public final CarriageContraptionEntity entity; private float lastYaw; - public boolean standingState, isMounted, shouldTickState = true; + public boolean standingState; + public boolean isMounted; + public boolean shouldTickState = true; + public int ticksSinceLastUpdate = 0; public RotationState(CarriageContraptionEntity entity, boolean standingState, boolean isMounted) { this.entity = entity; @@ -60,40 +61,31 @@ public void onEntityMount(boolean isMounting, Entity entityMounting, Entity enti states.put(entityMounting.getUUID(), state); persp.enable(state.entity.pitch, state.entity.yaw); } else { - states.get(entityMounting.getUUID()).isMounted = true; + var state = states.get(entityMounting.getUUID()); + state.isMounted = true; + state.shouldTickState = true; } } else { if(states.containsKey(entityMounting.getUUID())) { - if(states.get(entityMounting.getUUID()).standingState) { - states.get(entityMounting.getUUID()).isMounted = false; - } else { - states.remove(entityMounting.getUUID()); - persp.disable(); - } + states.remove(entityMounting.getUUID()); + persp.disable(); } } } } - public void tickStandingPlayers(final CarriageContraptionEntity contraption) { - for(Map.Entry entry : contraption.collidingEntities.entrySet()) { - var entity = entry.getKey(); - var ticks = entry.getValue(); - if(entity instanceof LocalPlayer player) { - if(player.getVehicle() != null) continue; - - var state = states.get(player.getUUID()); - if (state == null) { - var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - state = new RotationState(contraption, true, false); - states.put(player.getUUID(), state); - persp.enable(state.entity.pitch, state.entity.yaw); - } else if(ticks.getValue() >= 2) { - state.shouldTickState = false; - } else if(!state.shouldTickState) { - state.shouldTickState = true; - } - } + public void tickStandingPlayer(final CarriageContraptionEntity contraption, final Player player) { + if(player.getVehicle() != null) return; + + var state = states.get(player.getUUID()); + + if (state == null || !Objects.equals(state.entity, contraption)) { + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + state = new RotationState(contraption, true, false); + states.put(player.getUUID(), state); + persp.enable(state.entity.pitch, state.entity.yaw); + } else { + state.ticksSinceLastUpdate = 0; } } @@ -104,6 +96,14 @@ private void tickState(LocalPlayer player) { persp.setYaw(state.entity.yaw); player.setYRot(player.getYRot() + state.getYawDelta()); player.setYBodyRot(player.getYRot()); + + if(state.standingState && !state.isMounted) { + state.ticksSinceLastUpdate += 1; + + if(state.ticksSinceLastUpdate > 5) { + state.shouldTickState = false; + } + } } public void onTickPlayer(final Player player) { diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java index e456e32..4636714 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java @@ -16,6 +16,6 @@ default void diminish() { } default boolean diminished() { - return Mth.abs(getLean(1.0f)) < 0.02f; + return Mth.abs(getLean(1.0f)) < 0.01f; } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java similarity index 59% rename from common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java rename to common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java index 4b85f2e..c072623 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java @@ -1,26 +1,28 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; import com.simibubi.create.content.contraptions.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.ContraptionCollider; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ContraptionCollider.class) +@Mixin(AbstractContraptionEntity.class) @Environment(EnvType.CLIENT) -public class ContraptionColliderMixin { - @Inject(method = "collideEntities", at = @At("HEAD"), remap = false) - private static void saveClientPlayerFromClipping( - AbstractContraptionEntity contraptionEntity, +public class AbstractContraptionEntityMixin { + @SuppressWarnings({"ConstantValue", "UnreachableCode"}) + @Inject(method = "registerColliding", at = @At("TAIL"), remap = false) + private void onRegisterColliding( + Entity entity, CallbackInfo ci ) { - if(contraptionEntity instanceof CarriageContraptionEntity carriage) { - CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayers(carriage); + if((Object) this instanceof CarriageContraptionEntity carriage && entity instanceof Player player) { + CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayer(carriage, player); } } } diff --git a/common/src/main/resources/create_train_perspective.mixins.json b/common/src/main/resources/create_train_perspective.mixins.json index 1a93dd3..56fb265 100644 --- a/common/src/main/resources/create_train_perspective.mixins.json +++ b/common/src/main/resources/create_train_perspective.mixins.json @@ -5,7 +5,7 @@ "compatibilityLevel": "JAVA_8", "client": [ "CameraMixin", - "ContraptionColliderMixin", + "AbstractContraptionEntityMixin", "EntityMixin", "GameRendererMixin", "PlayerRendererMixin", From 9e5504ef60872c5b269faecec5f4a011756dad14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 20:39:09 -0700 Subject: [PATCH 14/18] fix: no more intense camera moments when travelling along along the X axis --- .../trainperspective/CreateTrainPerspectiveMod.java | 8 ++++++++ .../trainperspective/mixin/PlayerRendererMixin.java | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java index 4ee8a72..ac9aaef 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java @@ -41,6 +41,14 @@ public RotationState(CarriageContraptionEntity entity, boolean standingState, bo } public float getYawDelta() { + while (entity.yaw - lastYaw < -180.0f) { + lastYaw -= 360.0f; + } + + while (entity.yaw - lastYaw >= 180.0f) { + lastYaw += 360.0f; + } + var rotation = entity.yaw - lastYaw; lastYaw = entity.yaw; return rotation; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java index 09d4a51..9cb1351 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java @@ -50,8 +50,18 @@ public class PlayerRendererMixin { } public void ctp$setYaw(float yaw) { + // some configurations flip between 0 and 360 constantly + // adjust accordingly ctp$oldYaw = ctp$yaw; ctp$yaw = yaw; + + while (ctp$yaw - ctp$oldYaw < -180.0f) { + ctp$oldYaw -= 360.0f; + } + + while (ctp$yaw - ctp$oldYaw >= 180.0f) { + ctp$oldYaw += 360.0f; + } } public float ctp$getLean(float f) { From 4a2bdec6a3a6ea7e74a188447e155ce02ae819e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 20:44:18 -0700 Subject: [PATCH 15/18] v0.3.0: update changelog --- changelog.md | 6 ++---- changelog.txt | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index 2f5565d..c496d4f 100644 --- a/changelog.md +++ b/changelog.md @@ -3,10 +3,8 @@ - When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35) - This is probably incompatible with anti-cheat mods/plugins. - The feature is also still _ever so slightly_ janky, but for most purposes it should be very usable. - -Known issues: -- No known issues. Nice! -- If you find any bugs, be sure to report them in the Discord server or issue tracker, both listed below. +- Fixed jittering of hand when traveling along the negative X axis. +- Fabric only: added a contact email. [View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0) diff --git a/changelog.txt b/changelog.txt index 5317b41..0dbc517 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,10 +5,8 @@ Major update to fix major problems. The mod is in a pretty good state now. - When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35 - This is probably incompatible with anti-cheat mods/plugins. - The feature is also still *ever so slightly* janky, but for most purposes it should be very usable. - -Known issues: -- No known issues. Nice! -- If you find any bugs, be sure to report them in the Discord server or issue tracker, both listed below. +- Fixed jittering of hand when traveling along the negative X axis. +- Fabric only: added a contact email. Changelog: https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0 From 1e1e42e58d67a9704877b9f779bd1895012078f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 21:14:07 -0700 Subject: [PATCH 16/18] v0.3.0: update changelog further --- changelog.md | 21 +++++++++++++++++++++ changelog.txt | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index c496d4f..b126835 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +Major update to fix major problems. The mod is in a pretty good state now. + +The scoops: - Players now look at their perceived down (e.g. the seat they're sitting in) rather than the real ground. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/32) - Fixed jittery leaning. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22) - When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35) @@ -10,6 +13,24 @@ --- +In 0.1.2, I decided that the mod was basically ready and marked it as a Release version. + +On second thought, I have realized the state of the mod and decided that Beta better describes its current state. +I have marked versions 0.2.2+ as Beta and all versions before that as Alpha to better represent this. + +Of course, this does not mean that the mod is unusable or is going to break _everything_. +It just doesn't hold all the qualities I want it to. +In my opinion, A full Release version should be highly functional and configurable, +while retaining good compatibility with popular mods. + +On that note, this version is _quality_ enough to be a release candidate, +and would be if it weren't for the missing things below: +- Configuration. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/36) +- More accurate perspective. For a mod called "Create: _Train Perspective_", this is an important issue. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/38) +- Some sound system and fog issues. Nothing major, but slightly annoying. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/39) + +--- + Issues? Feature Requests? [View the issue tracker!](https://github.com/der-fruhling-entertainment/create-train-perspective/issues) diff --git a/changelog.txt b/changelog.txt index 0dbc517..0f44573 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Major update to fix major problems. The mod is in a pretty good state now. +[Changelog] - Players now look at their perceived down (e.g. the seat they're sitting in) rather than the real ground. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/32 - Fixed jittery leaning. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22 - When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35 @@ -8,7 +9,7 @@ Major update to fix major problems. The mod is in a pretty good state now. - Fixed jittering of hand when traveling along the negative X axis. - Fabric only: added a contact email. -Changelog: https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0 +Commits: https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0 --- From 349e6f5622c31236dc7550f60fd5e3fe18ad56c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 21:15:21 -0700 Subject: [PATCH 17/18] fix: mod files using loader suffixed version numbers when loader is implied --- fabric/src/main/resources/fabric.mod.json | 2 +- forge/src/main/resources/META-INF/mods.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 3e7d648..75c385b 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "${mod_id}", "name": "Create: Train Perspective", "description": "Moves your camera (and body!) with the Create Mod train you're riding to increase immersion!", - "version": "${version}+fabric", + "version": "${version}", "contact": { "homepage": "https://github.com/der-fruhling-entertainment/create-train-perspective", "issues": "https://github.com/der-fruhling-entertainment/create-train-perspective/issues", diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index d2ca209..3af6a5b 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -17,7 +17,7 @@ issueTrackerURL="https://github.com/der-fruhling-entertainment/create-train-pers # The modid of the mod modId="${mod_id}" #mandatory # The version number of the mod -version="${mod_version}+forge" #mandatory +version="${mod_version}" #mandatory # A display name for the mod displayName="Create: Train Perspective" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ From 0ce93770eec190aabd9ead4c715942ddd09777b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 16 May 2024 21:19:52 -0700 Subject: [PATCH 18/18] fix: modrinth version type --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 7489ca8..0ea34bc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,5 +25,5 @@ flywheel_minecraft_version=1.20.1 registrate_version=MC1.20-1.3.11 modrinth_project_id=create-train-perspective -modrinth_version_type=release +modrinth_version_type=beta modrinth_game_versions=1.20.1