You spin me right round

- Seated Players now sync their camera rotation to the movement of the contraption (if possible)
This commit is contained in:
simibubi 2024-08-06 13:42:36 +02:00
parent 2e91e16932
commit 8b782019e0
4 changed files with 83 additions and 4 deletions

View file

@ -870,10 +870,11 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
public static class ContraptionRotationState { public static class ContraptionRotationState {
public static final ContraptionRotationState NONE = new ContraptionRotationState(); public static final ContraptionRotationState NONE = new ContraptionRotationState();
float xRotation = 0; public float xRotation = 0;
float yRotation = 0; public float yRotation = 0;
float zRotation = 0; public float zRotation = 0;
float secondYRotation = 0; public float secondYRotation = 0;
Matrix3d matrix; Matrix3d matrix;
public Matrix3d asMatrix() { public Matrix3d asMatrix() {

View file

@ -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));
}
}

View file

@ -7,6 +7,7 @@ import com.simibubi.create.AllPackets;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.CreateClient; import com.simibubi.create.CreateClient;
import com.simibubi.create.content.contraptions.ContraptionHandler; 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.actors.trainControls.ControlsHandler;
import com.simibubi.create.content.contraptions.chassis.ChassisRangeDisplay; import com.simibubi.create.content.contraptions.chassis.ChassisRangeDisplay;
import com.simibubi.create.content.contraptions.minecart.CouplingHandlerClient; import com.simibubi.create.content.contraptions.minecart.CouplingHandlerClient;
@ -166,6 +167,7 @@ public class ClientEvents {
CreateClient.VALUE_SETTINGS_HANDLER.tick(); CreateClient.VALUE_SETTINGS_HANDLER.tick();
ScrollValueHandler.tick(); ScrollValueHandler.tick();
NetheriteBacktankFirstPersonRenderer.clientTick(); NetheriteBacktankFirstPersonRenderer.clientTick();
ContraptionPlayerPassengerRotation.tick();
} }
@SubscribeEvent @SubscribeEvent
@ -218,6 +220,8 @@ public class ClientEvents {
buffer.draw(); buffer.draw();
RenderSystem.enableCull(); RenderSystem.enableCull();
ms.popPose(); ms.popPose();
ContraptionPlayerPassengerRotation.frame();
} }
@SubscribeEvent @SubscribeEvent

View file

@ -33,6 +33,8 @@ public class CClient extends ConfigBase {
Comments.ingameMenuConfigButtonOffsetX); Comments.ingameMenuConfigButtonOffsetX);
public final ConfigBool ignoreFabulousWarning = b(false, "ignoreFabulousWarning", public final ConfigBool ignoreFabulousWarning = b(false, "ignoreFabulousWarning",
Comments.ignoreFabulousWarning); Comments.ignoreFabulousWarning);
public final ConfigBool rotateWhenSeated = b(true, "rotateWhenSeated",
Comments.rotatewhenSeated);
// custom fluid fog // custom fluid fog
public final ConfigGroup fluidFogSettings = group(1, "fluidFogSettings", Comments.fluidFogSettings); 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)" "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 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 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 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"; static String overlayCustomColor = "Enable this to use your custom colors for the Goggle- and Hover- Overlay";