diff --git a/src/main/java/com/simibubi/create/content/contraptions/AbstractContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/AbstractContraptionEntity.java index 795513952..aabab575b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/AbstractContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/AbstractContraptionEntity.java @@ -870,10 +870,11 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit public static class ContraptionRotationState { public static final ContraptionRotationState NONE = new ContraptionRotationState(); - float xRotation = 0; - float yRotation = 0; - float zRotation = 0; - float secondYRotation = 0; + public float xRotation = 0; + public float yRotation = 0; + public float zRotation = 0; + public float secondYRotation = 0; + Matrix3d matrix; public Matrix3d asMatrix() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/seat/ContraptionPlayerPassengerRotation.java b/src/main/java/com/simibubi/create/content/contraptions/actors/seat/ContraptionPlayerPassengerRotation.java new file mode 100644 index 000000000..d5c81643c --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/seat/ContraptionPlayerPassengerRotation.java @@ -0,0 +1,71 @@ +package com.simibubi.create.content.contraptions.actors.seat; + +import com.simibubi.create.content.contraptions.AbstractContraptionEntity; +import com.simibubi.create.content.contraptions.AbstractContraptionEntity.ContraptionRotationState; +import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.infrastructure.config.AllConfigs; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; + +public class ContraptionPlayerPassengerRotation { + + static boolean active; + static int prevId; + static float prevYaw; + static float prevPitch; + + public static void tick() { + active = AllConfigs.client().rotateWhenSeated.get(); + } + + public static void frame() { + Player player = Minecraft.getInstance().player; + if (!active) + return; + if (player == null || !player.isPassenger()) { + prevId = 0; + return; + } + + Entity vehicle = player.getVehicle(); + if (!(vehicle instanceof AbstractContraptionEntity contraptionEntity)) + return; + + ContraptionRotationState rotationState = contraptionEntity.getRotationState(); + + float yaw = AngleHelper.wrapAngle180((contraptionEntity instanceof CarriageContraptionEntity cce) + ? cce.getViewYRot(AnimationTickHolder.getPartialTicks()) + : rotationState.yRotation); + + float pitch = (contraptionEntity instanceof CarriageContraptionEntity cce) + ? cce.getViewXRot(AnimationTickHolder.getPartialTicks()) + : 0; + + if (prevId != contraptionEntity.getId()) { + prevId = contraptionEntity.getId(); + prevYaw = yaw; + prevPitch = pitch; + } + + float yawDiff = AngleHelper.getShortestAngleDiff(yaw, prevYaw); + float pitchDiff = AngleHelper.getShortestAngleDiff(pitch, prevPitch); + + prevYaw = yaw; + prevPitch = pitch; + + float yawRelativeToTrain = Mth.abs(AngleHelper.getShortestAngleDiff(player.getYRot(), -yaw - 90)); + if (yawRelativeToTrain > 120) + pitchDiff *= -1; + else if (yawRelativeToTrain > 60) + pitchDiff *= 0; + + player.setYRot((float) (player.getYRot() + yawDiff)); + player.setXRot((float) (player.getXRot() + pitchDiff)); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/events/ClientEvents.java b/src/main/java/com/simibubi/create/foundation/events/ClientEvents.java index c373e6d9b..162447300 100644 --- a/src/main/java/com/simibubi/create/foundation/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/foundation/events/ClientEvents.java @@ -7,6 +7,7 @@ import com.simibubi.create.AllPackets; import com.simibubi.create.Create; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.ContraptionHandler; +import com.simibubi.create.content.contraptions.actors.seat.ContraptionPlayerPassengerRotation; import com.simibubi.create.content.contraptions.actors.trainControls.ControlsHandler; import com.simibubi.create.content.contraptions.chassis.ChassisRangeDisplay; import com.simibubi.create.content.contraptions.minecart.CouplingHandlerClient; @@ -166,6 +167,7 @@ public class ClientEvents { CreateClient.VALUE_SETTINGS_HANDLER.tick(); ScrollValueHandler.tick(); NetheriteBacktankFirstPersonRenderer.clientTick(); + ContraptionPlayerPassengerRotation.tick(); } @SubscribeEvent @@ -218,6 +220,8 @@ public class ClientEvents { buffer.draw(); RenderSystem.enableCull(); ms.popPose(); + + ContraptionPlayerPassengerRotation.frame(); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/infrastructure/config/CClient.java b/src/main/java/com/simibubi/create/infrastructure/config/CClient.java index f864101f5..a25381f6b 100644 --- a/src/main/java/com/simibubi/create/infrastructure/config/CClient.java +++ b/src/main/java/com/simibubi/create/infrastructure/config/CClient.java @@ -33,6 +33,8 @@ public class CClient extends ConfigBase { Comments.ingameMenuConfigButtonOffsetX); public final ConfigBool ignoreFabulousWarning = b(false, "ignoreFabulousWarning", Comments.ignoreFabulousWarning); + public final ConfigBool rotateWhenSeated = b(true, "rotateWhenSeated", + Comments.rotatewhenSeated); // custom fluid fog public final ConfigGroup fluidFogSettings = group(1, "fluidFogSettings", Comments.fluidFogSettings); @@ -125,6 +127,7 @@ public class CClient extends ConfigBase { "The sign (-/+) of this value determines what side of the row the button appears on (left/right)" }; static String ignoreFabulousWarning = "Setting this to true will prevent Create from sending you a warning when playing with Fabulous graphics enabled"; + static String rotatewhenSeated = "Disable to prevent being rotated while seated on a Moving Contraption"; static String overlay = "Settings for the Goggle Overlay"; static String overlayOffset = "Offset the overlay from goggle- and hover- information by this many pixels on the respective axis; Use /create overlay"; static String overlayCustomColor = "Enable this to use your custom colors for the Goggle- and Hover- Overlay";