修复视角摇晃bug

This commit is contained in:
Atsuihsio 2024-09-21 02:12:55 +08:00
parent f629b9ced0
commit 9a4bcf0de6
2 changed files with 27 additions and 143 deletions

View file

@ -85,11 +85,9 @@ public class ClientEventHandler {
float yRotOffset = Mth.lerp(event.getPartialTick(), player.yBobO, player.yBob);
float xRot = player.getViewXRot(event.getPartialTick()) - xRotOffset;
float yRot = player.getViewYRot(event.getPartialTick()) - yRotOffset;
if (player.getMainHandItem().is(ModTags.Items.GUN)) {
turnRot[0] = Mth.clamp(0.05 * xRot, -5, 5) * (1 - 0.75 * zoomTime);
turnRot[1] = Mth.clamp(0.05 * yRot, -10, 10) * (1 - 0.75 * zoomTime);
turnRot[2] = Mth.clamp(0.1 * yRot, -10, 10) * (1 - zoomTime);
}
turnRot[0] = Mth.clamp(0.05 * xRot, -5, 5) * (1 - 0.75 * zoomTime);
turnRot[1] = Mth.clamp(0.05 * yRot, -10, 10) * (1 - 0.75 * zoomTime);
turnRot[2] = Mth.clamp(0.1 * yRot, -10, 10) * (1 - zoomTime);
droneCameraRotX = Mth.clamp(0.25f * xRot, -10, 10);
droneCameraRotY = Mth.clamp(0.25f * yRot, -20, 10);
@ -262,10 +260,10 @@ public class ClientEventHandler {
on_ground = 0.001;
}
if (Minecraft.getInstance().options.keyUp.isDown() && firePosTimer == 0 && zoomTime == 0) {
moveRotZ = Mth.clamp(moveRotZ + 0.007 * times, 0, 0.14);
if (Minecraft.getInstance().options.keyUp.isDown() && firePosTimer == 0) {
moveRotZ = Mth.clamp(moveRotZ + 0.007 * times, 0, 0.14) * (1 - zoomTime);
} else {
moveRotZ = Mth.clamp(moveRotZ - 0.007 * times, 0, 0.14);
moveRotZ = Mth.clamp(moveRotZ - 0.007 * times, 0, 0.14) * (1 - zoomTime);
}
if ((Minecraft.getInstance().options.keyLeft.isDown()
@ -312,17 +310,18 @@ public class ClientEventHandler {
}
}
if (movePosHorizon < 0) {
movePosHorizon += 2 * times * Math.pow(movePosHorizon, 2);
} else {
movePosHorizon -= 2 * times * Math.pow(movePosHorizon, 2);
}
if (Minecraft.getInstance().options.keyRight.isDown()) {
movePosHorizon = Mth.clamp(movePosHorizon + Math.pow(Math.abs(movePosHorizon) + 0.05, 2) * 0.2 * times, -0.5, 0.5) * (1 - zoomTime);
} else if (Minecraft.getInstance().options.keyLeft.isDown()) {
movePosHorizon = Mth.clamp(movePosHorizon - Math.pow(Math.abs(movePosHorizon) + 0.05, 2) * 0.2 * times, -0.5, 0.5) * (1 - zoomTime);
}
if (movePosHorizon < 0) {
movePosHorizon += 2 * times * Math.pow(movePosHorizon, 2) * (1 - zoomTime);
} else {
movePosHorizon -= 2 * times * Math.pow(movePosHorizon, 2) * (1 - zoomTime);
}
double velocity = entity.getDeltaMovement().y();
if (-0.8 < velocity + 0.078 && velocity + 0.078 < 0.8) {
@ -420,15 +419,9 @@ public class ClientEventHandler {
public static void shake(double boneRotX, double boneRotY, double boneRotZ) {
LocalPlayer player = Minecraft.getInstance().player;
if (player != null) {
if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.getVehicle() != null && (player.getVehicle() instanceof ICannonEntity))) {
cameraRot[0] = boneRotX;
cameraRot[1] = boneRotY;
cameraRot[2] = boneRotZ;
} else {
cameraRot[0] = 0;
cameraRot[1] = 0;
cameraRot[2] = 0;
}
cameraRot[0] = boneRotX;
cameraRot[1] = boneRotY;
cameraRot[2] = boneRotZ;
}
}
@ -436,12 +429,18 @@ public class ClientEventHandler {
double yaw = event.getYaw();
double pitch = event.getPitch();
double roll = event.getRoll();
event.setPitch((float) (pitch + cameraRot[0] + 0.2 * turnRot[0] + 3 * velocityY));
event.setYaw((float) (yaw + cameraRot[1] + 0.8 * turnRot[1]));
event.setRoll((float) (roll + cameraRot[2] + 0.35 * turnRot[2]));
LocalPlayer player = Minecraft.getInstance().player;
if (player == null) return;
if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.getVehicle() != null && (player.getVehicle() instanceof ICannonEntity))) {
event.setPitch((float) (pitch + cameraRot[0] + 0.2 * turnRot[0] + 3 * velocityY));
event.setYaw((float) (yaw + cameraRot[1] + 0.8 * turnRot[1]));
event.setRoll((float) (roll + cameraRot[2] + 0.35 * turnRot[2]));
}
}
private static void handleBowPullAnimation(LivingEntity entity) {
private static void handleBowPullAnimation(LivingEntity entity) {
float times = 4 * Minecraft.getInstance().getDeltaFrameTime();
if ((entity.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).bowPull) {

View file

@ -44,7 +44,7 @@ public class GunEventHandler {
ItemStack stack = player.getMainHandItem();
if (event.phase == TickEvent.Phase.END && stack.is(ModTags.Items.GUN)) {
handleGunFire(player);
handleGunBolt(player);
handleMiniGunFire(player);
handleGunReload(player);
handleGunSingleReload(player);
@ -55,124 +55,9 @@ public class GunEventHandler {
/**
* 通用的武器开火流程
*/
private static void handleGunFire(Player player) {
private static void handleGunBolt(Player player) {
ItemStack stack = player.getMainHandItem();
if (stack.is(ModTags.Items.NORMAL_GUN)) {
// double mode = stack.getOrCreateTag().getInt("fire_mode");
//
// int interval = stack.getOrCreateTag().getInt("fire_interval");
//
// if (!player.getPersistentData().getBoolean("firing") && player.getMainHandItem().getItem() == ModItems.DEVOTION.get()) {
// stack.getOrCreateTag().putDouble("fire_increase", 0);
// }
//
// if (stack.getOrCreateTag().getInt("ammo") == 0) {
// stack.getOrCreateTag().putInt("burst_fire", 0);
// }
//
// if ((player.getPersistentData().getBoolean("firing") || stack.getOrCreateTag().getInt("burst_fire") > 0)
// && !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
// && !stack.getOrCreateTag().getBoolean("reloading")
// && !stack.getOrCreateTag().getBoolean("charging")
// && stack.getOrCreateTag().getInt("ammo") > 0
// && !player.getCooldowns().isOnCooldown(stack.getItem())
// && !stack.getOrCreateTag().getBoolean("need_bolt_action")) {
//
// playGunSounds(player);
//
// if (mode == 0) {
// player.getPersistentData().putBoolean("firing", false);
// }
//
// int burstCooldown = 0;
// if (mode == 1) {
// stack.getOrCreateTag().putInt("burst_fire", (stack.getOrCreateTag().getInt("burst_fire") - 1));
// burstCooldown = stack.getOrCreateTag().getInt("burst_fire") == 0 ? interval + 4 : 0;
// }
//
// if (stack.getOrCreateTag().getDouble("animindex") == 1) {
// stack.getOrCreateTag().putDouble("animindex", 0);
// } else {
// stack.getOrCreateTag().putDouble("animindex", 1);
// }
// /*
// 空仓挂机
// */
// if (stack.getOrCreateTag().getInt("ammo") == 1) {
// stack.getOrCreateTag().putBoolean("HoldOpen", true);
// }
//
// /*
// 判断是否为栓动武器bolt_action_time > 0并在开火后给一个需要上膛的状态
// */
// if (stack.getOrCreateTag().getDouble("bolt_action_time") > 0 && stack.getOrCreateTag().getInt("ammo") > 1) {
// stack.getOrCreateTag().putBoolean("need_bolt_action", true);
// }
//
// stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
// stack.getOrCreateTag().putInt("fire_animation", interval);
// player.getPersistentData().putInt("noRun_time", interval + 2);
// stack.getOrCreateTag().putDouble("flash_time", 2);
//
// stack.getOrCreateTag().putDouble("empty", 1);
//
// if (stack.getItem() == ModItems.M_60.get()) {
// stack.getOrCreateTag().putBoolean("bullet_chain", true);
// }
//
// if (stack.getItem() == ModItems.M_4.get() || player.getMainHandItem().getItem() == ModItems.HK_416.get() || player.getMainHandItem().getItem() == ModItems.QBZ_95.get()) {
// if (stack.getOrCreateTag().getDouble("fire_sequence") == 1) {
// stack.getOrCreateTag().putDouble("fire_sequence", 0);
// } else {
// stack.getOrCreateTag().putDouble("fire_sequence", 1);
// }
// }
//
// if (stack.getItem() == ModItems.DEVOTION.get()) {
// stack.getOrCreateTag().putDouble("fire_increase", stack.getOrCreateTag().getDouble("fire_increase") + 0.334);
// }
//
// if (stack.getItem() == ModItems.ABEKIRI.get()) {
// stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(InteractionHand.MAIN_HAND));
// if (player instanceof ServerPlayer serverPlayer && player.level() instanceof ServerLevel serverLevel) {
// ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y,
// player.getZ() + 1.8 * player.getLookAngle().z, 30, 0.4, 0.4, 0.4, 0.005, true, serverPlayer);
// }
// }
//
// if (stack.getItem() == ModItems.SENTINEL.get()) {
// stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
// iEnergyStorage -> iEnergyStorage.extractEnergy(3000, false)
// );
// stack.getOrCreateTag().putDouble("chamber_rot", 20);
// }
//
// int zoomAddCooldown = 0;
// if (stack.getItem() == ModItems.MARLIN.get()) {
// if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) {
// zoomAddCooldown = 5;
// stack.getOrCreateTag().putDouble("marlin_animation_time", 15);
// stack.getOrCreateTag().putBoolean("fastfiring", false);
// } else {
// stack.getOrCreateTag().putDouble("marlin_animation_time", 10);
// stack.getOrCreateTag().putBoolean("fastfiring", true);
// }
// }
//
// int cooldown = interval + (int) stack.getOrCreateTag().getDouble("fire_sequence") - (int) stack.getOrCreateTag().getDouble("fire_increase") + burstCooldown + zoomAddCooldown;
// player.getCooldowns().addCooldown(stack.getItem(), cooldown);
//
// for (int index0 = 0; index0 < (int) stack.getOrCreateTag().getDouble("projectile_amount"); index0++) {
// gunShoot(player);
// }
//
// stack.getOrCreateTag().putBoolean("shoot", true);
//
// }
//
/*
在开火动画的最后1tick设置需要拉栓上膛的武器拉栓动画的倒计时为data里的拉栓时间
*/
if (stack.getOrCreateTag().getInt("fire_animation") == 1 && stack.getOrCreateTag().getBoolean("need_bolt_action")) {
stack.getOrCreateTag().putInt("bolt_action_anim", stack.getOrCreateTag().getInt("bolt_action_time") + 1);
player.getCooldowns().addCooldown(stack.getItem(), stack.getOrCreateTag().getInt("bolt_action_time") + 1);