Posted April 24, 20232 yr i'm trying to make a mod that announces a chosen player's joining to all other players with a sound. i managed to get a custom sound to play upon a player joining, but for some reason the sound can be only heard within maximum 8 blocks of the joining player's joining spot. i tried playing the sound to every single player's client, but for whatever reason the effect hasn't changed. the forge doc for sounds is barely helpful in this regard, so figuring out this issue by myself seems nigh impossible. two versions of my code, one that plays a sound from the joining player: @SubscribeEvent public void pickupItem(PlayerLoggedInEvent event) { String UUID = configmaker.names.get().toString().replace("[", "").replace("]", "").replace(" ", ""); String[] toStringArray = UUID.split(",");//get the list and split it in to different uuids System.out.println("Player's UUID: " + event.getEntity().getStringUUID().toString());//logs the player's uuid for (int i = 0; i < toStringArray.length; i++) { if (event.getEntity().getStringUUID().equals(toStringArray[i])) {//"893fe864-7b87-4155-b1de-82a517d0e294" is kuba26038 event.getEntity().playSound(ModSounds.THE_SOUND_ITSELF.get(), 1.0F, 1.0F); } } and another one that plays a sound for all clients that are currently in-game: @SubscribeEvent public void pickupItem(PlayerLoggedInEvent event) { String UUID = configmaker.names.get().toString().replace("[", "").replace("]", "").replace(" ", ""); String[] toStringArray = UUID.split(",");//get the list and split it in to different uuids MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); System.out.println("Player's UUID: " + event.getEntity().getStringUUID().toString());//logs the player's uuid for (int i = 0; i < toStringArray.length; i++) { if (event.getEntity().getStringUUID().equals(toStringArray[i])) {//"893fe864-7b87-4155-b1de-82a517d0e294" is kuba26038 List<ServerPlayer> players = server.getPlayerList().getPlayers(); for (ServerPlayer player : players) player.playSound(ModSounds.THE_SOUND_ITSELF.get(), 1.0F, 1.0F); } } please tell me what i'm missing, i'm slowly going insane over this. thanks.
April 24, 20232 yr Quote the forge doc for sounds is barely helpful in this regard You should be grateful that people document Mojang's code at all. The main purpose of the forge documentation is to explain what it provides in addition to Mojang's code. The feature you are using is very much Mojang's code and quite idiosyncratic in its behaviour. Quote so figuring out this issue by myself seems nigh impossible. You didn't consider looking at Mojang's code to see how it actually works? Or using a debugger to see which "if statement" stops the sound from playing? https://forge.gemwire.uk/wiki/Sounds#Player It won't send the sound from the server to the player making the sound. It assumes the client already played the sound. You pass a null player directly to Level.playSound() to send it to the player and nearby players. So your first attempt plays the sound to everybody near the joining player, but not to the joining player The second attempt will be heard by everybody that is near another player. But people by themselves won't hear it because there is no other player making the sound for them. The example I can think of similar to what you want to do is the use of ClientBoundCustomSoundPacket in the PlaySoundCommand? Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.