From bca506c7ef8bdbdea2f0aa05faa7e9f42290bf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 10:46:28 -0700 Subject: [PATCH 01/14] #14 Implement fixed standing position --- .../CreateTrainPerspectiveMod.java | 27 +++++++++++++++++-- .../mixin/ContraptionColliderMixin.java | 23 ++++++++++++++++ .../create_train_perspective.mixins.json | 3 ++- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java 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 b91e47d..4b3d4e4 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 @@ -8,20 +8,24 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import org.apache.commons.lang3.mutable.MutableInt; import org.slf4j.Logger; import java.util.HashMap; +import java.util.Map; import java.util.UUID; // The value here should match an entry in the META-INF/mods.toml file public class CreateTrainPerspectiveMod { // Define mod id in a common place for everything to reference public static final String MODID = "create_train_perspective"; + public static CreateTrainPerspectiveMod INSTANCE; // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); public CreateTrainPerspectiveMod() { - TickEvent.PLAYER_POST.register(this::onTickPlayer); + TickEvent.PLAYER_POST.register(this::tickPlayer); + INSTANCE = this; } private static class RotationState { @@ -59,7 +63,26 @@ public void onEntityMount(boolean isMounting, Entity entityMounting, Entity enti } } - public void onTickPlayer(final Player player) { + public void tickStandingPlayers(final CarriageContraptionEntity contraption) { + for(Map.Entry entry : contraption.collidingEntities.entrySet()) { + var entity = entry.getKey(); + var ticks = entry.getValue(); + if(entity instanceof Player player) { + if(ticks.getValue() >= 2) { + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + states.remove(player.getUUID()); + persp.disable(); + } else { + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + var state = new RotationState(contraption); + states.put(player.getUUID(), state); + persp.enable(state.entity.pitch, state.entity.yaw); + } + } + } + } + + public void tickPlayer(final Player player) { if (!(player instanceof AbstractClientPlayer)) return; if(states.containsKey(player.getUUID())) { var state = states.get(player.getUUID()); 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 new file mode 100644 index 0000000..9fa6864 --- /dev/null +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java @@ -0,0 +1,23 @@ +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 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) +public class ContraptionColliderMixin { + @Inject(method = "collideEntities", at = @At("HEAD"), remap = false) + private static void saveClientPlayerFromClipping( + AbstractContraptionEntity contraptionEntity, + CallbackInfo ci + ) { + if(contraptionEntity instanceof CarriageContraptionEntity carriage) { + CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayers(carriage); + } + } +} diff --git a/common/src/main/resources/create_train_perspective.mixins.json b/common/src/main/resources/create_train_perspective.mixins.json index e4e25b6..bb0cc93 100644 --- a/common/src/main/resources/create_train_perspective.mixins.json +++ b/common/src/main/resources/create_train_perspective.mixins.json @@ -4,7 +4,8 @@ "package": "net.derfruhling.minecraft.create.trainperspective.mixin", "compatibilityLevel": "JAVA_8", "client": [ - "PlayerRendererMixin" + "PlayerRendererMixin", + "ContraptionColliderMixin" ], "injectors": { "defaultRequire": 1 From 3e70124fac7348b3b79fe2925de092415548f258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 11:28:29 -0700 Subject: [PATCH 02/14] Fix: Standing impl was breaking existing seated impl --- .../CreateTrainPerspectiveMod.java | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 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 4b3d4e4..184aae1 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 @@ -24,17 +24,20 @@ public class CreateTrainPerspectiveMod { private static final Logger LOGGER = LogUtils.getLogger(); public CreateTrainPerspectiveMod() { - TickEvent.PLAYER_POST.register(this::tickPlayer); + TickEvent.PLAYER_POST.register(this::onTickPlayer); INSTANCE = this; } private static class RotationState { public final CarriageContraptionEntity entity; private float lastYaw; + public boolean standingState, isMounted; - public RotationState(CarriageContraptionEntity entity) { + public RotationState(CarriageContraptionEntity entity, boolean standingState, boolean isMounted) { this.entity = entity; lastYaw = entity.yaw; + this.standingState = standingState; + this.isMounted = isMounted; } public float getYawDelta() { @@ -53,12 +56,22 @@ public void onEntityMount(boolean isMounting, Entity entityMounting, Entity enti ) { var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); if(isMounting) { - var state = new RotationState(contraption); - states.put(entityMounting.getUUID(), state); - persp.enable(state.entity.pitch, state.entity.yaw); + if(!states.containsKey(entityMounting.getUUID())) { + var state = new RotationState(contraption, false, true); + states.put(entityMounting.getUUID(), state); + persp.enable(state.entity.pitch, state.entity.yaw); + } else { + states.get(entityMounting.getUUID()).isMounted = true; + } } else { - states.remove(entityMounting.getUUID()); - persp.disable(); + if(states.containsKey(entityMounting.getUUID())) { + if(states.get(entityMounting.getUUID()).standingState) { + states.get(entityMounting.getUUID()).isMounted = false; + } else { + states.remove(entityMounting.getUUID()); + persp.disable(); + } + } } } } @@ -67,14 +80,19 @@ public void tickStandingPlayers(final CarriageContraptionEntity contraption) { for(Map.Entry entry : contraption.collidingEntities.entrySet()) { var entity = entry.getKey(); var ticks = entry.getValue(); - if(entity instanceof Player player) { + if(entity instanceof LocalPlayer player) { + if(player.getVehicle() != null) continue; + if(ticks.getValue() >= 2) { var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); states.remove(player.getUUID()); persp.disable(); + } else if(states.containsKey(player.getUUID())) { + var state = states.get(player.getUUID()); + if(state.standingState && !state.isMounted) tickState(player); } else { var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - var state = new RotationState(contraption); + var state = new RotationState(contraption, true, false); states.put(player.getUUID(), state); persp.enable(state.entity.pitch, state.entity.yaw); } @@ -82,14 +100,17 @@ public void tickStandingPlayers(final CarriageContraptionEntity contraption) { } } - public void tickPlayer(final Player player) { - if (!(player instanceof AbstractClientPlayer)) return; - if(states.containsKey(player.getUUID())) { - var state = states.get(player.getUUID()); - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((AbstractClientPlayer) player); - persp.setLean(state.entity.pitch); - persp.setYaw(state.entity.yaw); - player.setYRot(player.getYRot() + state.getYawDelta()); + private void tickState(LocalPlayer player) { + var state = states.get(player.getUUID()); + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((LocalPlayer) player); + persp.setLean(state.entity.pitch); + persp.setYaw(state.entity.yaw); + player.setYRot(player.getYRot() + state.getYawDelta()); + } + + public void onTickPlayer(final Player player) { + if(player instanceof LocalPlayer localPlayer && states.containsKey(player.getUUID()) && states.get(player.getUUID()).isMounted) { + tickState(localPlayer); } } } From 1a8125a8f4cfb81291bc7ea51d883a904351f97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 11:46:30 -0700 Subject: [PATCH 03/14] #11 Implement vertical camera moving Currently very jittery due to #12 --- .../PlayerPerspectiveBehavior.java | 1 + .../trainperspective/mixin/CameraMixin.java | 33 +++++++++++++++++++ .../mixin/PlayerRendererMixin.java | 4 +++ .../create_train_perspective.mixins.json | 1 + 4 files changed, 39 insertions(+) create mode 100644 common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java index 5d02d05..1b39cfc 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java @@ -5,4 +5,5 @@ public interface PlayerPerspectiveBehavior { void disable(); void setLean(float lean); void setYaw(float yaw); + float getLean(); } 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 new file mode 100644 index 0000000..832b529 --- /dev/null +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java @@ -0,0 +1,33 @@ +package net.derfruhling.minecraft.create.trainperspective.mixin; + +import net.derfruhling.minecraft.create.trainperspective.PlayerPerspectiveBehavior; +import net.minecraft.client.Camera; +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.world.entity.Entity; +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.ModifyArg; + +@Mixin(Camera.class) +public class CameraMixin { + @Shadow private Entity entity; + + @ModifyArg(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 0), index = 1) + public float modifyXRotPrimary(float xRot) { + if(entity instanceof LocalPlayer player) { + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + return xRot - persp.getLean(); + } else return xRot; + } + + @ModifyArg(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 1), index = 1) + public float modifyXRotThirdPersonMirrored(float invertedXRot) { + if(entity instanceof LocalPlayer player) { + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + return invertedXRot + persp.getLean(); + } else return invertedXRot; + } +} 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 7908d70..e35508f 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 @@ -39,6 +39,10 @@ public class PlayerRendererMixin { ctp$yaw = yaw; } + public float ctp$getLean() { + return ctp$lean; + } + @Inject( method = "setupRotations(Lnet/minecraft/client/player/AbstractClientPlayer;Lcom/mojang/blaze3d/vertex/PoseStack;FFF)V", at = @At( diff --git a/common/src/main/resources/create_train_perspective.mixins.json b/common/src/main/resources/create_train_perspective.mixins.json index e4e25b6..31baf61 100644 --- a/common/src/main/resources/create_train_perspective.mixins.json +++ b/common/src/main/resources/create_train_perspective.mixins.json @@ -4,6 +4,7 @@ "package": "net.derfruhling.minecraft.create.trainperspective.mixin", "compatibilityLevel": "JAVA_8", "client": [ + "CameraMixin", "PlayerRendererMixin" ], "injectors": { From 4a1d7b6d65f0c065a92357a7b4c0e41f85494c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 12:40:15 -0700 Subject: [PATCH 04/14] Implement camera rolling and better vertical camera movement --- .../create/trainperspective/Camera3D.java | 6 +++ .../create/trainperspective/MixUtil.java | 12 +++++ .../trainperspective/mixin/CameraMixin.java | 52 ++++++++++++++----- .../mixin/GameRendererMixin.java | 23 ++++++++ .../create_train_perspective.mixins.json | 5 +- 5 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java create mode 100644 common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixUtil.java create mode 100644 common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java 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 new file mode 100644 index 0000000..c9975c0 --- /dev/null +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java @@ -0,0 +1,6 @@ +package net.derfruhling.minecraft.create.trainperspective; + +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/MixUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixUtil.java new file mode 100644 index 0000000..6917f50 --- /dev/null +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixUtil.java @@ -0,0 +1,12 @@ +package net.derfruhling.minecraft.create.trainperspective; + +import net.derfruhling.minecraft.create.trainperspective.mixin.CameraMixin; +import net.minecraft.client.Camera; + +public class MixUtil { + private MixUtil() {} + + public static Camera3D asCamera3D(Camera camera) { + return (Camera3D) camera; + } +} 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 832b529..eac46d6 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,33 +1,57 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; +import net.derfruhling.minecraft.create.trainperspective.Camera3D; import net.derfruhling.minecraft.create.trainperspective.PlayerPerspectiveBehavior; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +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) -public class CameraMixin { +@Implements({@Interface(iface = Camera3D.class, prefix = "ctp$")}) +public abstract class CameraMixin { @Shadow private Entity entity; + @Shadow private float xRot; + @Shadow private float yRot; + @Unique private float ctp$zRot; - @ModifyArg(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 0), index = 1) - public float modifyXRotPrimary(float xRot) { - if(entity instanceof LocalPlayer player) { - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - return xRot - persp.getLean(); - } else return xRot; + @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); + } + + @Unique + public float ctp$getZRot() { + return this.ctp$zRot; } - @ModifyArg(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 1), index = 1) - public float modifyXRotThirdPersonMirrored(float invertedXRot) { + @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) { var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - return invertedXRot + persp.getLean(); - } else return invertedXRot; + ctp$setRotation3D(y, + x + persp.getLean() * Mth.cos(y * Mth.DEG_TO_RAD), + 360.0f - (persp.getLean() * Mth.sin(y * Mth.DEG_TO_RAD))); + } else 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 new file mode 100644 index 0000000..9db5a7c --- /dev/null +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java @@ -0,0 +1,23 @@ +package net.derfruhling.minecraft.create.trainperspective.mixin; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Axis; +import net.derfruhling.minecraft.create.trainperspective.MixUtil; +import net.minecraft.client.Camera; +import net.minecraft.client.renderer.GameRenderer; +import org.spongepowered.asm.mixin.Final; +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.callback.CallbackInfo; + +@Mixin(GameRenderer.class) +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)) + public void applyZRotation(float f, long l, PoseStack poseStack, CallbackInfo ci) { + poseStack.mulPose(Axis.ZP.rotationDegrees(MixUtil.asCamera3D(mainCamera).getZRot())); + } +} diff --git a/common/src/main/resources/create_train_perspective.mixins.json b/common/src/main/resources/create_train_perspective.mixins.json index 894ef80..1294e6b 100644 --- a/common/src/main/resources/create_train_perspective.mixins.json +++ b/common/src/main/resources/create_train_perspective.mixins.json @@ -4,9 +4,10 @@ "package": "net.derfruhling.minecraft.create.trainperspective.mixin", "compatibilityLevel": "JAVA_8", "client": [ - "PlayerRendererMixin", + "CameraMixin", "ContraptionColliderMixin", - "CameraMixin" + "GameRendererMixin", + "PlayerRendererMixin" ], "injectors": { "defaultRequire": 1 From f14f35673002ab26ff9b3d02ff052eab4c197572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 12:52:43 -0700 Subject: [PATCH 05/14] #13 Ensure that player body rotation is always forward --- .../create/trainperspective/CreateTrainPerspectiveMod.java | 1 + 1 file changed, 1 insertion(+) 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 184aae1..18b279b 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 @@ -106,6 +106,7 @@ private void tickState(LocalPlayer player) { persp.setLean(state.entity.pitch); persp.setYaw(state.entity.yaw); player.setYRot(player.getYRot() + state.getYawDelta()); + player.setYBodyRot(player.getYRot()); } public void onTickPlayer(final Player player) { From 4e0d9710090bf527a6fec3766a0f0ebf731a3268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 13:05:12 -0700 Subject: [PATCH 06/14] Fix: incorrect roll on certain axis --- .../create/trainperspective/PlayerPerspectiveBehavior.java | 1 + .../minecraft/create/trainperspective/mixin/CameraMixin.java | 4 ++-- .../create/trainperspective/mixin/PlayerRendererMixin.java | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java index 1b39cfc..c20ce51 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java @@ -6,4 +6,5 @@ public interface PlayerPerspectiveBehavior { void setLean(float lean); void setYaw(float yaw); float getLean(); + float getYaw(); } 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 eac46d6..60fdd59 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 @@ -50,8 +50,8 @@ public void modifyRotationsPrimary(Camera instance, float y, float x) { if(entity instanceof LocalPlayer player) { var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); ctp$setRotation3D(y, - x + persp.getLean() * Mth.cos(y * Mth.DEG_TO_RAD), - 360.0f - (persp.getLean() * Mth.sin(y * Mth.DEG_TO_RAD))); + 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); } } 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 e35508f..f9c0dd9 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 @@ -43,6 +43,10 @@ public class PlayerRendererMixin { return ctp$lean; } + public float ctp$getYaw() { + return ctp$yaw; + } + @Inject( method = "setupRotations(Lnet/minecraft/client/player/AbstractClientPlayer;Lcom/mojang/blaze3d/vertex/PoseStack;FFF)V", at = @At( From a149a8c46473ad66e4728e57373658ac18f3d195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 15:46:14 -0700 Subject: [PATCH 07/14] #16 Players now ride tall trains correctly --- .../CreateTrainPerspectiveMod.java | 3 +-- .../mixin/PlayerRendererMixin.java | 16 +++++++++++----- 2 files changed, 12 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 18b279b..fcd073d 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 @@ -4,7 +4,6 @@ import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import dev.architectury.event.events.common.TickEvent; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -102,7 +101,7 @@ public void tickStandingPlayers(final CarriageContraptionEntity contraption) { private void tickState(LocalPlayer player) { var state = states.get(player.getUUID()); - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((LocalPlayer) player); + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); persp.setLean(state.entity.pitch); persp.setYaw(state.entity.yaw); player.setYRot(player.getYRot() + state.getYawDelta()); 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 f9c0dd9..a20703a 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 @@ -6,6 +6,8 @@ import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.util.Mth; +import net.minecraft.world.phys.Vec3; +import org.joml.Vector3f; import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Mixin; @@ -50,15 +52,19 @@ public class PlayerRendererMixin { @Inject( method = "setupRotations(Lnet/minecraft/client/player/AbstractClientPlayer;Lcom/mojang/blaze3d/vertex/PoseStack;FFF)V", at = @At( - value = "INVOKE", - shift = At.Shift.BEFORE, - target = "Lnet/minecraft/client/renderer/entity/LivingEntityRenderer;setupRotations(Lnet/minecraft/world/entity/LivingEntity;Lcom/mojang/blaze3d/vertex/PoseStack;FFF)V" + value = "HEAD" ) ) protected void setupRotations(AbstractClientPlayer p_117802_, PoseStack p_117803_, float p_117804_, float p_117805_, float p_117806_, CallbackInfo ci) { if(ctp$perspectiveActive) { - p_117803_.rotateAround(Axis.ZP.rotationDegrees(Mth.cos(Mth.DEG_TO_RAD * ctp$yaw) * ctp$lean), 0, 1.3f, 0); - p_117803_.rotateAround(Axis.XP.rotationDegrees(Mth.sin(Mth.DEG_TO_RAD * ctp$yaw) * -ctp$lean), 0, 1.3f, 0); + float height = 0; + + if(p_117802_.getVehicle() != null) { + height = 1.4f; + } + + p_117803_.rotateAround(Axis.ZP.rotationDegrees(Mth.cos(Mth.DEG_TO_RAD * ctp$yaw) * ctp$lean), 0, height, 0); + p_117803_.rotateAround(Axis.XP.rotationDegrees(Mth.sin(Mth.DEG_TO_RAD * ctp$yaw) * -ctp$lean), 0, height, 0); } } } From aa747030cc12935594841b5c47873601e7c73e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 16:06:46 -0700 Subject: [PATCH 08/14] Fix: Going from leaning to not leaning is now slightly less jarring --- .../CreateTrainPerspectiveMod.java | 35 ++++++++++++------- .../PlayerPerspectiveBehavior.java | 5 +++ 2 files changed, 28 insertions(+), 12 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 fcd073d..3775feb 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 @@ -30,7 +30,7 @@ public CreateTrainPerspectiveMod() { private static class RotationState { public final CarriageContraptionEntity entity; private float lastYaw; - public boolean standingState, isMounted; + public boolean standingState, isMounted, shouldTickState = true; public RotationState(CarriageContraptionEntity entity, boolean standingState, boolean isMounted) { this.entity = entity; @@ -82,18 +82,16 @@ public void tickStandingPlayers(final CarriageContraptionEntity contraption) { if(entity instanceof LocalPlayer player) { if(player.getVehicle() != null) continue; - if(ticks.getValue() >= 2) { + var state = states.get(player.getUUID()); + if (state == null) { var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - states.remove(player.getUUID()); - persp.disable(); - } else if(states.containsKey(player.getUUID())) { - var state = states.get(player.getUUID()); - if(state.standingState && !state.isMounted) tickState(player); - } else { - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - var state = new RotationState(contraption, true, false); + 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; } } } @@ -109,8 +107,21 @@ private void tickState(LocalPlayer player) { } public void onTickPlayer(final Player player) { - if(player instanceof LocalPlayer localPlayer && states.containsKey(player.getUUID()) && states.get(player.getUUID()).isMounted) { - tickState(localPlayer); + if(player instanceof LocalPlayer localPlayer && states.containsKey(player.getUUID())) { + var state = states.get(player.getUUID()); + + if(state.shouldTickState) { + tickState(localPlayer); + } else { + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + persp.diminish(); + } + + if(localPlayer.onGround() && state.standingState) { + var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + states.remove(player.getUUID()); + persp.disable(); + } } } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java index c20ce51..9646631 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java @@ -7,4 +7,9 @@ public interface PlayerPerspectiveBehavior { void setYaw(float yaw); float getLean(); float getYaw(); + + default void diminish() { + setLean(getLean() * 0.97f); + setYaw(getYaw() * 0.97f); + } } From 9b8245259a874fce33d29c7e8582c5894221f8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 16:08:52 -0700 Subject: [PATCH 09/14] Fix: Stop doing anything on a dedicated server --- .../create/trainperspective/forge/ModForgeEntrypoint.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java b/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java index a44f5f4..93cad36 100644 --- a/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java +++ b/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java @@ -2,9 +2,12 @@ import dev.architectury.platform.forge.EventBuses; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityMountEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.jetbrains.annotations.NotNull; @@ -13,11 +16,16 @@ public class ModForgeEntrypoint { public CreateTrainPerspectiveMod mod = new CreateTrainPerspectiveMod(); public ModForgeEntrypoint() { + MinecraftForge.EVENT_BUS.addListener(this::onClientSetupEvent); + } + + private void onClientSetupEvent(FMLClientSetupEvent event) { EventBuses.registerModEventBus(CreateTrainPerspectiveMod.MODID, FMLJavaModLoadingContext.get().getModEventBus()); MinecraftForge.EVENT_BUS.addListener(this::onEntityMountEvent); } + @OnlyIn(Dist.CLIENT) private void onEntityMountEvent(@NotNull EntityMountEvent event) { mod.onEntityMount( event.isMounting(), From 42ebb1194bc923e703dc9282089d5f87758b4baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 21:08:14 -0700 Subject: [PATCH 10/14] The great refactoring --- .../CreateTrainPerspectiveMod.java | 10 +++++----- .../{MixUtil.java => MixinUtil.java} | 5 ++--- ...rPerspectiveBehavior.java => Perspective.java} | 2 +- .../trainperspective/mixin/CameraMixin.java | 5 ++--- .../trainperspective}/mixin/EntityMixin.java | 11 +++++------ .../trainperspective/mixin/GameRendererMixin.java | 4 ++-- .../mixin/PlayerRendererMixin.java | 6 ++---- .../create_train_perspective.mixins.json | 3 ++- .../create_train_perspective.fabric.mixins.json | 12 ------------ fabric/src/main/resources/fabric.mod.json | 3 +-- .../forge/ModForgeEntrypoint.java | 15 --------------- 11 files changed, 22 insertions(+), 54 deletions(-) rename common/src/main/java/net/derfruhling/minecraft/create/trainperspective/{MixUtil.java => MixinUtil.java} (61%) rename common/src/main/java/net/derfruhling/minecraft/create/trainperspective/{PlayerPerspectiveBehavior.java => Perspective.java} (88%) rename {fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric => common/src/main/java/net/derfruhling/minecraft/create/trainperspective}/mixin/EntityMixin.java (68%) delete mode 100644 fabric/src/main/resources/create_train_perspective.fabric.mixins.json 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 3775feb..61bae09 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 @@ -53,7 +53,7 @@ public void onEntityMount(boolean isMounting, Entity entityMounting, Entity enti entityMounting instanceof LocalPlayer player && entityBeingMounted instanceof CarriageContraptionEntity contraption ) { - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); if(isMounting) { if(!states.containsKey(entityMounting.getUUID())) { var state = new RotationState(contraption, false, true); @@ -84,7 +84,7 @@ public void tickStandingPlayers(final CarriageContraptionEntity contraption) { var state = states.get(player.getUUID()); if (state == null) { - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + 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); @@ -99,7 +99,7 @@ public void tickStandingPlayers(final CarriageContraptionEntity contraption) { private void tickState(LocalPlayer player) { var state = states.get(player.getUUID()); - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); persp.setLean(state.entity.pitch); persp.setYaw(state.entity.yaw); player.setYRot(player.getYRot() + state.getYawDelta()); @@ -113,12 +113,12 @@ public void onTickPlayer(final Player player) { if(state.shouldTickState) { tickState(localPlayer); } else { - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); persp.diminish(); } if(localPlayer.onGround() && state.standingState) { - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); states.remove(player.getUUID()); persp.disable(); } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java similarity index 61% rename from common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixUtil.java rename to common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index 6917f50..79f8b09 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -1,10 +1,9 @@ package net.derfruhling.minecraft.create.trainperspective; -import net.derfruhling.minecraft.create.trainperspective.mixin.CameraMixin; import net.minecraft.client.Camera; -public class MixUtil { - private MixUtil() {} +public class MixinUtil { + private MixinUtil() {} public static Camera3D asCamera3D(Camera camera) { return (Camera3D) camera; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java similarity index 88% rename from common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java rename to common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java index 9646631..cb64c9b 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/PlayerPerspectiveBehavior.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java @@ -1,6 +1,6 @@ package net.derfruhling.minecraft.create.trainperspective; -public interface PlayerPerspectiveBehavior { +public interface Perspective { void enable(float initialLean, float initialYaw); void disable(); void setLean(float lean); 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 60fdd59..515608e 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,7 +1,7 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; import net.derfruhling.minecraft.create.trainperspective.Camera3D; -import net.derfruhling.minecraft.create.trainperspective.PlayerPerspectiveBehavior; +import net.derfruhling.minecraft.create.trainperspective.Perspective; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -11,7 +11,6 @@ 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) @@ -48,7 +47,7 @@ public abstract class CameraMixin { @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) { - var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(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)); diff --git a/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/mixin/EntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java similarity index 68% rename from fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/mixin/EntityMixin.java rename to common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java index e0c51fc..d29c011 100644 --- a/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/mixin/EntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java @@ -1,7 +1,8 @@ -package net.derfruhling.minecraft.create.trainperspective.fabric.mixin; +package net.derfruhling.minecraft.create.trainperspective.mixin; -import net.derfruhling.minecraft.create.trainperspective.fabric.ModFabricEntrypoint; +import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -9,21 +10,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import javax.annotation.Nullable; - @Mixin(Entity.class) public class EntityMixin { @Shadow @Nullable private Entity vehicle; @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) { - ModFabricEntrypoint.getInstance().common.onEntityMount(true, (Entity)(Object)this, entity); + CreateTrainPerspectiveMod.INSTANCE.onEntityMount(true, (Entity)(Object)this, entity); } @Inject(method = "removeVehicle", at = @At("HEAD")) public void onRemoveVehicle(CallbackInfo ci) { if(vehicle != null) { - ModFabricEntrypoint.getInstance().common.onEntityMount(false, (Entity)(Object)this, vehicle); + CreateTrainPerspectiveMod.INSTANCE.onEntityMount(false, (Entity)(Object)this, vehicle); } } } 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 9db5a7c..a288f09 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 @@ -2,7 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; -import net.derfruhling.minecraft.create.trainperspective.MixUtil; +import net.derfruhling.minecraft.create.trainperspective.MixinUtil; import net.minecraft.client.Camera; import net.minecraft.client.renderer.GameRenderer; import org.spongepowered.asm.mixin.Final; @@ -18,6 +18,6 @@ public class GameRendererMixin { @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", ordinal = 3, shift = At.Shift.AFTER)) public void applyZRotation(float f, long l, PoseStack poseStack, CallbackInfo ci) { - poseStack.mulPose(Axis.ZP.rotationDegrees(MixUtil.asCamera3D(mainCamera).getZRot())); + poseStack.mulPose(Axis.ZP.rotationDegrees(MixinUtil.asCamera3D(mainCamera).getZRot())); } } 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 a20703a..8faae07 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,12 +2,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; -import net.derfruhling.minecraft.create.trainperspective.PlayerPerspectiveBehavior; +import net.derfruhling.minecraft.create.trainperspective.Perspective; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.util.Mth; -import net.minecraft.world.phys.Vec3; -import org.joml.Vector3f; import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Mixin; @@ -17,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(PlayerRenderer.class) -@Implements({@Interface(iface = PlayerPerspectiveBehavior.class, prefix = "ctp$")}) +@Implements({@Interface(iface = Perspective.class, prefix = "ctp$")}) public class PlayerRendererMixin { @Unique private boolean ctp$perspectiveActive = false; @Unique private float ctp$lean = 0.0f, ctp$yaw = 0.0f; diff --git a/common/src/main/resources/create_train_perspective.mixins.json b/common/src/main/resources/create_train_perspective.mixins.json index 1294e6b..4c8eb29 100644 --- a/common/src/main/resources/create_train_perspective.mixins.json +++ b/common/src/main/resources/create_train_perspective.mixins.json @@ -7,7 +7,8 @@ "CameraMixin", "ContraptionColliderMixin", "GameRendererMixin", - "PlayerRendererMixin" + "PlayerRendererMixin", + "EntityMixin" ], "injectors": { "defaultRequire": 1 diff --git a/fabric/src/main/resources/create_train_perspective.fabric.mixins.json b/fabric/src/main/resources/create_train_perspective.fabric.mixins.json deleted file mode 100644 index c9fc9c4..0000000 --- a/fabric/src/main/resources/create_train_perspective.fabric.mixins.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "net.derfruhling.minecraft.create.trainperspective.fabric.mixin", - "compatibilityLevel": "JAVA_8", - "client": [ - "EntityMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 1758d1d..327352c 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -24,8 +24,7 @@ ] }, "mixins": [ - "create_train_perspective.mixins.json", - "create_train_perspective.fabric.mixins.json" + "create_train_perspective.mixins.json" ], "depends": { "architectury": "*", diff --git a/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java b/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java index 93cad36..67f2b0b 100644 --- a/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java +++ b/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java @@ -2,14 +2,10 @@ import dev.architectury.platform.forge.EventBuses; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.EntityMountEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.jetbrains.annotations.NotNull; @Mod(CreateTrainPerspectiveMod.MODID) public class ModForgeEntrypoint { @@ -21,16 +17,5 @@ public ModForgeEntrypoint() { private void onClientSetupEvent(FMLClientSetupEvent event) { EventBuses.registerModEventBus(CreateTrainPerspectiveMod.MODID, FMLJavaModLoadingContext.get().getModEventBus()); - - MinecraftForge.EVENT_BUS.addListener(this::onEntityMountEvent); - } - - @OnlyIn(Dist.CLIENT) - private void onEntityMountEvent(@NotNull EntityMountEvent event) { - mod.onEntityMount( - event.isMounting(), - event.getEntityMounting(), - event.getEntityBeingMounted() - ); } } From 304d182ea78140150f3b632b1e0e2fd33f2dd5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 21:22:41 -0700 Subject: [PATCH 11/14] #20 bump & fix versions; prep for v0.2.2 --- fabric/gradle.properties | 2 +- gradle.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fabric/gradle.properties b/fabric/gradle.properties index 97dd714..c98f903 100644 --- a/fabric/gradle.properties +++ b/fabric/gradle.properties @@ -1,4 +1,4 @@ loom.platform=fabric -create_version=0.5.1-f-build.1394+mc1.20.1 +create_version=0.5.1-f-build.1417+mc1.20.1 flywheel_version=0.6.10-2 diff --git a/gradle.properties b/gradle.properties index 8dd079f..9b4e30d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,13 +16,13 @@ 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.1 +mod_version=0.2.2 maven_group=net.derfruhling.minecraft archives_base_name=create-train-perspective create_minecraft_version=1.20.1 flywheel_minecraft_version=1.20.1 -registrate_version=MC1.20-1.3.3 +registrate_version=MC1.20-1.3.11 modrinth_project_id=create-train-perspective modrinth_version_type=release From accdf596376b7c8eff04d759217d5f150acd0ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 21:23:56 -0700 Subject: [PATCH 12/14] #20 fixup versions in mods.toml & fabric.mod.json --- 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 327352c..bb1519d 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}", + "version": "${version}+fabric", "contact": { "homepage": "https://github.com/der-fruhling/create-train-perspective", "issues": "https://github.com/der-fruhling/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 cc5880a..76e6928 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/create-train-perspective/issues # The modid of the mod modId="${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version="${mod_version}+forge" #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 1d09bd5eb951cb65671983f5138feae13816ce20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 21:48:17 -0700 Subject: [PATCH 13/14] #20 write the changelog --- changelog.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 29d0881..cf4627d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,26 @@ -- Fabric: This mod now correctly depends on Create Fabric. Sorry for the issues. -- Updated mod metadata to include info about the project. +- Player camera now leans while their train is on a slope. + - 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. +- Players standing on a train will now be affected the same way as players sitting. + - 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. -Full Changelog: https://github.com/der-fruhling/create-train-perspective/compare/v0.2.0...v0.2.1 +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. +- 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) + +--- + +Issues? +Feature Requests? +[View the issue tracker!](https://github.com/der-fruhling-entertainment/create-train-perspective/issues) + +Questions? +[Join the Discord!](https://discord.gg/AyM66DhPKr) +Or, +[discuss on GitHub!](https://github.com/der-fruhling-entertainment/create-train-perspective/discussions) From 71fc1c54df8a915167ddb0fdd9621b7d51019f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Mon, 22 Apr 2024 21:58:52 -0700 Subject: [PATCH 14/14] #20 revise changelog to add more issue links --- changelog.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index cf4627d..5ece566 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,10 @@ -- Player camera now leans while their train is on a slope. +- 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. -- Players standing on a train will now be affected the same way as players sitting. +- 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. +- 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)