优化A10的鼠标操控和自由视角

This commit is contained in:
Atsuishio 2025-06-02 00:59:16 +08:00 committed by Light_Quanta
parent 9b9703bbd2
commit 440689c71a
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
4 changed files with 102 additions and 79 deletions

View file

@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.AircraftEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.event.ClientMouseHandler;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.FormatTool;
import com.atsuishio.superbwarfare.tools.InventoryTool;
@ -82,16 +83,17 @@ public class AircraftOverlay implements LayeredDraw.Layer {
RenderSystem.setShaderColor(1, 1, 1, 1);
lerpVy = (float) Mth.lerp(0.021f * partialTick, lerpVy, mobileVehicle.getDeltaMovement().y());
float diffY = Mth.wrapDegrees(Mth.lerp(partialTick, player.yHeadRotO, player.getYHeadRot()) - Mth.lerp(partialTick, mobileVehicle.yRotO, mobileVehicle.getYRot())) * 0.5f;
float diffX = Mth.wrapDegrees(Mth.lerp(partialTick, player.xRotO, player.getXRot()) - Mth.lerp(partialTick, mobileVehicle.xRotO, mobileVehicle.getXRot())) * 0.5f;
float diffY = (float) ClientMouseHandler.lerpSpeedX;
float diffX = (float) ClientMouseHandler.lerpSpeedY;
float fovAdjust2 = (float) (Minecraft.getInstance().options.fov().get() / 30) - 1;
double zoom = 3 + 0.06 * fovAdjust2;
Vec3 pos = aircraftEntity.shootPos(partialTick).add(mobileVehicle.getViewVector(partialTick).scale(192));
Vec3 lookAngle = mobileVehicle.getViewVector(partialTick).normalize().scale(pos.distanceTo(cameraPos) * (1 - 1.0 / zoom));
Vec3 posCross = aircraftEntity.shootPos(partialTick).add(aircraftEntity.shootVec(partialTick).scale(192));
Vec3 lookAngle = player.getViewVector(partialTick).normalize().scale(pos.distanceTo(cameraPos) * (1 - 1.0 / zoom));
Vec3 lookAngle2 = player.getViewVector(partialTick).normalize().scale(posCross.distanceTo(cameraPos) * (1 - 1.0 / zoom));
Vec3 lookAngle2 = aircraftEntity.shootVec(partialTick).normalize().scale(posCross.distanceTo(cameraPos) * (1 - 1.0 / zoom));
var cPos = cameraPos.add(lookAngle);
var cPos2 = cameraPos.add(lookAngle2);

View file

@ -61,6 +61,8 @@ import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import static com.atsuishio.superbwarfare.event.ClientMouseHandler.freeCameraPitch;
import static com.atsuishio.superbwarfare.event.ClientMouseHandler.freeCameraYaw;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity, WeaponVehicleEntity, AircraftEntity {
@ -79,13 +81,17 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
public int reloadCoolDownMissile;
public String lockingTargetO = "none";
public String lockingTarget = "none";
private float yRotSync;
public float destroyRot;
public int lockTime;
public boolean locked;
private boolean wasFiring = false;
public float delta_xo;
public float delta_yo;
public float delta_x;
public float delta_y;
public A10Entity(EntityType<A10Entity> type, Level world) {
super(type, world);
}
@ -202,6 +208,9 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.lockingTargetO = getTargetUuid();
delta_xo = delta_x;
delta_yo = delta_y;
super.baseTick();
float f = (float) Mth.clamp(Math.max((onGround() ? 0.819f : 0.82f) - 0.0035 * getDeltaMovement().length(), 0.5) + 0.001f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99);
@ -463,8 +472,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
@Override
public void travel() {
Entity passenger = this.getFirstPassenger();
float diffX = 0;
float diffY = 0;
if (getHealth() > 0.1f * getMaxHealth()) {
if (passenger == null || isInWater()) {
@ -508,9 +515,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
}
this.entityData.set(PLANE_BREAK, Math.min(this.entityData.get(PLANE_BREAK) + 10, 60f));
}
diffY = Mth.clamp(Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()), -90f, 90f);
diffX = Mth.clamp(Mth.wrapDegrees(passenger.getXRot() - this.getXRot()), -90f, 90f);
}
if (getEnergy() > 0 && !this.level().isClientSide) {
@ -519,17 +523,18 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
float rotSpeed = 1.5f + 2 * Mth.abs(VectorTool.calculateY(getRoll()));
float addY = Mth.clamp(Math.max((this.onGround() ? 0.1f : 0.2f) * (float) getDeltaMovement().length(), 0f) * diffY, -rotSpeed, rotSpeed);
float addX = Mth.clamp(Math.min((float) Math.max(getDeltaMovement().dot(getViewVector(1)) - 0.17, 0.04), 0.7f) * diffX, -3.5f, 3.5f);
float addZ = this.entityData.get(DELTA_ROT) - (this.onGround() ? 0 : 0.004f) * diffY * (float) getDeltaMovement().dot(getViewVector(1));
float addY = Mth.clamp(Math.max((this.onGround() ? 0.1f : 0.2f) * (float) getDeltaMovement().length(), 0f) * entityData.get(MOUSE_SPEED_X), -rotSpeed, rotSpeed);
float addX = Mth.clamp(Math.min((float) Math.max(getDeltaMovement().dot(getViewVector(1)) - 0.24, 0.03), 0.4f) * entityData.get(MOUSE_SPEED_Y), -3.5f, 3.5f);
float addZ = this.entityData.get(DELTA_ROT) - (this.onGround() ? 0 : 0.004f) * entityData.get(MOUSE_SPEED_X) * (float) getDeltaMovement().dot(getViewVector(1));
float i = getXRot() / 80;
yRotSync = addY - VectorTool.calculateY(getXRot()) * addZ;
delta_x = addX;
delta_y = addY - VectorTool.calculateY(getXRot()) * addZ;
this.setYRot(this.getYRot() + yRotSync);
this.setYRot(this.getYRot() + delta_y);
if (!onGround()) {
this.setXRot(Mth.clamp(this.getXRot() + addX, -80, 80));
this.setXRot(this.getXRot() + delta_x);
this.setZRot(this.getRoll() - addZ * (1 - Mth.abs(i)));
}
@ -559,7 +564,7 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
entityData.set(GEAR_ROT, Math.max(entityData.get(GEAR_ROT) - 5, 0));
}
float flapX = (1 - (Mth.abs(getRoll())) / 90) * Mth.clamp(diffX, -22.5f, 22.5f) - VectorTool.calculateY(getRoll()) * Mth.clamp(diffY, -22.5f, 22.5f);
float flapX = (1 - (Mth.abs(getRoll())) / 90) * Mth.clamp(entityData.get(MOUSE_SPEED_Y), -22.5f, 22.5f) - VectorTool.calculateY(getRoll()) * Mth.clamp(entityData.get(MOUSE_SPEED_X), -22.5f, 22.5f);
setFlap1LRot(Mth.clamp(-flapX - 4 * addZ - this.entityData.get(PLANE_BREAK), -22.5f, 22.5f));
setFlap1RRot(Mth.clamp(-flapX + 4 * addZ - this.entityData.get(PLANE_BREAK), -22.5f, 22.5f));
@ -569,11 +574,12 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
setFlap2LRot(Mth.clamp(flapX - 4 * addZ, -22.5f, 22.5f));
setFlap2RRot(Mth.clamp(flapX + 4 * addZ, -22.5f, 22.5f));
float flapY = (1 - (Mth.abs(getRoll())) / 90) * Mth.clamp(diffY, -22.5f, 22.5f) + VectorTool.calculateY(getRoll()) * Mth.clamp(diffX, -22.5f, 22.5f);
float flapY = (1 - (Mth.abs(getRoll())) / 90) * Mth.clamp(entityData.get(MOUSE_SPEED_X), -22.5f, 22.5f) + VectorTool.calculateY(getRoll()) * Mth.clamp(entityData.get(MOUSE_SPEED_Y), -22.5f, 22.5f);
setFlap3Rot(flapY * 5);
} else if (!onGround()) {
float diffX;
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0003f, 0.02f));
destroyRot += 0.1f;
diffX = 90 - this.getXRot();
@ -662,25 +668,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
return entityData.get(POWER) * (sprintInputDown ? 5.5f : 3f);
}
protected void clampRotation(Entity entity) {
float f = Mth.wrapDegrees(entity.getXRot() - this.getXRot());
float f1 = Mth.clamp(f, -85.0F, 60F);
entity.xRotO += f1 - f;
entity.setXRot(entity.getXRot() + f1 - f);
entity.setYBodyRot(this.getYRot());
float f2 = Mth.wrapDegrees(entity.getYRot() - this.getYRot());
float f3 = Mth.clamp(f2, -90.0F, 90.0F);
entity.yRotO += f3 - f2;
entity.setYRot(entity.getYRot() + f3 - f2);
entity.setYBodyRot(this.getYRot());
}
@Override
public void onPassengerTurned(@NotNull Entity entity) {
this.clampRotation(entity);
}
@Override
public void positionRider(@NotNull Entity passenger, @NotNull MoveFunction callback) {
// From Immersive_Aircraft
@ -702,10 +689,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
}
if (passenger != this.getFirstPassenger()) {
passenger.setXRot(passenger.getXRot() + (getXRot() - xRotO));
}
copyEntityData(passenger);
}
@ -723,12 +706,10 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
}
public void copyEntityData(Entity entity) {
float f = Mth.wrapDegrees(entity.getYRot() - getYRot());
float g = Mth.clamp(f, -105.0f, 105.0f);
entity.yRotO += g - f;
entity.setYRot(entity.getYRot() + g - f - yRotSync * VectorTool.calculateY(getXRot()));
entity.setYHeadRot(entity.getYRot());
entity.setYBodyRot(getYRot());
entity.setXRot(this.getXRot());
entity.setYHeadRot(this.getYRot());
entity.setYRot(this.getYRot());
entity.setYBodyRot(this.getYRot());
}
@Override
@ -1031,34 +1012,22 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
@Override
public double getSensitivity(double original, boolean zoom, int seatIndex, boolean isOnGround) {
return 0.25;
return 0;
}
@OnlyIn(Dist.CLIENT)
@Override
public @Nullable Vec2 getCameraRotation(float partialTicks, Player player, boolean zoom, boolean isFirstPerson) {
if (isFirstPerson) {
return new Vec2(Mth.lerp(partialTicks, player.yRotO, player.getYRot()), Mth.lerp(partialTicks, player.xRotO, player.getXRot()));
}
return super.getCameraRotation(partialTicks, player, false, false);
public double getMouseSensitivity() {
return 0.07;
}
@OnlyIn(Dist.CLIENT)
@Override
public Vec3 getCameraPosition(float partialTicks, Player player, boolean zoom, boolean isFirstPerson) {
if (isFirstPerson) {
if (zoom) {
return new Vec3(this.driverZoomPos(partialTicks).x, this.driverZoomPos(partialTicks).y, this.driverZoomPos(partialTicks).z);
} else {
return new Vec3(this.driverPos(partialTicks).x, this.driverPos(partialTicks).y, this.driverPos(partialTicks).z);
}
}
return super.getCameraPosition(partialTicks, player, false, false);
public double getMouseSpeedX() {
return 0.3;
}
@OnlyIn(Dist.CLIENT)
public boolean useFixedCameraPos(Entity entity) {
return true;
@Override
public double getMouseSpeedY() {
return 0.3;
}
@OnlyIn(Dist.CLIENT)
@ -1066,4 +1035,44 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
public Pair<Quaternionf, Quaternionf> getPassengerRotation(Entity entity, float tickDelta) {
return Pair.of(Axis.XP.rotationDegrees(-this.getViewXRot(tickDelta)), Axis.ZP.rotationDegrees(-this.getRoll(tickDelta)));
}
public Matrix4f getClientVehicleTransform(float ticks) {
Matrix4f transform = new Matrix4f();
transform.translate((float) Mth.lerp(ticks, xo, getX()), (float) Mth.lerp(ticks, yo + 2.375f, getY() + 2.375f), (float) Mth.lerp(ticks, zo, getZ()));
transform.rotate(Axis.YP.rotationDegrees((float) (-Mth.lerp(ticks, yRotO, getYRot()) + freeCameraYaw)));
transform.rotate(Axis.XP.rotationDegrees((float) (Mth.lerp(ticks, xRotO, getXRot()) + freeCameraPitch)));
transform.rotate(Axis.ZP.rotationDegrees(Mth.lerp(ticks, prevRoll, getRoll())));
return transform;
}
@OnlyIn(Dist.CLIENT)
@Override
public @Nullable Vec2 getCameraRotation(float partialTicks, Player player, boolean zoom, boolean isFirstPerson) {
Vec3 vec3 = shootVec(partialTicks);
float rotX = (float) -VehicleEntity.getXRotFromVector(vec3);
float rotY = (float) -VehicleEntity.getYRotFromVector(vec3);
if (this.getSeatIndex(player) == 0) {
return new Vec2((float) (rotY - 0.5f * Mth.lerp(partialTicks, delta_yo, delta_y) - freeCameraYaw), (float) (rotX - 0.5f * Mth.lerp(partialTicks, delta_xo, delta_x) + freeCameraPitch));
}
return super.getCameraRotation(partialTicks, player, false, false);
}
@OnlyIn(Dist.CLIENT)
@Override
public Vec3 getCameraPosition(float partialTicks, Player player, boolean zoom, boolean isFirstPerson) {
if (this.getSeatIndex(player) == 0) {
Matrix4f transform = getClientVehicleTransform(partialTicks);
Vector4f worldPosition = transformPosition(transform, 0f, 4, -13);
if (isFirstPerson) {
return new Vec3(Mth.lerp(partialTicks, player.xo, player.getX()), Mth.lerp(partialTicks, player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(partialTicks, player.zo, player.getZ()));
} else {
return new Vec3(worldPosition.x, worldPosition.y, worldPosition.z);
}
}
return super.getCameraPosition(partialTicks, player, false, false);
}
}

View file

@ -1001,6 +1001,18 @@ public abstract class VehicleEntity extends Entity {
return getEyePosition();
}
public double getMouseSensitivity() {
return 0.1;
}
public double getMouseSpeedX() {
return 0.4;
}
public double getMouseSpeedY() {
return 0.4;
}
public float getMass() {
return data().mass();
}

View file

@ -32,8 +32,8 @@ import static com.atsuishio.superbwarfare.event.ClientEventHandler.isFreeCam;
public class ClientMouseHandler {
public static Vec2 posO = new Vec2(0, 0);
public static Vec2 posN = new Vec2(0, 0);
public static double lerpPosX = 0;
public static double lerpPosY = 0;
public static double lerpSpeedX = 0;
public static double lerpSpeedY = 0;
public static double speedX = 0;
@ -60,11 +60,11 @@ public class ClientMouseHandler {
posN = MouseMovementHandler.getMousePos();
if (!notInGame() && player.getVehicle() instanceof VehicleEntity vehicle) {
speedX = 0.1 * (posN.x - posO.x);
speedY = 0.1 * (posN.y - posO.y);
speedX = vehicle.getMouseSensitivity() * (posN.x - posO.x);
speedY = vehicle.getMouseSensitivity() * (posN.y - posO.y);
lerpPosX = Mth.lerp(0.4, lerpPosX, speedX);
lerpPosY = Mth.lerp(0.4, lerpPosY, speedY);
lerpSpeedX = Mth.lerp(vehicle.getMouseSpeedX(), lerpSpeedX, speedX);
lerpSpeedY = Mth.lerp(vehicle.getMouseSpeedY(), lerpSpeedY, speedY);
double i = 0;
@ -81,11 +81,11 @@ public class ClientMouseHandler {
if (!isFreeCam(player)) {
if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) {
PacketDistributor.sendToServer(new MouseMoveMessage(
(1 - (Mth.abs(vehicle.getRoll()) / 90)) * lerpPosX + ((Mth.abs(vehicle.getRoll()) / 90)) * lerpPosY * i,
(1 - (Mth.abs(vehicle.getRoll()) / 90)) * lerpPosY + ((Mth.abs(vehicle.getRoll()) / 90)) * lerpPosX * (vehicle.getRoll() < 0 ? -1 : 1))
(1 - (Mth.abs(vehicle.getRoll()) / 90)) * lerpSpeedX + ((Mth.abs(vehicle.getRoll()) / 90)) * lerpSpeedY * i,
(1 - (Mth.abs(vehicle.getRoll()) / 90)) * lerpSpeedY + ((Mth.abs(vehicle.getRoll()) / 90)) * lerpSpeedX * (vehicle.getRoll() < 0 ? -1 : 1))
);
} else {
PacketDistributor.sendToServer(new MouseMoveMessage(lerpPosX, lerpPosY));
PacketDistributor.sendToServer(new MouseMoveMessage(lerpSpeedX, lerpSpeedY));
}
} else {
PacketDistributor.sendToServer(new MouseMoveMessage(0, 0));
@ -101,8 +101,8 @@ public class ClientMouseHandler {
float times = 0.6f * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8);
if (isFreeCam(player)) {
freeCameraYaw -= 0.4f * times * lerpPosX;
freeCameraPitch += 0.2f * times * lerpPosY;
freeCameraYaw -= 0.4f * times * lerpSpeedX;
freeCameraPitch += 0.2f * times * lerpSpeedY;
} else {
freeCameraYaw = Mth.lerp(0.075 * event.getPartialTick(), freeCameraYaw, 0);
freeCameraPitch = Mth.lerp(0.075 * event.getPartialTick(), freeCameraPitch, 0);