Jump to content

[1.6.4] Adding sounds


BrighamX

Recommended Posts

OK. making a mod and this is the first mod that I've tried to complete. I've been referencing the source code for all of the support I've needed up until this point. I just can't for the life of me figure out how to add sounds to the mod. If you could link me to a YouTube video (because I've failed at looking there) that would be great.

Link to comment
Share on other sites

Hi

 

Sorry no You-Tube, but some code:

 

public class CustomSoundsHandler

{

  @ForgeSubscribe

  public void onSound(SoundLoadEvent event)

  {

    event.manager.addSound("speedytools:wandplace.ogg");

    event.manager.addSound("speedytools:wandunplace.ogg");

    event.manager.addSound("speedytools:orbplace.ogg");

    event.manager.addSound("speedytools:orbunplace.ogg");

    event.manager.addSound("speedytools:sceptreunplace.ogg");

    event.manager.addSound("speedytools:sceptreplace.ogg");

  }

}

 

In commonproxy.postInit:

    MinecraftForge.EVENT_BUS.register(new CustomSoundsHandler());

 

When you want to play the sound:

      Minecraft.getMinecraft().sndManager.playSound("speedytools:sceptreplace.ogg",

              (float) (thePlayer.posX),

              (float) (thePlayer.posY),

              (float) (thePlayer.posZ),

              1.0F, 1.0F);

 

That's it....

 

-TGG

Link to comment
Share on other sites

Indeed, I highly recommend NOT to ever use Minecraft.getMinecraft(). The way to play sounds is either through the World object, or with the EntityPlayer#playSound. When using world.playSoundAtEntity, for example, you must do so on the server side and it will play a sound for all to hear; using player.playSound, however, will only play a sound for that player and must be used on the client side - it will not crash on the server, but it won't play a sound, either.

 

EDIT: Actually, it looks like EntityPlayer.playSound plays a sound for everyone else, but not for the player... I could swear I've used it before and had it play sounds for me, but maybe not. Anyway, use the World methods :P

Link to comment
Share on other sites

Hi

 

You've got a good point about playing sounds through World if you want other players to hear them.  In my case I didn't, but I agree that's not clear from my post.

 

The point of my post was to show the SoundLoadEvent which is very different to how forge registers just about everything else.  Took me quite some time to find it myself because based on the name I assumed it was an event triggered by the loading of each sound, not an event you need to hook into to register your sounds at the right time.  Once you're aware of that key difference it's easy to fill in the blanks.  I never managed to get sounds to work properly until I did it this way and it took nearly a day of stuffing around to get there.

 

-TGG

 

 

Link to comment
Share on other sites

If you don't understand what the f*ck we are talking about then that means you are not ready for coding.

 

What coolAlias is saying that Minecraft.getMinecraft() is run client-side.

There are two sides (client-side and server-side).

Client-side is like player mangement (I guess), server-side is world management.

 

He is saying that if you use Minecraft.getMinecraft() then only the (one) PLAYER (client-side) will hear it.

But if you use a method that is run on the server-side it will play it for all players.

 

Got it? Good. ;c

Link to comment
Share on other sites

If you don't understand what the f*ck we are talking about then that means you are not ready for coding.

 

What coolAlias is saying that Minecraft.getMinecraft() is run client-side.

There are two sides (client-side and server-side).

Client-side is like player mangement (I guess), server-side is world management.

 

He is saying that if you use Minecraft.getMinecraft() then only the (one) PLAYER (client-side) will hear it.

But if you use a method that is run on the server-side it will play it for all players.

 

Got it? Good. ;c

 

Calm down. I understood what they are saying, but it just doesn't give me a clear idea of what I should be doing. I already know what server-side/client-side is.

Link to comment
Share on other sites

I still have no idea where to start from

 

As TGG mentioned, you need to subscribe to the SoundLoadEvent to add your custom sounds to the sound manager. Sounds are loaded only on the client side, so make sure you register the event in your client proxy so you don't crash on the server with class not found exception.

 

If you don't know how to use / register events, TGG gave you the code already, or you could look up Forge Events on the wiki or Minecraft Forums.

 

Create an .ogg file for your sound (preferably not too long) and place it in your assets/modid/sound/ directory. Follow previous advice to play it.

 

If that doesn't help you figure out to start, then I recommend starting with Java :P

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.