Jump to content

[1.8] Sound not playing on event (server side)


Samalot

Recommended Posts

Hello, I am having trouble getting a sound to play server side. I have looked all over the internet without avail:

 

@SubscribeEvent
public void testTest(WorldTickEvent event) 
{
	//Word object from event.
	World world = event.world;	
	if(!world.isRemote)
	{
		System.out.println("Server");
		event.world.playSound(0, 0, 0, "random.explode", 10.0F, 1.0F, false);	
	}
}

 

Here are a few points:

  • The console does NOT print any errors, including 'unable to play sound'.
  • I have tried many different sound files, ones which have worked elsewhere.
  • The console does print 'server', so it is entering the if block
  • The event handler is registered properly, the rest of the event works fine, just not the sound.

 

Furthermore, The 'WorldTickEvent' seems to only yield remote worlds, I had a catch for client worlds but it never entered it.

 

@SubscribeEvent
public void testTest(WorldTickEvent event) 
{
	//Word object from event.
	World world = event.world;	
	if(world.isRemote)
	{
		System.out.println("Client");
	}
}

 

Nothing was printed.

 

Thanks in advance,

Sam

Link to comment
Share on other sites

Use TickEvent.WorldTickEvent, unless they broke that out (not an internal subtype) for 1.8

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Unless I misunderstood you, I think they must have broke it out. This is what is inside of TickEvent:

 

public static class WorldTickEvent extends TickEvent {
        public final World world;
        public WorldTickEvent(Side side, Phase phase, World world)
        {
            super(Type.WORLD, side, phase);
            this.world = world;
        }
    }

 

Either way, I tried TickEvent.WorldTickEvent and no dice.

 

I'm paranoid that I am missing something simple. Playing sounds server side is definitely a thing right?...

Link to comment
Share on other sites

Thanks!

 

I knew it was going to be something stupid, I do feel small now. I do check code (spent the whole of yesterday digging through Entity just to find that the parameters I needed use are private and hardcoded...).

 

I try to only post on here as a last resort. I was so convinced it was something to do with Server/Client in my event handler. It didn't even cross my mind that there would be two methods for playing sound..

Link to comment
Share on other sites

Client-Server architecture can take a while to wrap your head around. In general, all sound and light presented to a user is going to be executing on the client side, so you should always be suspicious of any thought crossing your mind that combines something like "play sound" (or "render graphics") with the phrase "server side".

 

In all such cases, look carefully for the threshold between server's decisions and client's rendering, and watch out for similarly named methods on opposite sides. As usual, it pays to walk through a vanilla example doing something like what you're attempting. Sometimes it's even more helpful to step through in the debugger. Note: When using the debugger to analyze client-server interaction, pay particular attention to what thread is hitting each of your breaks, otherwise you'll just confuse yourself more.

 

As it happens, there is the sound-effect method that is designed to be called server side so that sound decisions can be distributed to multiple clients (World Accesses) where they are actually "played" (rendered).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.