From 7fe770bf1baa82b6656eecef1da6d3f57fb6d4fa Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Thu, 30 Jan 2025 13:22:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BD=BD=E5=85=B7=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=AD=A6=E5=99=A8=E6=97=B6=E7=9A=84=E9=9F=B3=E6=95=88?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/Ah6Entity.java | 22 +++++++---------- .../entity/vehicle/Bmp2Entity.java | 24 +++++++------------ .../entity/vehicle/Lav150Entity.java | 22 +++++++---------- 3 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index 27ddbbe1d..660ba24ae 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -762,20 +762,16 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli @Override public void changeWeapon(int scroll) { - entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll); - if (entityData.get(WEAPON_TYPE) == 0) { - this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); - } - if (entityData.get(WEAPON_TYPE) == 1) { - this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); - } + var type = (entityData.get(WEAPON_TYPE) + scroll + 2) % 2; + entityData.set(WEAPON_TYPE, type); - if (entityData.get(WEAPON_TYPE) <= -1) { - entityData.set(WEAPON_TYPE, 1); - } - if (entityData.get(WEAPON_TYPE) >= 2) { - entityData.set(WEAPON_TYPE, 0); - } + var sound = switch (type) { + case 0 -> ModSounds.INTO_MISSILE.get(); + case 1 -> ModSounds.INTO_CANNON.get(); + default -> throw new IllegalStateException("Unexpected type: " + type); + }; + + this.level().playSound(null, this, sound, this.getSoundSource(), 1, 1); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index 1961880c5..69530167f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -813,24 +813,16 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ICha @Override public void changeWeapon(int scroll) { - entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll); + var type = (entityData.get(WEAPON_TYPE) + scroll + 3) % 3; + entityData.set(WEAPON_TYPE, type); - if (entityData.get(WEAPON_TYPE) == 0) { - this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); - } - if (entityData.get(WEAPON_TYPE) == 1) { - this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); - } - if (entityData.get(WEAPON_TYPE) == 2) { - this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); - } + var sound = switch (type) { + case 0, 2 -> ModSounds.INTO_MISSILE.get(); + case 1 -> ModSounds.INTO_CANNON.get(); + default -> throw new IllegalStateException("Unexpected type: " + type); + }; - if (entityData.get(WEAPON_TYPE) <= -1) { - entityData.set(WEAPON_TYPE, 2); - } - if (entityData.get(WEAPON_TYPE) >= 3) { - entityData.set(WEAPON_TYPE, 0); - } + this.level().playSound(null, this, sound, this.getSoundSource(), 1, 1); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index d59ca5980..724300c33 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -779,20 +779,16 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC @Override public void changeWeapon(int scroll) { - entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll); - if (entityData.get(WEAPON_TYPE) == 0) { - this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); - } - if (entityData.get(WEAPON_TYPE) == 1) { - this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); - } + var type = (entityData.get(WEAPON_TYPE) + scroll + 2) % 2; + entityData.set(WEAPON_TYPE, type); - if (entityData.get(WEAPON_TYPE) <= -1) { - entityData.set(WEAPON_TYPE, 1); - } - if (entityData.get(WEAPON_TYPE) >= 2) { - entityData.set(WEAPON_TYPE, 0); - } + var sound = switch (type) { + case 0 -> ModSounds.INTO_MISSILE.get(); + case 1 -> ModSounds.INTO_CANNON.get(); + default -> throw new IllegalStateException("Unexpected type: " + type); + }; + + this.level().playSound(null, this, sound, this.getSoundSource(), 1, 1); } @Override