Jump to content

Recommended Posts

Posted

So i want to play various sounds in my mod. For that I'm checking for the server side and call the world.playSound() method. When playing in a singleplayer world everything works and the sounds are playing but on a dedicated server the sounds are never playing.

That's how i play the sounds:

		if (!worldIn.isRemote) {
			worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundHelper.SEAMOTH_EXIT, SoundCategory.NEUTRAL, 0.6F, 1.0F);
		}

Shouldn't this method play the sound for all nearby players except the passed player?

Thanks for the help in advance.

Posted
6 hours ago, diesieben07 said:

Yes, it should. Show more of your code.

Ok i'm playing a sound at 3 locations in my code:

In my item class:

	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
		if (!worldIn.isRemote) {
			System.out.println("play sound");
			worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundHelper.SEAMOTH_EXIT, SoundCategory.NEUTRAL, 0.6F, 1.0F);
		}
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
	}

 

In my entity class:

	@Override
	public boolean processInitialInteract(EntityPlayer player, EnumHand hand) {
		if (!this.world.isRemote) {
			System.out.println("play sound");
			this.world.playSound(null, this.posX, this.posY, this.posZ, SoundHelper.SEAMOTH_ENTER, SoundCategory.NEUTRAL, 0.6F, 1.0F);
		}
		return true;
	}

 

In my event handler class:

@EventBusSubscriber
public class SeamothEventHandler {
	
	@SubscribeEvent
	public static void exit(EntityMountEvent event) {
		if (!event.getWorldObj().isRemote && event.isDismounting()
				&& event.getEntityMounting() instanceof EntityPlayer && event.getEntityBeingMounted() instanceof EntitySeamoth) {
			System.out.println("play sound");
			Entity e = event.getEntityBeingMounted();
			event.getWorldObj().playSound(null, e.posX, e.posY, e.posZ, SoundHelper.SEAMOTH_EXIT, SoundCategory.NEUTRAL, 0.6F, 1.0F);
		}
	}
	
}

 

Here i'm collecting my sound events:

public class SoundHelper {
	
	public static final SoundEvent SEAMOTH_ENTER = new SoundEvent(new ResourceLocation(BetterDiving.MOD_ID, "seamoth_enter"));
	public static final SoundEvent SEAMOTH_EXIT = new SoundEvent(new ResourceLocation(BetterDiving.MOD_ID, "seamoth_exit"));
  	
}

 

In Singleplayer the sound is playing all 3 times. But on a dedicated server i just see the "play sound" in the log.

Also i found this error in the client log when playing on a dedicated server:

[16:21:55] [Client thread/FATAL] [net.minecraft.client.Minecraft]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_201]
	at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_201]
	at net.minecraft.util.Util.func_181617_a(SourceFile:47) [h.class:?]
	at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1088) [bib.class:?]
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:398) [bib.class:?]
	at net.minecraft.client.main.Main.main(SourceFile:123) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_201]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_201]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_201]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
Caused by: java.lang.NullPointerException
	at net.minecraft.client.audio.PositionedSoundRecord.<init>(SourceFile:34) ~[cgp.class:?]
	at net.minecraft.client.audio.PositionedSoundRecord.<init>(SourceFile:30) ~[cgp.class:?]
	at net.minecraft.client.multiplayer.WorldClient.func_184134_a(WorldClient.java:468) ~[bsb.class:?]
	at net.minecraft.client.multiplayer.WorldClient.func_184148_a(WorldClient.java:456) ~[bsb.class:?]
	at net.minecraft.client.network.NetHandlerPlayClient.func_184327_a(NetHandlerPlayClient.java:1674) ~[brz.class:?]
	at net.minecraft.network.play.server.SPacketSoundEffect.func_148833_a(SourceFile:89) ~[kq.class:?]
	at net.minecraft.network.play.server.SPacketSoundEffect.func_148833_a(SourceFile:11) ~[kq.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[hv$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_201]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_201]
	at net.minecraft.util.Util.func_181617_a(SourceFile:46) ~[h.class:?]
	... 9 more

 

Posted
29 minutes ago, diesieben07 said:

Registry entries must be created in a forge-controlled event, not a static initializer. The most common place to do this would be RegistryEvent.Register.

Also show where you register your SoundEvent instances.

Well i haven't registered my sound events. That may be the reason.

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.