No, im trying to make a sound eminate from a block when certain conditions are met.
I've gotten everything to work so far except for the paramaters of how far, how many repeats, etc. Just more lines of code I need to find I presume.
Oh ok, so you already have the sound playing at the block right. I have been looking at Minecraft's SoundManager and it doesn't look like you can set how far it will travel. Correct me if I'm wrong. But Minecraft uses a 3rd party SoundSystem if you haven't noticed so you could make direct calls from it. http://www.paulscode...x.php?topic=4.0 Look at the playSound method.
/**
* Plays a sound. Args: soundName, x, y, z, volume, pitch
*/
public void playSound(String soundName, float x, float y, float z,
float volume, float pitch) {
if (!loaded || options.soundVolume == 0.0F) { return; }
SoundPoolEntry soundpoolentry = soundPoolSounds
.getRandomSoundFromSoundPool(soundName);
if (soundpoolentry != null && volume > 0.0F) {
latestSoundID = (latestSoundID + 1) % 256;
String s = (new StringBuilder()).append("sound_")
.append(latestSoundID).toString();
float f = 16F;
if (volume > 1.0F) {
f *= volume;
}
sndSystem.newSource(volume > 1.0F, s, soundpoolentry.soundUrl,
soundpoolentry.soundName, false, x, y, z, 2, f);
sndSystem.setPitch(s, pitch);
if (volume > 1.0F) {
volume = 1.0F;
}
sndSystem.setVolume(s, volume * options.soundVolume);
sndSystem.play(s);
}
}[/size][size=small]
When you play a new sound it will make a new Source in the Sound System.
Here is the javadoc for that method which will explain it some more. Java Doc Link
The last parameter is, float distOrRoll - Either the fading distance or rolloff factor, depending on the value of "attmodel". I believe that is what you are looking for. Back in the playSound method it looks like the distance is always set to 16F.
float f = 16F; // The distance variable
if (volume > 1.0F) {
f *= volume;
}
In order to set how far it goes you will have to make your volume greater than 1.0F as you can see there. Then the distance will multiple it by the volume. That's the only way I found on how to change the distance. You will have to figure out how to make the sound repeat though.
If you do want to set the Distance on your sound then it will have to be done with some reflection and more steps.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Thanks for deviating a bit from the previous tutorial to expand a bit here.
Well, in retrospect, I probbally won't need to program that many variables into the program as long as it does fade over time on an X/Y/Z/ plane.
I've been looking into the playSound method with not too much luck. Ive been looking into the documentation here and I have a few questions regarding it.
Should the resource installation method that was working with playSoundFX work with playSound, or will I have to add a new method stated in that documention like addSound?
Also, ive been trying to get the x, y, and z paramaters to work, but with no luck. Can I not use 15F there? If not, what?
I've been looking into the playSound method with not too much luck. Ive been looking into the documentation here and I have a few questions regarding it.
Should the resource installation method that was working with playSoundFX work with playSound, or will I have to add a new method stated in that documention like addSound?
If you install the sound it should work for all methods since playSoundFX and playSound use the same soundPools.
Also, ive been trying to get the x, y, and z paramaters to work, but with no luck. Can I not use 15F there? If not, what?
In your playSound method you have 0.5F for x,y, and z. Shouldn't you put the block coordinate there instead? Everything else looks alright.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Well, those three are variables. Putting a block coordinate that is a constant would defeat the purpose.
Oh. So you don't hear the sound? Since this is at coordinates 5,5,5 you might not hear it unless you are near it. So you could put a higher volume variable too. Also the method playSound will only play it once, it won't loop it.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Right, I never heard the sound. Is there a way to set those paramaters to where the block is placed rather than a central entity?
You can set the sound anywhere in the game with those parameters, mostly. Do you know where the block is placed? If you know where it is then just retrieve the coordinated from it.
Also, I tried resolving to those classes that you sent me with soundsystem and none of them work. I have the imports, but do I need anything more?
SoundSystem(sndSystem) is a private variable inside minecraft's sound manager. So if you want to be able to access it then you will need to use some reflection. If you want to do this I can show you how. What would you want to do with the soundSystem that's different from Minecraft's SoundManager?
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Thanks for the tutorial, it helped a lot But is there any way I could have the sounds limited so only one mob sound plays at a time? I don't want overlapping hurt and living sounds.
Hi, I'd just like to say, awesome thread you have!
I'm having some problems though. I've done everything you told me to do to install the sounds into the resources so then it can be used in MC, but when I set the death tone for a certain custom sound of a mob I'm working on, it doesn't play anything. Would you mind helping me out here? Thanks!
Hi, I'd just like to say, awesome thread you have!
I'm having some problems though. I've done everything you told me to do to install the sounds into the resources so then it can be used in MC, but when I set the death tone for a certain custom sound of a mob I'm working on, it doesn't play anything. Would you mind helping me out here? Thanks!
Sure but I don't know what you did wrong lol. Could you post your code where you install the sound and where you are using it.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
I've posted it on a new .class file in Eclipse because I wasn't too sure where to put all of it, and here is the code:
package net.minecraft.src;
import java.io.File;
import net.minecraft.client.Minecraft;
public class SaxtonSounds {
{
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("newsound/mob/Saxton_lose.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_lose.ogg"));
mc.installResource("newsound/mob/Saxton_win.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_win.ogg"));
mc.installResource("newsound/mob/Saxton_50blockradius.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_50blockradius.ogg"));
mc.installResource("newsound/mob/Saxton_100blockradius.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_100blockradius.ogg"));
mc.installResource("newsound/mob/Saxton_jump1.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_jump1.ogg"));
mc.installResource("newsound/mob/Saxton_20blockradius.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_20blockradius.ogg"));
mc.installResource("newsound/mob/Saxton_lastman.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_lastman.ogg"));
mc.installResource("newsound/mob/Saxton_lastman2.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_lastman2.ogg"));
mc.installResource("newsound/mob/Saxton_jump2.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_jump2.ogg"));
mc.installResource("newsound/mob/Saxton_losemusic.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_losemusic.ogg"));
mc.installResource("newsound/mob/Saxton_rage.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage.ogg"));
mc.installResource("newsound/mob/Saxton_rage2.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage2.ogg"));
mc.installResource("newsound/mob/Saxton_rage3.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage4.ogg"));
mc.installResource("newsound/mob/Saxton_rage4.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage4.ogg"));
mc.installResource("newsound/mob/Saxton_winmusic.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_winmusic.ogg"));
}
}
Did you read about the Same Number Name Exception part in my tutorial? Also can you show me where you call the death sound for your mob? Don't post the whole mob code, just where you call it in the method. You are creating the object SaxtonSounds right?
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Did you read about the Same Number Name Exception part in my tutorial? Also can you show me where you call the death sound for your mob? Don't post the whole mob code, just where you call it in the method. You are creating the object SaxtonSounds right?
Ah I'm not sure how to put it in code tags and I have read the Same Number Name Exception part, but that's not my current problem.
And yeah here is where I call for the sound to occur in my coding:
I've gotten everything to work so far except for the paramaters of how far, how many repeats, etc. Just more lines of code I need to find I presume.
Update:
I've tried using this method with no luck. It could be a different method to install the sound I presume.
playSound
public void playSound(java.lang.String par1Str,
float par2,
float par3,
float par4,
float par5,
float par6) Plays a sound. Args: soundName, x, y, z, volume, pitch
Oh ok, so you already have the sound playing at the block right. I have been looking at Minecraft's SoundManager and it doesn't look like you can set how far it will travel. Correct me if I'm wrong. But Minecraft uses a 3rd party SoundSystem if you haven't noticed so you could make direct calls from it. http://www.paulscode...x.php?topic=4.0 Look at the playSound method.
When you play a new sound it will make a new Source in the Sound System.
Here is the javadoc for that method which will explain it some more.
Java Doc Link
The last parameter is, float distOrRoll - Either the fading distance or rolloff factor, depending on the value of "attmodel". I believe that is what you are looking for. Back in the playSound method it looks like the distance is always set to 16F.
In order to set how far it goes you will have to make your volume greater than 1.0F as you can see there. Then the distance will multiple it by the volume. That's the only way I found on how to change the distance. You will have to figure out how to make the sound repeat though.
If you do want to set the Distance on your sound then it will have to be done with some reflection and more steps.
Well, in retrospect, I probbally won't need to program that many variables into the program as long as it does fade over time on an X/Y/Z/ plane.
I've been looking into the playSound method with not too much luck. Ive been looking into the documentation here and I have a few questions regarding it.
Should the resource installation method that was working with playSoundFX work with playSound, or will I have to add a new method stated in that documention like addSound?
Also, ive been trying to get the x, y, and z paramaters to work, but with no luck. Can I not use 15F there? If not, what?
On a total sidenote, I've found a youtube video explaining this tutorial if you want me to post it. It may help your users.
If you install the sound it should work for all methods since playSoundFX and playSound use the same soundPools.
In your playSound method you have 0.5F for x,y, and z. Shouldn't you put the block coordinate there instead? Everything else looks alright.
Oh. So you don't hear the sound? Since this is at coordinates 5,5,5 you might not hear it unless you are near it. So you could put a higher volume variable too. Also the method playSound will only play it once, it won't loop it.
You can set the sound anywhere in the game with those parameters, mostly. Do you know where the block is placed? If you know where it is then just retrieve the coordinated from it.
SoundSystem(sndSystem) is a private variable inside minecraft's sound manager. So if you want to be able to access it then you will need to use some reflection. If you want to do this I can show you how. What would you want to do with the soundSystem that's different from Minecraft's SoundManager?
Now for just the spiel of fixing the repeating problem.
Thank you,
agg23
I'm having some problems though. I've done everything you told me to do to install the sounds into the resources so then it can be used in MC, but when I set the death tone for a certain custom sound of a mob I'm working on, it doesn't play anything. Would you mind helping me out here? Thanks!
Sure but I don't know what you did wrong lol. Could you post your code where you install the sound and where you are using it.
package net.minecraft.src;
import java.io.File;
import net.minecraft.client.Minecraft;
public class SaxtonSounds {
{
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("newsound/mob/Saxton_lose.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_lose.ogg"));
mc.installResource("newsound/mob/Saxton_win.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_win.ogg"));
mc.installResource("newsound/mob/Saxton_50blockradius.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_50blockradius.ogg"));
mc.installResource("newsound/mob/Saxton_100blockradius.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_100blockradius.ogg"));
mc.installResource("newsound/mob/Saxton_jump1.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_jump1.ogg"));
mc.installResource("newsound/mob/Saxton_20blockradius.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_20blockradius.ogg"));
mc.installResource("newsound/mob/Saxton_lastman.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_lastman.ogg"));
mc.installResource("newsound/mob/Saxton_lastman2.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_lastman2.ogg"));
mc.installResource("newsound/mob/Saxton_jump2.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_jump2.ogg"));
mc.installResource("newsound/mob/Saxton_losemusic.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_losemusic.ogg"));
mc.installResource("newsound/mob/Saxton_rage.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage.ogg"));
mc.installResource("newsound/mob/Saxton_rage2.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage2.ogg"));
mc.installResource("newsound/mob/Saxton_rage3.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage4.ogg"));
mc.installResource("newsound/mob/Saxton_rage4.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_rage4.ogg"));
mc.installResource("newsound/mob/Saxton_winmusic.ogg",
new File(mc.mcDataDir,"resources/mob/random/Saxton_winmusic.ogg"));
}
}
Did you read about the Same Number Name Exception part in my tutorial? Also can you show me where you call the death sound for your mob? Don't post the whole mob code, just where you call it in the method. You are creating the object SaxtonSounds right?
Ah I'm not sure how to put it in code tags and I have read the Same Number Name Exception part, but that's not my current problem.
And yeah here is where I call for the sound to occur in my coding:
protected String getDeathSound()
/* */ {
/* 43 */ return "mob.Saxton_lose";
/* */ }
In the toolbar when editing your posts is a icon that looks like '<>', that's the code block.
It looks good so my guess is you aren't initiating this SaxtonSounds object. I would do it in the load method in your BaseMod class.