优化抛壳代码

This commit is contained in:
17146 2024-10-11 20:11:23 +08:00
parent 0630f6e7ce
commit ad0a3f6e03
4 changed files with 26 additions and 77 deletions

View file

@ -84,7 +84,7 @@ public class AK47ItemModel extends GeoModel<AK47Item> {
CoreGeoBone root = getAnimationProcessor().getBone("root"); CoreGeoBone root = getAnimationProcessor().getBone("root");
root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph)); root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph));
root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY)); root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY));
root.setRotX((float) (swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY)); root.setRotX((float) (swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY));
root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY)); root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY));
@ -115,6 +115,6 @@ public class AK47ItemModel extends GeoModel<AK47Item> {
CoreGeoBone shell4 = getAnimationProcessor().getBone("shell4"); CoreGeoBone shell4 = getAnimationProcessor().getBone("shell4");
CoreGeoBone shell5 = getAnimationProcessor().getBone("shell5"); CoreGeoBone shell5 = getAnimationProcessor().getBone("shell5");
ClientEventHandler.handleShell(shell1, shell2, shell3, shell4, shell5, 1f, 1f); ClientEventHandler.handleShells(1f, 1f, shell1, shell2, shell3, shell4, shell5);
} }
} }

View file

@ -76,7 +76,7 @@ public class Aa12ItemModel extends GeoModel<Aa12Item> {
shen.setPosX(0.2f * (float) (ClientEventHandler.recoilHorizon * (0.5 + 0.4 * ClientEventHandler.fireSpread))); shen.setPosX(0.2f * (float) (ClientEventHandler.recoilHorizon * (0.5 + 0.4 * ClientEventHandler.fireSpread)));
CoreGeoBone root = getAnimationProcessor().getBone("root"); CoreGeoBone root = getAnimationProcessor().getBone("root");
root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph)); root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph));
root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY)); root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY));
root.setRotX((float) (swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY)); root.setRotX((float) (swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY));
root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY)); root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY));
@ -98,7 +98,7 @@ public class Aa12ItemModel extends GeoModel<Aa12Item> {
camera.setRotY(numR * camera.getRotY()); camera.setRotY(numR * camera.getRotY());
camera.setRotZ(numR * camera.getRotZ()); camera.setRotZ(numR * camera.getRotZ());
} }
ClientEventHandler.shake(Mth.RAD_TO_DEG * camera.getRotX(),Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ()); ClientEventHandler.shake(Mth.RAD_TO_DEG * camera.getRotX(), Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ());
CoreGeoBone shell1 = getAnimationProcessor().getBone("shell1"); CoreGeoBone shell1 = getAnimationProcessor().getBone("shell1");
CoreGeoBone shell2 = getAnimationProcessor().getBone("shell2"); CoreGeoBone shell2 = getAnimationProcessor().getBone("shell2");
@ -106,6 +106,6 @@ public class Aa12ItemModel extends GeoModel<Aa12Item> {
CoreGeoBone shell4 = getAnimationProcessor().getBone("shell4"); CoreGeoBone shell4 = getAnimationProcessor().getBone("shell4");
CoreGeoBone shell5 = getAnimationProcessor().getBone("shell5"); CoreGeoBone shell5 = getAnimationProcessor().getBone("shell5");
ClientEventHandler.handleShell(shell1, shell2, shell3, shell4, shell5,1f, 0.6f); ClientEventHandler.handleShells(1f, 0.6f, shell1, shell2, shell3, shell4, shell5);
} }
} }

View file

@ -80,7 +80,7 @@ public class M4ItemModel extends GeoModel<M4Item> {
shen.setPosX(0.2f * (float) (ClientEventHandler.recoilHorizon * (0.5 + 0.4 * ClientEventHandler.fireSpread))); shen.setPosX(0.2f * (float) (ClientEventHandler.recoilHorizon * (0.5 + 0.4 * ClientEventHandler.fireSpread)));
CoreGeoBone root = getAnimationProcessor().getBone("root"); CoreGeoBone root = getAnimationProcessor().getBone("root");
root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph)); root.setPosX((float) (movePosX + 20 * ClientEventHandler.drawTime + 9.3f * mph));
root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY)); root.setPosY((float) (swayY + movePosY - 40 * ClientEventHandler.drawTime - 2f * vY));
root.setRotX((float) (swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY)); root.setRotX((float) (swayX - Mth.DEG_TO_RAD * 60 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotX - 0.15f * vY));
root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY)); root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY));
@ -103,7 +103,7 @@ public class M4ItemModel extends GeoModel<M4Item> {
camera.setRotY(numR * camera.getRotY()); camera.setRotY(numR * camera.getRotY());
camera.setRotZ(numR * camera.getRotZ()); camera.setRotZ(numR * camera.getRotZ());
} }
ClientEventHandler.shake(Mth.RAD_TO_DEG * camera.getRotX(),Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ()); ClientEventHandler.shake(Mth.RAD_TO_DEG * camera.getRotX(), Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ());
CoreGeoBone shell1 = getAnimationProcessor().getBone("shell1"); CoreGeoBone shell1 = getAnimationProcessor().getBone("shell1");
CoreGeoBone shell2 = getAnimationProcessor().getBone("shell2"); CoreGeoBone shell2 = getAnimationProcessor().getBone("shell2");
@ -111,6 +111,6 @@ public class M4ItemModel extends GeoModel<M4Item> {
CoreGeoBone shell4 = getAnimationProcessor().getBone("shell4"); CoreGeoBone shell4 = getAnimationProcessor().getBone("shell4");
CoreGeoBone shell5 = getAnimationProcessor().getBone("shell5"); CoreGeoBone shell5 = getAnimationProcessor().getBone("shell5");
ClientEventHandler.handleShell(shell1, shell2, shell3, shell4, shell5,1f, 1f); ClientEventHandler.handleShells(1f, 1f, shell1, shell2, shell3, shell4, shell5);
} }
} }

View file

@ -77,7 +77,6 @@ public class ClientEventHandler {
public static double firePosZ = 0; public static double firePosZ = 0;
public static double fireRot = 0; public static double fireRot = 0;
public static double recoilTime = 0; public static double recoilTime = 0;
public static double recoilHorizon = 0; public static double recoilHorizon = 0;
@ -313,7 +312,7 @@ public class ClientEventHandler {
handleWeaponZoom(living); handleWeaponZoom(living);
handlePlayerBreath(living); handlePlayerBreath(living);
handleWeaponFire(event, living); handleWeaponFire(event, living);
handleWeaponShell(living); handleWeaponShell();
handleGunRecoil(); handleGunRecoil();
handleShockCamera(event, living); handleShockCamera(event, living);
handleBowPullAnimation(living); handleBowPullAnimation(living);
@ -551,7 +550,7 @@ public class ClientEventHandler {
if (0 < fireRotTimer && fireRotTimer < 1.732) { if (0 < fireRotTimer && fireRotTimer < 1.732) {
fireRot = 1 / 6.3 * (fireRotTimer - 0.5) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)); fireRot = 1 / 6.3 * (fireRotTimer - 0.5) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2));
if (recoilY> 0) { if (recoilY > 0) {
event.setYaw((float) (yaw - 1.3 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 1 * Mth.clamp(0.3 - fireRotTimer, 0, 1) * (2 * Math.random() - 1))); event.setYaw((float) (yaw - 1.3 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 1 * Mth.clamp(0.3 - fireRotTimer, 0, 1) * (2 * Math.random() - 1)));
event.setPitch((float) (pitch + 1.3 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 1 * Mth.clamp(0.3 - fireRotTimer, 0, 1) * (2 * Math.random() - 1))); event.setPitch((float) (pitch + 1.3 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 1 * Mth.clamp(0.3 - fireRotTimer, 0, 1) * (2 * Math.random() - 1)));
event.setRoll((float) (roll + 4.2 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 3 * Mth.clamp(0.5 - fireRotTimer, 0, 0.5) * (2 * Math.random() - 1))); event.setRoll((float) (roll + 4.2 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 3 * Mth.clamp(0.5 - fireRotTimer, 0, 0.5) * (2 * Math.random() - 1)));
@ -571,36 +570,17 @@ public class ClientEventHandler {
} }
} }
private static void handleWeaponShell(LivingEntity entity) { private static void handleWeaponShell() {
Player player = Minecraft.getInstance().player; Player player = Minecraft.getInstance().player;
if (player == null) return; if (player == null) return;
float times = Minecraft.getInstance().getDeltaFrameTime(); float times = Minecraft.getInstance().getDeltaFrameTime();
if (shellIndex >= 5) { shellIndex %= 5;
shellIndex = 0;
shellIndexTime[0] = 0; for (int i = 0; i < 5; i++) {
shellIndexTime[i] = Math.min(shellIndexTime[i] + 6 * times * ((50 - shellIndexTime[i]) / 50), 50);
} }
shellIndexTime[0] = Math.min(shellIndexTime[0] + 6 * times * ((50 - shellIndexTime[0]) / 50), 50);
shellIndexTime[1] = Math.min(shellIndexTime[1] + 6 * times * ((50 - shellIndexTime[1]) / 50), 50);
shellIndexTime[2] = Math.min(shellIndexTime[2] + 6 * times * ((50 - shellIndexTime[2]) / 50), 50);
shellIndexTime[3] = Math.min(shellIndexTime[3] + 6 * times * ((50 - shellIndexTime[3]) / 50), 50);
shellIndexTime[4] = Math.min(shellIndexTime[4] + 6 * times * ((50 - shellIndexTime[4]) / 50), 50);
// player.displayClientMessage(Component.literal(new java.text.DecimalFormat("##.##").format(shellIndex) + " "
// + new java.text.DecimalFormat("##").format(shellIndexTime1) + " "
// + new java.text.DecimalFormat("##").format(shellIndexTime2) + " "
// + new java.text.DecimalFormat("##").format(shellIndexTime3) + " "
// + new java.text.DecimalFormat("##").format(shellIndexTime4) + " "
// + new java.text.DecimalFormat("##").format(shellIndexTime5)
// ), true);
} }
private static void handleGunRecoil() { private static void handleGunRecoil() {
@ -630,12 +610,7 @@ public class ClientEventHandler {
} }
recoilY = 0; recoilY = 0;
// player.displayClientMessage(Component.literal(new java.text.DecimalFormat("##.##").format(recoilY) + " " + new java.text.DecimalFormat("##.#").format(recoilHorizon)), true); // 计算后坐力
/*
计算后坐力
*/
float pose = 1; float pose = 1;
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && !isProne(player)) { if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && !isProne(player)) {
pose = 0.7f; pose = 0.7f;
@ -675,8 +650,7 @@ public class ClientEventHandler {
player.xRotO = player.getXRot(); player.xRotO = player.getXRot();
} }
if (recoilTime >= 2.5) recoilTime = 0d; if (recoilTime >= 2.5) recoilTime = 0;
} }
private static void handlePlayerBreath(LivingEntity entity) { private static void handlePlayerBreath(LivingEntity entity) {
@ -840,8 +814,7 @@ public class ClientEventHandler {
@SubscribeEvent @SubscribeEvent
public static void handleChangeSlot(LivingEquipmentChangeEvent event) { public static void handleChangeSlot(LivingEquipmentChangeEvent event) {
if (event.getEntity() instanceof Player player && event.getSlot() == EquipmentSlot.MAINHAND) { if (event.getEntity() instanceof Player && event.getSlot() == EquipmentSlot.MAINHAND) {
ItemStack oldStack = event.getFrom(); ItemStack oldStack = event.getFrom();
ItemStack newStack = event.getTo(); ItemStack newStack = event.getTo();
@ -872,40 +845,16 @@ public class ClientEventHandler {
} }
drawTime = Math.max(drawTime - Math.max(0.2 * speed * times * drawTime, 0.0008), 0); drawTime = Math.max(drawTime - Math.max(0.2 * speed * times * drawTime, 0.0008), 0);
// Player player = Minecraft.getInstance().player;
// if (player != null) {
// player.displayClientMessage(Component.literal(new java.text.DecimalFormat("##.##").format(drawTime)), true);
// }
} }
public static void handleShell(CoreGeoBone shell1, CoreGeoBone shell2, CoreGeoBone shell3, CoreGeoBone shell4, CoreGeoBone shell5, float x, float y) { public static void handleShells(float x, float y, CoreGeoBone... shells) {
for (int i = 0; i < shells.length; i++) {
shell1.setPosX((float) (-x * shellIndexTime[0])); if (i >= 5) break;
shell1.setPosY((float) (randomShell[0] * y * Math.sin(0.15 * shellIndexTime[0])));
shell1.setRotX((float) (randomShell[1] * shellIndexTime[0]));
shell1.setRotY((float) (randomShell[2] * shellIndexTime[0]));
shell2.setPosX((float) (-x * shellIndexTime[1]));
shell2.setPosY((float) (randomShell[0] * y * Math.sin(0.15 * shellIndexTime[1])));
shell2.setRotX((float) (randomShell[1] * shellIndexTime[1]));
shell2.setRotY((float) (randomShell[2] * shellIndexTime[1]));
shell3.setPosX((float) (-x * shellIndexTime[2]));
shell3.setPosY((float) (randomShell[0] * y* Math.sin(0.15 * shellIndexTime[2])));
shell2.setRotX((float) (randomShell[1] * shellIndexTime[2]));
shell3.setRotY((float) (randomShell[2] * shellIndexTime[2]));
shell4.setPosX((float) (-x * shellIndexTime[3]));
shell4.setPosY((float) (randomShell[0] * y * Math.sin(0.15 * shellIndexTime[3])));
shell2.setRotX((float) (randomShell[1] * shellIndexTime[3]));
shell4.setRotY((float) (randomShell[2] * shellIndexTime[3]));
shell5.setPosX((float) (-x * shellIndexTime[4]));
shell5.setPosY((float) (randomShell[0] * y * Math.sin(0.15 * shellIndexTime[4])));
shell2.setRotX((float) (randomShell[1] * shellIndexTime[4]));
shell5.setRotY((float) (randomShell[2] * shellIndexTime[4]));
shells[i].setPosX((float) (-x * shellIndexTime[i]));
shells[i].setPosY((float) (randomShell[0] * y * Math.sin(0.15 * shellIndexTime[i])));
shells[i].setRotX((float) (randomShell[1] * shellIndexTime[i]));
shells[i].setRotY((float) (randomShell[2] * shellIndexTime[i]));
}
} }
} }