Jump to content

[1.7.2] Starting/stopping long running sound from a block


absalon

Recommended Posts

Hey everyone.

 

I'm trying to grasp minecraft/forge modding and it's been going fine so far. I'm creating a nuclear warning siren for my ic2 nuclear power plant I'm building. I've created a textured siren block so far and when it gets powered by redstone it emits light (I wanted it to be a red warning light, but apparently that's not natively supported by minecraft.. any tips there are welcome) and it plays a siren sound. 

I'm playing the sound with

 

world.playSoundEffect((double)x, (double)y, (double)z, Sirens.MODID + ":siren.nuclear", 5f, 0.5f);

 

And it works beautifully, but the problem is that the siren sound is ~2 minutes long. I want the block to behave exactly like a Jukebox block does when it's broken. That is, when I remove the redstone power from the siren block, I want it to stop (preferably to ease into a "powering down" sound). I've been looking at the Jukebox block and how it handles the right click from a player, but it seems to me that it's using some code specifically created for records.

 

So what I am hoping someone knows how to do is, stop a sound as soon as it's playing (and I don't want to stop all of them, so I can't just somehow tell the sound manager to stop all sounds called "siren.nuclearwarning", incase other sirens are still running).

 

The next phase I would like to go to after getting that to work would then be to have "Siren starting", "Siren on" and "Siren stopping" sounds, so that "Siren starting" is the first sound played, then "Siren on" on repeat until the block it stopped with the "Siren stopping" sound playing at the end. But I'd say that's a 'nice to have' feature if I get the other thing working.

 

The whole source code is available on Github right here. The exact line where I'm playing the sound is here

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.