#PlaySound locally and at position

44 messages · Page 1 of 1 (latest)

loud quiver
#

Hi all,

I've been at this for hours. I've already resource pack'd out the weather2:streaming.siren event by replacing it with just silence. I was able to make it so that the weather2 mod triggering the above siren sound event also triggers my script, and it all works as intended EXCEPT the Client.level.playSound call. For some reason, the sound just doesn't play at that block. Running /playsound manually plays the sound though, so I know it's for sure registered.

Any help is appreciated.

ForgeEvents.onEvent(
  "net.minecraftforge.client.event.sound.SoundEvent",
  (event) => {
    global.SoundEvent(event);
  },
);
StartupEvents.registry("sound_event", (event) => {
  event.create("siren");
});
let sirenActive = false;
global.SoundEvent = (event) => {
  if (Client.player != null) {
    let sound = event.getSound();
    if (sound) {
      let location = sound.location.toString();
      if (location == "weather2:streaming.siren") {
        // get location of sound
        let x = sound.getX();
        let y = sound.getY();
        let z = sound.getZ();
        console.log("Siren sound detected at " + x + ", " + y + ", " + z);
        if (!sirenActive) {
          sirenActive = true;
          Client.player.tell(
            "Siren is not active, playing custom sound and setting sirenActive to true.",
          );

          Client.level.playSound(
            null,
            x,
            y,
            z,
            "kubejs:siren",
            "blocks",
            1.0,
            1.0,
          );
          // after 96 seconds, set sirenActive to false
          Client.schedule(96000, () => {
            sirenActive = false;
          });
        } else {
          Client.player.tell(
            "Siren is already active, not playing custom sound.",
          );
        }
      }
    }
  }
};

polar krakenBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

loud quiver
#

(This is a startup script, btw)

#

There also doesn't seem to be any error output. There's just... no kubejs:siren sound being played at the requested position.

#

The tell messages are shown correctly, though

deep saddle
#

are you sure the params for playSound are correct

#

I only ever played sound server side, so I'm not too sure, but the first param for playsound was a bit fiddly when I looked into playing sounds

loud quiver
#

to be honest, no. i can't find any docs on it and it feels like searching this server has yielded either ..., x, y, z, ... or ..., <something>.pos, .... I don't know which is correct

deep saddle
#

does your sound var even hold anything

#

i'd try logging that first

loud quiver
#

I know it does because:

let x = sound.getX();
let y = sound.getY();
let z = sound.getZ();
console.log("Siren sound detected at " + x + ", " + y + ", " + z);```
does yield correct positional logs
#

at least it did last time i checked. I'll double check real quick

#

yeah

[17:20:17] [Render thread/INFO] [KubeJS Startup/]: siren_replacement.js#21: Siren sound detected at -432.30364990234375, 63, 1139.300048828125
[17:20:17] [Render thread/INFO] [minecraft/ChatComponent]: [CHAT] Siren is not active, playing custom sound and setting sirenActive to true.
[17:20:17] [Thread-111/INFO] [EMI/]: [EMI] Baking recipes
[17:20:17] [Sound engine/INFO] [KubeJS Startup/]: siren_replacement.js#21: Siren sound detected at -432.30364990234375, 63, 1139.300048828125
[17:20:17] [Sound engine/INFO] [minecraft/ChatComponent]: [CHAT] Siren is already active, not playing custom sound.```
deep saddle
#

could be the sound type

#

try "players"

#

instead of "blocks"

#

or "neutral"

loud quiver
#

I'll try but, could that really have made a difference if it worked with blocks when doing /playsound?

#

this is also my sounds.json:

  "siren": {
    "category": "block",
    "stream": true,
    "sounds": [
      "kubejs:siren"
    ]
  }
}```

do I have to update it too? or does it not matter
deep saddle
#

one sec i have an example of a custom streamed sound somewhere

#

i believe it still is played server side but should work

#

as an example

loud quiver
#

yeah still not working

onyx pier
#

I think I have made a client bound sound script

#

Posted in #1048591172165189632

loud quiver
#

But I can't get level off of a SoundEvent

onyx pier
loud quiver
#

so I thought Client.level should work

loud quiver
#

Wait no

#

event.source.getActual()?

onyx pier
#

that just grabs the immediate entity dealing damage from the source

loud quiver
#

wait, it might be because null was passed in for the Player parameter

#

gonna try the playLocalSound syntax instead

#

yeah this makes sense because people typically do it server side so they don't need a specific player, right?

#

but in this case it might be needed

#
Client.level.playLocalSound(
  x,
  y,
  z,
  "kubejs:siren",
  "neutral",
  1.0,
  1.0,
);```
full creekBOT
#

Paste version of message.txt from @loud quiver

loud quiver
#

IT WORKS

#

good lord what strange behavior lol