Change positioned sounds to be non-relative and have their location correctly set at the beginning so it doesn't start at the camera position

This commit is contained in:
Sollace 2023-08-28 22:23:35 +01:00
parent 22bed1ee19
commit ba0f5ecd4c
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 18 additions and 7 deletions

View file

@ -64,7 +64,7 @@ public class ClientInteractionManager extends InteractionManager {
SoundManager soundManager = client.getSoundManager();
if (type == SOUND_EARS_RINGING && source instanceof LivingEntity living) {
soundManager.play(new LoopingSoundInstance<>(living,
soundManager.playNextTick(new LoopingSoundInstance<>(living,
createTicker(100).and(e -> !e.isRemoved()),
USounds.ENTITY_PLAYER_EARS_RINGING, 0.01F, 2, Random.create(seed)).setFadeIn()
);
@ -75,26 +75,26 @@ public class ClientInteractionManager extends InteractionManager {
: new PassiveBeeSoundInstance(bee)
);
} else if (type == SOUND_MINECART && source instanceof AbstractMinecartEntity minecart) {
soundManager.play(new MovingMinecartSoundInstance(minecart));
soundManager.playNextTick(new MovingMinecartSoundInstance(minecart));
} else if (type == SOUND_CHANGELING_BUZZ && source instanceof PlayerEntity player) {
soundManager.play(new MotionBasedSoundInstance<>(USounds.ENTITY_PLAYER_CHANGELING_BUZZ, player, e -> {
soundManager.playNextTick(new MotionBasedSoundInstance<>(USounds.ENTITY_PLAYER_CHANGELING_BUZZ, player, e -> {
PlayerPhysics physics = Pony.of(e).getPhysics();
return physics.isFlying() && physics.getFlightType() == FlightType.INSECTOID;
}, 0.25F, 0.5F, 0.66F, Random.create(seed)));
} else if (type == SOUND_GLIDING && source instanceof PlayerEntity player && isClientPlayer(player)) {
soundManager.play(new MotionBasedSoundInstance<>(USounds.Vanilla.ITEM_ELYTRA_FLYING, player, e -> {
soundManager.playNextTick(new MotionBasedSoundInstance<>(USounds.Vanilla.ITEM_ELYTRA_FLYING, player, e -> {
Pony pony = Pony.of(e);
return pony.getPhysics().isFlying() && pony.getPhysics().getFlightType().isAvian();
}, 0, 1, 1, Random.create(seed)));
} else if (type == SOUND_GLIDING && source instanceof PlayerEntity player) {
soundManager.play(new MotionBasedSoundInstance<>(USounds.ENTITY_PLAYER_PEGASUS_FLYING, player, e -> {
soundManager.playNextTick(new MotionBasedSoundInstance<>(USounds.ENTITY_PLAYER_PEGASUS_FLYING, player, e -> {
Pony pony = Pony.of(e);
return pony.getPhysics().isFlying() && pony.getPhysics().getFlightType().isAvian();
}, 0, 1, 1, Random.create(seed)));
} else if (type == SOUND_MAGIC_BEAM) {
soundManager.play(new LoopedEntityTrackingSoundInstance(USounds.SPELL_CAST_SHOOT, 0.3F, 1F, source, seed));
soundManager.playNextTick(new LoopedEntityTrackingSoundInstance(USounds.SPELL_CAST_SHOOT, 0.3F, 1F, source, seed));
} else if (type == SOUND_HEART_BEAT) {
soundManager.play(new NonLoopingFadeOutSoundInstance(USounds.ENTITY_PLAYER_HEARTBEAT, SoundCategory.PLAYERS, 0.3F, Random.create(seed), 80L));
soundManager.playNextTick(new NonLoopingFadeOutSoundInstance(USounds.ENTITY_PLAYER_HEARTBEAT, SoundCategory.PLAYERS, 0.3F, Random.create(seed), 80L));
}
});
}

View file

@ -17,7 +17,13 @@ public class MagicAuraSoundInstance extends FadeOutSoundInstance {
public MagicAuraSoundInstance(SoundCategory category, Living<?> living, Random random) {
super(USounds.ITEM_MAGIC_AURA, category, 1, random);
this.relative = false;
this.living = living;
Vec3d pos = living.getOriginVector();
x = pos.x;
y = pos.y;
z = pos.z;
}
@Override

View file

@ -35,6 +35,11 @@ public class MotionBasedSoundInstance<E extends Entity> extends FadeOutSoundInst
this.minVolume = minVolume;
this.maxVolume = maxVolume;
this.playingCondition = playingCondition;
this.relative = false; // position is ABSOLUTE! We do this so the sound doesn't play to other players
x = (float)entity.getX();
y = (float)entity.getY();
z = (float)entity.getZ();
}
@Override