Jump to content

Recommended Posts

Posted

Hi

 

Yes there is, have a look at vanilla MovingSoundMinecartRiding and/or RenderGlobal.playRecord().

 

You can play the sound using something like

 

  ResourceLocation mySoundRes = new ResourceLocation("mymodid:mysound");

  PositionedSoundRecord  mySoundRes = PositionedSoundRecord.create(mySoundRes);

  Minecraft.getMinecraft().getSoundHandler().playSound(mySoundRes);

 

put a sounds.json in

resources/assets/mymodid/

 

{

  "mysound": {"category": "ambient", "sounds": ["mysoundfilename"]}

}

 

and your .ogg sound file in

resources/assets/mymodid/sounds

mysoundfilename.ogg

 

It's a bit fiddly to get right.... the console often gives you a relevant error message.

 

-TGG

Posted

You can subscribe ClientTickEvent and play the background music randomly.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted
  On 4/2/2015 at 2:56 PM, Alanzote said:

  Quote

You can subscribe ClientTickEvent and play the background music randomly.

Can you give me a little example?

 

For learning how to handle events (this is worth learning as it is a powerful modding approach) I have a tutorial here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

For the random part, that is just Java. Always remember that in Minecraft modding that you can do anything that Java can do.  For example, Java has the Random class: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html

 

Use the random class to generate a number, use an if statement to compare that number to some chance, and if the chance happens play the sound.

 

Note that the client tick handler is fired 20 times per second.  So if you want 6 minutes on average between playing the sound, you need the chance to play to be less than 1/3600.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
  On 4/2/2015 at 3:01 PM, jabelar said:

  Quote

  Quote

You can subscribe ClientTickEvent and play the background music randomly.

Can you give me a little example?

 

For learning how to handle events (this is worth learning as it is a powerful modding approach) I have a tutorial here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

For the random part, that is just Java. Always remember that in Minecraft modding that you can do anything that Java can do.  For example, Java has the Random class: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html

 

Use the random class to generate a number, use an if statement to compare that number to some chance, and if the chance happens play the sound.

 

Note that the client tick handler is fired 20 times per second.  So if you want 6 minutes on average between playing the sound, you need the chance to play to be less than 1/3600.

I am getting an Error in My Event Class:

 

 

  Reveal hidden contents

 

My EventClass:

 

  Reveal hidden contents

 

Posted
  On 4/2/2015 at 4:02 PM, diesieben07 said:

Read the error. It's an english sentence that tells you EXACTLY what you need to do...

Lol, I din't noticed...

Fixed! Thanks!

Posted
  On 4/6/2015 at 1:54 AM, Lua said:

Is there a way to check that no background music is already playing first before I play mine?

Yes, there is:

1. In your Event use this:

Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(ISound)

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.