Jump to content

Music in My Dimension


Thor597

Recommended Posts

Subscribe to the PlayBackgroundMusicEvent and then check if the player is in your dimension. If so, return a different SoundPoolEntry. That's how I'd do it.

To have the music in your Mod-Zip file, you can use a custom URLStreamHandler which makes the SoundPoolEntry accept the InputStreams from your zip. Ask if you wan't help with that.

 

Yes I would want some more help with that stuff. Someone should make a page on the tutorials page on how to add background music to dimensions and just music in general and also in the same tutorial how to add sounds(I used the system with ISoundHandler before but now that its gone I need to do the events things)

 

so yeah, a tutorial called: How to add new Audio(Sounds and Music) should be in the tutorials section! :D

Link to comment
Share on other sites

You are aware of the fact that Class.getResource() (Not as stream) returns an URL you could pass to new SoundPoolEntry?

Like:

public class SoundHandler {
    @ForgeSubscribe
    public void onSound(SoundLoadEvent event) {
        try {
            event.manager.soundPoolSounds.addSound("your/sound.ogg", CameraCraft.class.getResource("/path/to/your/sound.ogg"));
        } catch (Exception e) {
            System.err.println("Failed to register one or more sounds.");
        }
    }
}

This avoids writing a hacked urlstreamhandler and will work no matter where in your classpath the sound file is.

Link to comment
Share on other sites

I have a problem.

 

I want my mob to do this sound but im not getting anything, heres my code

 

package net.minecraft.src;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class ThorMod_SoundHandler
{
@ForgeSubscribe
 @SideOnly(Side.CLIENT)
public void onSound(SoundLoadEvent event)
{
	try
	{
		event.manager.soundPoolSounds.addSound("monkey1", mod_TheThorMod.class.getResource("/Sounds/monkey1"));
		event.manager.soundPoolSounds.addSound("monkey2", mod_TheThorMod.class.getResource("/Sounds/monkey2"));
		event.manager.soundPoolSounds.addSound("monkey3", mod_TheThorMod.class.getResource("/Sounds/monkey3"));
	} 

	catch (Exception e)
	{
		System.err.println("Failed to register one or more sounds.");
	}
}
}

 

And in my entity class I have this

protected String getLivingSound()
    {
        return "monkey";
    }

Link to comment
Share on other sites

Okay, I tried that now for myself and my sound won't register anywhere. In fact, the onSound method doesn't get even called (I've put a println in the method to test if it gets called). Did I do something wrong?

 

My SoundHandler:

 

public class PD_SoundHandler {	
@ForgeSubscribe
public void onSound(SoundLoadEvent event) {
	System.out.println("sound!");
        try {
            event.manager.soundPoolSounds.addSound("particledeco/static.ogg", PD_ModRegistry.class.getResource("/sound/static.wav"));
        } catch (Exception e) {
            System.err.println("Failed to register one or more sounds.");
        }
    }

 

 

The event bus will be registered in my ClientProxy like this:

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

 

how I want to call my sound (in my entity):

PD_ModRegistry.proxy.getClientWorld().playSoundAtEntity(this, "particledeco.static", 1f, 1f);

 

 

PS: It seems that Thor597 above me has the same problem :P

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Okay, tyvm, but I have still the problem that the sound isn't played.

 

The sound is registered and the file will be found, but the entity won't play it :/

 

EDIT: Nvm, I'm using the worldObj field from my entity instead the ClientWorld from my proxy and it works now ^.^

EDIT2: It seems you have to use the server world for the entity, because it doesn't work with the client one...

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

So if i want music in my dimension i put this in my soundhandler

 

@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void onSound(SoundLoadEvent event)
{
	try
	{
		if(this.world.provider.worldType == 23)
		{
			event.manager.soundPoolMusic.addSound("thormod/netromWood2.wav", mod_TheThorMod.class.getResource("/Sounds/netromWood2.wav"));
		}
	} 

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.