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.",
);
}
}
}
}
};