Skip to content

Commit

Permalink
Merge pull request #11 from Jerozgen/master
Browse files Browse the repository at this point in the history
Make sounds relative and play no sounds on chat refresh
  • Loading branch information
AlurienFlame authored Sep 27, 2022
2 parents 1c24927 + 65d511c commit 9416cf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
24 changes: 12 additions & 12 deletions src/main/java/net/chatsounds/ChatsoundsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static class JoinConfig{
float pitch = 1f;
Sounds sound = Sounds.BLOCK_BARREL_OPEN;

public PositionedSoundInstance getChatSound(double x, double y, double z) {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.LINEAR, x, y, z, false);
public PositionedSoundInstance getChatSound() {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.NONE, 0, 0, 0, true);
}
}

Expand All @@ -62,8 +62,8 @@ public static class LeaveConfig{
float pitch = 1f;
Sounds sound = Sounds.BLOCK_BARREL_CLOSE;

public PositionedSoundInstance getChatSound(double x, double y, double z) {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.LINEAR, x, y, z, false);
public PositionedSoundInstance getChatSound() {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.NONE, 0, 0, 0, true);
}
}

Expand All @@ -76,8 +76,8 @@ public static class DeathConfig{
float pitch = 0.1f;
Sounds sound = Sounds.BLOCK_BELL_USE;

public PositionedSoundInstance getChatSound(double x, double y, double z) {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.LINEAR, x, y, z, false);
public PositionedSoundInstance getChatSound() {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.NONE, 0, 0, 0, true);
}
}

Expand All @@ -90,8 +90,8 @@ public static class PmConfig{
float pitch = 1f;
Sounds sound = Sounds.ENTITY_VILLAGER_WORK_CARTOGRAPHER;

public PositionedSoundInstance getChatSound(double x, double y, double z) {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.LINEAR, x, y, z, false);
public PositionedSoundInstance getChatSound() {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.NONE, 0, 0, 0, true);
}
}

Expand All @@ -104,8 +104,8 @@ public static class AdvancementConfig{
float pitch = 1f;
Sounds sound = Sounds.ENTITY_EXPERIENCE_ORB_PICKUP;

public PositionedSoundInstance getChatSound(double x, double y, double z) {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.LINEAR, x, y, z, false);
public PositionedSoundInstance getChatSound() {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.NONE, 0, 0, 0, true);
}
}

Expand All @@ -118,8 +118,8 @@ public static class MessageConfig{
float pitch = 0.3f;
Sounds sound = Sounds.ENTITY_ITEM_PICKUP;

public PositionedSoundInstance getChatSound(double x, double y, double z) {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.LINEAR, x, y, z, false);
public PositionedSoundInstance getChatSound() {
return new PositionedSoundInstance(this.sound.getId(), SoundCategory.PLAYERS, this.volume, this.pitch, SoundInstance.createRandom(), false, 0, SoundInstance.AttenuationType.NONE, 0, 0, 0, true);
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/main/java/net/chatsounds/mixin/ChatsoundsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,43 @@
public class ChatsoundsMixin {
@Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", at = @At("HEAD"))
private void addMessage(Text message, @Nullable MessageSignatureData signature, int ticks, @Nullable MessageIndicator indicator, boolean refresh, CallbackInfo ci) {
if (refresh) return;

ChatsoundsConfig config = AutoConfig.getConfigHolder(ChatsoundsConfig.class).getConfig();
MinecraftClient client = MinecraftClient.getInstance();
double x = client.player.getX();
double y = client.player.getY();
double z = client.player.getZ();

TextContent content = message.getContent();

if (content instanceof TranslatableTextContent) {
String key = ((TranslatableTextContent) content).getKey();

if (config.join.enabled && key.contains("multiplayer.player.joined")) {
client.getSoundManager().play(config.join.getChatSound(x, y, z));
client.getSoundManager().play(config.join.getChatSound());

} else if (config.leave.enabled && key.contains("multiplayer.player.left")) {
client.getSoundManager().play(config.leave.getChatSound(x, y, z));
client.getSoundManager().play(config.leave.getChatSound());

} else if (config.death.enabled && key.contains("death.")) {
client.getSoundManager().play(config.death.getChatSound(x, y, z));
client.getSoundManager().play(config.death.getChatSound());

} else if (config.pm.enabled && key.contains("commands.message.display.")) {
client.getSoundManager().play(config.pm.getChatSound(x, y, z));
client.getSoundManager().play(config.pm.getChatSound());

} else if (config.advancement.enabled && key.contains("chat.type.advancement.")) {
client.getSoundManager().play(config.advancement.getChatSound(x, y, z));
client.getSoundManager().play(config.advancement.getChatSound());

} else if (config.message.enabled && key.contains("chat.type.")) {
client.getSoundManager().play(config.message.getChatSound(x, y, z));
client.getSoundManager().play(config.message.getChatSound());

} else {
System.out.println(String.format("Chatsounds failed to find translation key: %s", key));
client.getSoundManager().play(config.message.getChatSound(x, y, z));
client.getSoundManager().play(config.message.getChatSound());
}

} else {
// Fall back to the message sound
if (config.message.enabled) {
client.getSoundManager().play(config.message.getChatSound(x, y, z));
client.getSoundManager().play(config.message.getChatSound());
}
}
}
Expand Down

0 comments on commit 9416cf8

Please sign in to comment.