优化飞控

This commit is contained in:
Atsuihsio 2025-01-25 01:00:30 +08:00
parent 0b983f8b1d
commit 91067cc152
5 changed files with 110 additions and 10 deletions

View file

@ -40,6 +40,10 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
public boolean upInputDown; public boolean upInputDown;
public boolean downInputDown; public boolean downInputDown;
public boolean decoyInputDown; public boolean decoyInputDown;
public boolean leftInputDownMouse;
public boolean rightInputDownMouse;
public boolean upInputDownMouse;
public boolean downInputDownMouse;
public double lastTickSpeed; public double lastTickSpeed;
public double lastTickVerticalSpeed; public double lastTickVerticalSpeed;
public int collisionCoolDown; public int collisionCoolDown;

View file

@ -190,7 +190,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
setXRot(getXRot() * 0.7f); setXRot(getXRot() * 0.7f);
setZRot(getRoll() * 0.7f); setZRot(getRoll() * 0.7f);
} else { } else {
setZRot(getRoll() * 0.994f); // setZRot(getRoll() * 0.994f);
} }
// if (this.forwardInputDown || this.backInputDown) { // if (this.forwardInputDown || this.backInputDown) {

View file

@ -1,6 +1,8 @@
package com.atsuishio.superbwarfare.event; package com.atsuishio.superbwarfare.event;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.client.MouseMovementHandler; import com.atsuishio.superbwarfare.client.MouseMovementHandler;
import com.atsuishio.superbwarfare.network.message.VehicleMovementMessage;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -51,9 +53,48 @@ public class ClientMouseHandler {
} }
} }
lerpPosX = Mth.lerp(0.1,lerpPosX,0); lerpPosX = Mth.clamp(Mth.lerp(0.1,lerpPosX,0), -0.11, 0.11);
lerpPosY = Mth.lerp(0.1,lerpPosY,0); lerpPosY = Mth.clamp(Mth.lerp(0.1,lerpPosY,0), -0.11, 0.11);
// player.displayClientMessage(Component.literal(new DecimalFormat("##.##").format(lerpPosX)), true); int typeX = 0;
if (lerpPosX < -0.05) {
typeX = -1;
} else if (lerpPosX > 0.05) {
typeX = 1;
}
int typeY = 0;
if (lerpPosY < -0.05) {
typeY = 1;
} else if (lerpPosY > 0.05) {
typeY = -1;
}
if (typeX == -1) {
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(7, true));
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(8, false));
} else if (typeX == 1) {
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(7, false));
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(8, true));
} else {
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(7, false));
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(8, false));
}
if (typeY == 1) {
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(9, true));
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(10, false));
} else if (typeY == -1) {
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(9, false));
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(10, true));
} else {
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(9, false));
ModUtils.PACKET_HANDLER.sendToServer(new VehicleMovementMessage(10, false));
}
// player.displayClientMessage(Component.literal(typeX + " " + typeY), true);
} }
} }

View file

@ -1,10 +1,7 @@
package com.atsuishio.superbwarfare.mixins; package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.config.client.VehicleControlConfig; import com.atsuishio.superbwarfare.config.client.VehicleControlConfig;
import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity; import com.atsuishio.superbwarfare.entity.vehicle.*;
import com.atsuishio.superbwarfare.entity.vehicle.ICannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity;
import com.atsuishio.superbwarfare.entity.vehicle.Tom6Entity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModMobEffects; import com.atsuishio.superbwarfare.init.ModMobEffects;
@ -29,6 +26,9 @@ import static com.atsuishio.superbwarfare.event.ClientEventHandler.droneFovLerp;
@Mixin(MouseHandler.class) @Mixin(MouseHandler.class)
public class MouseHandlerMixin { public class MouseHandlerMixin {
private static double x;
private static double y;
@ModifyVariable(method = "turnPlayer()V", at = @At(value = "STORE", opcode = Opcodes.DSTORE), ordinal = 2) @ModifyVariable(method = "turnPlayer()V", at = @At(value = "STORE", opcode = Opcodes.DSTORE), ordinal = 2)
private double sensitivity(double original) { private double sensitivity(double original) {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
@ -80,12 +80,55 @@ public class MouseHandlerMixin {
if (player == null) return i; if (player == null) return i;
if (player.getVehicle() instanceof Ah6Entity ah6Entity && ah6Entity.getFirstPassenger() == player) { if (player.getVehicle() instanceof Ah6Entity ah6Entity && ah6Entity.getFirstPassenger() == player) {
return VehicleControlConfig.INVERT_AIRCRAFT_CONTROL.get() ? (Mth.abs(ah6Entity.getRoll()) < 90 ? -i : i) : (Mth.abs(ah6Entity.getRoll()) < 90 ? i : -i); return VehicleControlConfig.INVERT_AIRCRAFT_CONTROL.get() ? -i : i;
} }
if (player.getVehicle() instanceof Tom6Entity tom6 && tom6.getFirstPassenger() == player) { if (player.getVehicle() instanceof Tom6Entity tom6 && tom6.getFirstPassenger() == player) {
return VehicleControlConfig.INVERT_AIRCRAFT_CONTROL.get() ? (Mth.abs(tom6.getRoll()) < 90 ? -i : i) : (Mth.abs(tom6.getRoll()) < 90 ? i : -i); return VehicleControlConfig.INVERT_AIRCRAFT_CONTROL.get() ? -i : i;
} }
return i; return i;
} }
@ModifyVariable(method = "turnPlayer()V", at = @At(value = "STORE", opcode = Opcodes.DSTORE), ordinal = 5)
private double modifyD2(double d) {
Minecraft mc = Minecraft.getInstance();
Player player = mc.player;
if (player == null) return d;
if (player.getVehicle() instanceof VehicleEntity vehicle) {
x = d;
double i = 0;
if (vehicle.getRoll() < 0) {
i = 1;
} else if (vehicle.getRoll() > 0) {
i = -1;
}
if (Mth.abs(vehicle.getRoll()) > 90) {
i *= (1 - (Mth.abs(vehicle.getRoll()) - 90) / 90);
}
return (1 - (Mth.abs(vehicle.getRoll()) / 90)) * d + ((Mth.abs(vehicle.getRoll()) / 90)) * y * i;
}
return d;
}
@ModifyVariable(method = "turnPlayer()V", at = @At(value = "STORE", opcode = Opcodes.DSTORE), ordinal = 6)
private double modifyD3(double d) {
Minecraft mc = Minecraft.getInstance();
Player player = mc.player;
if (player == null) return d;
if (player.getVehicle() instanceof VehicleEntity vehicle) {
y = d;
return (1 - (Mth.abs(vehicle.getRoll()) / 90)) * d + ((Mth.abs(vehicle.getRoll()) / 90)) * x * (vehicle.getRoll() < 0 ? -1 : 1);
}
return d;
}
} }

View file

@ -60,6 +60,18 @@ public class VehicleMovementMessage {
case 6: case 6:
mobileVehicleEntity.decoyInputDown = message.clicked; mobileVehicleEntity.decoyInputDown = message.clicked;
break; break;
case 7:
mobileVehicleEntity.leftInputDownMouse = message.clicked;
break;
case 8:
mobileVehicleEntity.rightInputDownMouse = message.clicked;
break;
case 9:
mobileVehicleEntity.downInputDownMouse = message.clicked;
break;
case 10:
mobileVehicleEntity.upInputDownMouse = message.clicked;
break;
} }
} else if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) { } else if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {
var drone = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone")); var drone = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone"));