Jump to content

[1.7.10] [Solved] Unable to play sounds


NomNuggetNom

Recommended Posts

Plain and simple, sounds are not playing. I am trying to use vanilla sounds. Here's an example:

				mc.theWorld.playSoundAtEntity(mc.thePlayer, "random.levelup", 0.75F, 1.0F);

I'm sure it's reaching this code. I copied the "random.levelup" from the EntityPlayerMP class, where the player is leveling up. But I don't hear anything. My mod is client-side only on a vanilla server. Any help is appreciated :D

 

EDIT:

This is the solution:

mc.thePlayer.playSound("random.levelup", 0.75F, 1.0F);

Link to comment
Share on other sites

Can you post the whole method that line is in?

 

It's a very large method, with lots of unrelated bits. What could possibly be affecting it in the method?

 

So, here's proof it's making it there:

			System.out.println("abc123");
			mc.theWorld.playSoundAtEntity(mc.thePlayer, "random.levelup", 0.75F, 1.0F);
			System.out.println("123abc");

 

Which results as

 

abc123
123abc

 

on the console. So, jabelar, no errors or anything :\

Link to comment
Share on other sites

You're wanting people to help but not letting them see the code they need to see to fix it? You could at least show them the method you're using. That way they could test and help. D:<

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Link to comment
Share on other sites

You're wanting people to help but not letting them see the code they need to see to fix it? You could at least show them the method you're using. That way they could test and help. D:<

 

The thing is, the rest of the code is really messy and completely unrelated. I've posted only the relevant code because I didn't want people to be confused :(.

 

But here, I moved it out of where it is, and into a more general spot (still not working):

@SubscribeEvent
public void onChat(ClientChatReceivedEvent event) {
	mc.theWorld.playSoundAtEntity(mc.thePlayer, "random.levelup", 1.0F, 1.0F);

	ChatFilter.handleChat(event);
}

Link to comment
Share on other sites

The thing is, the rest of the code is really messy and completely unrelated. I've posted only the relevant code because I didn't want people to be confused :(.

 

You're misunderstanding. For people to help you you'll need to show the entire class, not just that method.

playSoundAtEntity() works just fine. Its a vanilla method. If it didn't, than there'd be no sound in the vanilla game.

 

In order to see what is happening to cause it to not work, we need to see the rest of the .java file's contents to understand where the problem is.

You can't expect help on something without providing people with the thing you need help on.

Link to comment
Share on other sites

The thing is, the rest of the code is really messy and completely unrelated. I've posted only the relevant code because I didn't want people to be confused :(.

 

You're misunderstanding. For people to help you you'll need to show the entire class, not just that method.

playSoundAtEntity() works just fine. Its a vanilla method. If it didn't, than there'd be no sound in the vanilla game.

 

In order to see what is happening to cause it to not work, we need to see the rest of the .java file's contents to understand where the problem is.

You can't expect help on something without providing people with the thing you need help on.

I understand. I posted the method above.

Link to comment
Share on other sites

I understand. I posted the method above.

You're either trolling, or were dropped on your head as a child.

That is not the entire method. That doesn't even validate as java. Reread my post or read the post above this.

 

Sorry guys, I misunderstood. To make it much easier, I have separated it into it's own class - both to make sure nothing is interfering, and to make it easier to debug.

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientChatReceivedEvent;

public class ChatSound {

public static Minecraft mc = Minecraft.getMinecraft();

@SubscribeEvent
public void onChat(ClientChatReceivedEvent event) {
	System.out.println("About to play a sound.");
	mc.theWorld.playSoundAtEntity(mc.thePlayer, "random.levelup", 1.0F, 1.0F);
	System.out.println("Done playing a sound.");
}
}

 

Every time chat comes in, the lines are being printed, so I know the event is being called.

 

My apologies for the misunderstanding. Thank you guys for trying to help, I really appreciate it. If I am still giving you the wrong things, please tell me - I'm not trying to make it hard for you guys to help :(.

 

Link to comment
Share on other sites

Is the method that you are trying to use it in an Overide of another method? If so which one? and does the class you are trying to use it in extend anything? If you give me these two pieces of information I might be able to help you

 

I am not overriding any other method, and the class is not extending anything.

Link to comment
Share on other sites

If you only want the player to hear the sound and not every player around that player then this works fine:

mc.thePlayer.playSound("random.levelup", 1.0F, 1.0F);

However if you want every player near the player that sent the message to hear the sound this won't work.

 

This is the solution. Thank you very much.

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.