修复载具切换武器时的音效播放问题

This commit is contained in:
Light_Quanta 2025-01-30 13:22:24 +08:00
parent 4e525cb506
commit 7fe770bf1b
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 26 additions and 42 deletions

View file

@ -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

View file

@ -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

View file

@ -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