Guys for the ones with the same problem as me, I have the solution!
it's because eclipse doesn't reload the sounds automatically, try when u go ingame through eclipse and press f3+S at the same time, this makes eclipse reload the resources folder.
Hope this helped
That was your problem? It depends on how you put your sounds in. If you drag them in eclipse then it knows that it's there and does't need to refresh, But if you drag a new sound in the folder without eclipse, then you have to refresh the project as eclipse doesn't know there are new file changes. Hope that helps too.
Also Krayziee and other having a similar problem, you can check if File exists too.
File file = new File("resources/newsound/yoursound.ogg");
System.out.println(file.exists());
That will print out a boolean in the console whether it exist.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
I put my .ogg files in .minecraft/resources/newsound/mob/
I start minecraft.exe and the monsters make no sound at all right now..
Did you try to see if the File exists? If you are developing your mod why are you running minecraft.exe? Shouldn't you be doing everything from MCP. You are using eclipse right, so are you pressing run from there or using the MCP files to compile and run your mod?
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
The files exist, I am developing a mod which i release in another thread. All files are in place, in mcp they work fine but when i try to actually use it ingame running minecraft.exe they don't work.
I presume this guide isn't only working from eclipse/MCP?
This guide works for all, it just tells you how to play sounds. If it works in mcp but not from ./minecraft then there has to be something wrong with the files. What I would do is check the files cause I don't think minecraft crashes if the file isn't found. I could be wrong but I haven't been in the minecraft scene for a while lol.
File file = new File("resources/.....");
System.out.println(String.format("File: %s Exists: %b", file.getAbsolutePath(),file.exists()));
Of course you would have to run Minecraft.exe from command prompt so you can see the print line statements. If they do exist and still not playing then I don't know.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Can anyone tell me how to make them autoload?
I have to constantly press S+f3 when new monsters spawn or I go ingame.
So if anyone got it to work without the S+f3 i would love to hear it:)
and ofcourse locknload thank you for your tutorial
What do you mean by auto load? You would load all your sounds in the BaseMod-> load method, then once they are loaded you just play them. If you keep on loading/installing the sounds it will take time, depending on the size. Sorry, could you explain it a little more. S+F3? That loads the sounds? If you are spawning new mobs then the sound should already be installed and you can just play them.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
When using this method in GuiMainMenu, I get this error:
C:\Users\Cirno\Desktop\MCP\jars\.\resources\newsound\cirno\title.ogg (The system cannot find the path specified)
What I'm trying to do
mc.installResource("newsound/random/title.ogg", new File(mc.mcDataDir,"resources/newsound/cirno/title.ogg"));
mc.sndManager.playSoundFX("random.title", 1.0F, 1.0F);
Rollback Post to RevisionRollBack
I get kicked for hacking the Guest Rank, trololol.
First, thanks for the tutorial, I was looking for a way to add custom sounds for some new mobs I was making for a mod. I went over your tutorial and after fighting with the code for a while I finally worked out all of the obvious errors that eclipse was showing me. I thought it was all finally worked out and I tried to launch minecraft but it crashed as soon as it tried to load the sound java. I'm kinda new to modding. My code and the errors are below.
package net.minecraft.src;
import java.io.File;
import java.util.Random;
import net.minecraft.client.Minecraft;
public void load()
{
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("newsound/Reaper/Redzombie", new File(mc.mcDataDir,"resources/newsound/Reaper/Redzombie.ogg"));
}
@Override
public String getVersion(){
return "1.0";
}
}
-And the minecraft errors-
Exception in thread "Minecraft main thread" java.lang.ExceptionInInitializerError
at net.minecraft.client.Minecraft.startGame(Minecraft.java:424)
at net.minecraft.client.Minecraft.run(Minecraft.java:786)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at net.minecraft.src.ModLoader.init(ModLoader.java:891)
at net.minecraft.src.ModLoader.addAllRenderers(ModLoader.java:157)
at net.minecraft.src.RenderManager.<init>(RenderManager.java:85)
at net.minecraft.src.RenderManager.<clinit>(RenderManager.java:12)
... 3 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at net.minecraft.src.SoundPool.addSound(SoundPool.java:45)
at net.minecraft.src.SoundManager.addSound(SoundManager.java:135)
at net.minecraft.client.Minecraft.installResource(Minecraft.java:2296)
at net.minecraft.src.mod_sounds.load(mod_sounds.java:13)
at net.minecraft.src.ModLoader.init(ModLoader.java:856)
... 6 more
EDIT: Figured it out, simple mistake, forgot to put .ogg at the end of the first installresource. It works now and plays the sound, thanks for the tutorial!
package net.minecraft.src;
import java.util.Random;
import net.minecraft.client.Minecraft;
import java.io.File;
public class mod_Sound extends BaseMod
{
public static final Block SoundBlock = (new Block(161, 0,Material.ground)).setLightOpacity(4).setResistance(4F).setLightValue(1F).setHardness(3F).setBlockName("Speed Booster");
public void load()
{
SoundBlock.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/sbtexture/SoundBlock.png");
ModLoader.registerBlock(SoundBlock);
ModLoader.addName(SoundBlock, "Sound Block");
ModLoader.addRecipe(new ItemStack(SoundBlock, 1), new Object [] {"###","#@#","###", Character.valueOf('#'), Block.stone, Character.valueOf('@'), Item.diamond});
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("newsound/RedHott/ScarTissue.ogg", new File(mc.mcDataDir,"resources/newsound/RedHott/ScarTissue.ogg"));
}
public String getVersion()
{
return "1.2.5";
}
}
BlockSound
package net.minecraft.src;
import java.util.Random;
import net.minecraft.client.Minecraft;
public class SoundBlock extends Block
{
public SoundBlock(int i, int j)
{
super(i , j, Material.ground);
}
Minecraft mc = ModLoader.getMinecraftInstance();
public void load()
{
mc.sndManager.playSoundFX("resources.newsound.RedHott.ScarTissue", 1.0F, 1.0F);
}
};
Please post the error. BTW, as far as I know, the load() method won't work in a block class because it is a method from BaseMod, of which a block class doesn't extend.
Rollback Post to RevisionRollBack
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
package net.minecraft.src;
import java.util.Random;
import net.minecraft.client.Minecraft;
import java.io.File;
public class mod_Sound extends BaseMod
{
public static final Block SoundBlock = (new Block(161, 0,Material.ground)).setLightOpacity(4).setResistance(4F).setLightValue(1F).setHardness(3F).setBlockName("Speed Booster");
public void load()
{
SoundBlock.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/sbtexture/SoundBlock.png");
ModLoader.registerBlock(SoundBlock);
ModLoader.addName(SoundBlock, "Sound Block");
ModLoader.addRecipe(new ItemStack(SoundBlock, 1), new Object [] {"###","#@#","###", Character.valueOf('#'), Block.stone, Character.valueOf('@'), Item.diamond});
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("newsound/RedHott/ScarTissue.ogg", new File(mc.mcDataDir,"resources/newsound/RedHott/ScarTissue.ogg"));
}
public String getVersion()
{
return "1.2.5";
}
}
in soundBlock:
package net.minecraft.src;
import java.util.Random;
import net.minecraft.client.Minecraft;
public class SoundBlock extends Block
{
public SoundBlock(int i, int j)
{
super(i , j, Material.ground);
}
Minecraft mc = ModLoader.getMinecraftInstance();
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
mc.sndManager.playSoundFX("resources.newsound.RedHott.ScarTissue", 1.0F, 1.0F);
return true;
}
};
// installs the resource
mc.installResource("newsound/random/type_key.ogg", new File(mc.mcDataDir,"resources/newsound/random/type_key.ogg"));
// plays the sound
mc.sndManager.playSoundFX("random.type_key", 1.0F, 1.0F);
package net.minecraft.src;
import java.util.Random;
import java.io.File;
import net.minecraft.client.Minecraft;
import java.util.Map;
public class mod_Aliens extends BaseMod
{
public String getVersion()
{
return "MC 1.2.5";
}
public void load()
{
//Spawn Entities
ModLoader.addSpawn(net.minecraft.src.EntityMartian.class, 20, 20, 20, EnumCreatureType.creature);
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("/newsound/mod/aliens/sound/mobs/martian.ogg", new File(mc.mcDataDir,"/resources/newsound/mod/aliens/sound/mobs/martian.ogg"));
}
Entity File
package net.minecraft.src;
import java.util.Random;
public class EntityMartian extends EntityMob
{
public EntityMartian(World par1World)
{
super(par1World);
texture = "/Aliens/Mobs/Martian.png";
moveSpeed = 0.30F;
attackStrength = 10;
getNavigator().setBreakDoors(true);
tasks.addTask(0, new EntityAISwimming(this));
tasks.addTask(1, new EntityAIAttackOnCollide(this, net.minecraft.src.EntityPlayer.class, moveSpeed, false));
tasks.addTask(2, new EntityAIAttackOnCollide(this, net.minecraft.src.EntityVillager.class, moveSpeed, true));
tasks.addTask(3, new EntityAIMoveTwardsRestriction(this, moveSpeed));
tasks.addTask(4, new EntityAIMoveThroughVillage(this, moveSpeed, false));
tasks.addTask(5, new EntityAIWander(this, moveSpeed));
tasks.addTask(6, new EntityAIWatchClosest(this, net.minecraft.src.EntityPlayer.class, 8F));
tasks.addTask(6, new EntityAILookIdle(this));
targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, net.minecraft.src.EntityPlayer.class, 16F, 0, true));
targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, net.minecraft.src.EntityVillager.class, 16F, 0, false));
}
public int getMaxHealth()
{
return 100;
}
/**
* Returns the current armor value as determined by a call to InventoryPlayer.getTotalArmorValue
*/
public int getTotalArmorValue()
{
return 10;
}
/**
* Returns true if the newer Entity AI code should be run
*/
protected boolean isAIEnabled()
{
return true;
}
/**
* Returns the sound this mob makes while it's alive.
*/
protected String getLivingSound()
{
return "mobs.martian";
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return "mobs.martian";
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return "mobs.martian";
}
/**
* Returns the item ID for the item the mob drops on death.
*/
protected int getDropItemId()
{
return Item.rottenFlesh.shiftedIndex;
}
/**
* Get this Entity's EnumCreatureAttribute
*/
public EnumCreatureAttribute getCreatureAttribute()
{
return EnumCreatureAttribute.UNDEAD;
}
protected void dropRareDrop(int par1)
{
switch (rand.nextInt(4))
{
case 0:
dropItem(Item.swordSteel.shiftedIndex, 1);
break;
case 1:
dropItem(Item.helmetSteel.shiftedIndex, 1);
break;
case 2:
dropItem(Item.ingotIron.shiftedIndex, 1);
break;
case 3:
dropItem(Item.shovelSteel.shiftedIndex, 1);
break;
}
}
}
Hi lockNload147! I've been trying to make sounds play under certain circumstances, not because I need it to my mod, but I want to learn how to do it. Now when I play the game, it doesn't give any errors but the sound just doesn't play. I don't know what I'm doing wrong. and so I thought that you might know something about sounds in Minecraft since you made this (awesome) tutorial! Here's my code, I've made an item which plays a sound when eaten and a key bind which plays a sound when activated.
My mod_File:
package net.minecraft.src;
import java.util.List;
import java.io.File;
import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.ITextureProvider;
public class mod_SimonCraft extends BaseMod
{
Minecraft mc = ModLoader.getMinecraftInstance();
public static final Item itemChoco = new PC_ItemChoco(130).setItemName("choco");
//Keybind to fart
private KeyBinding key_fart = new KeyBinding("Farting Key", 33);
public mod_SimonCraft()
{
ModLoader.addName(itemChoco, "Chocolate");
ModLoader.addRecipe(new ItemStack(itemChoco, 1), new Object[] {
" *", " @%", Character.valueOf('*'), Item.sugar, Character.valueOf('@'), new ItemStack(Item.dyePowder, 1, 3), Character.valueOf('%'), Item.bucketMilk
});
}
public void load()
{
ModLoader.setInGameHook(this, true, false);
ModLoader.registerKey(this, key_fart, false);
ModLoader.addLocalization("key.fart", "Fart");
//Installs the fart sound
mc.installResource("/newsound/simoncraft/fart.ogg", new File(mc.mcDataDir,"/resources/newsound/simoncraft/fart1.ogg"));
mc.installResource("/newsound/simoncraft/fart.ogg", new File(mc.mcDataDir,"/resources/newsound/simoncraft/fart2.ogg"));
mc.installResource("/newsound/simoncraft/fart.ogg", new File(mc.mcDataDir,"/resources/newsound/simoncraft/fart3.ogg"));
}
public boolean fart;
public void KeyboardEvent(KeyBinding event)
{
if (event == key_fart)
{
fart = !fart;
}
}
public boolean onTickInGame(float f, Minecraft minecraft)
{
if (fart)
{
this.mc.sndManager.playSoundFX("simoncraft.fart", 1.0F, 1.0F);
}
return true;
}
public String getVersion()
{
return "v1.2.5";
}
}
My ItemFile:
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.ITextureProvider;
public class PC_ItemChoco extends ItemFood implements ITextureProvider
{
public static final int healAmount = 2;
public static final float healthTime = 0.5F;
public static final boolean eatenByWolf = true;
public PC_ItemChoco (int i)
{
super(i, 2, 0.5F, false);
setIconIndex(0);
maxStackSize = 64;
}
Minecraft mc = ModLoader.getMinecraftInstance();
public ItemStack onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
super.onFoodEaten(par1ItemStack, par2World, par3EntityPlayer);
this.mc.sndManager.playSoundFX("simoncraft.fart", 1.0F, 1.0F);
return par1ItemStack;
}
public String getTextureFile()
{
return "/simon/pctextures.png";
}
}
As you can see, I'm using Forge, hope it doesn't make any difference
camelCase should be used for method names.
keyboardEvent
Rollback Post to RevisionRollBack
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
i cannot get this to work. i have not tried it, but eclipse hates me.
on the line with the mc.installResource in ItemRush8s eclipse brings up these errors:
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on tokens, delete these tokens
- Syntax error on tokens, FormalParameter
expected instead
- Syntax error on token(s), misplaced construct(s)
public class ItemRush8s extends Item
{
public ItemRush8s(int i)
{
super(i);
maxStackSize = 1;
}
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("/streaming/Rush8s.ogg", new File(mc.mcDataDir,"/resources/streaming/Rush8s.ogg"));
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7)
{
if (par3World.getBlockId(par4, par5, par6) == Block.jukebox.blockID && par3World.getBlockMetadata(par4, par5, par6) == 0)
{
if (par3World.isRemote)
{
return true;
}
else
{
((BlockJukeBox)Block.jukebox).insertRecord(par3World, par4, par5, par6, this.shiftedIndex);
par3World.playAuxSFX(1005, par4, par5, par6, this.shiftedIndex);
--par1ItemStack.stackSize;
return true;
}
}
else
{
return false;
}
}
}
Mod_RushMusic.java
package net.minecraft.src;
public class mod_RushMusic extends BaseMod
{
public static final Item Rush8s = new ItemRush8s(5000).setItemName("Rush8s");
Same problem
When you play the sound or use the name for it, don't include the data type. In this case the data type is "newsound"
This is what I mean,
It needs to be
That was your problem? It depends on how you put your sounds in. If you drag them in eclipse then it knows that it's there and does't need to refresh, But if you drag a new sound in the folder without eclipse, then you have to refresh the project as eclipse doesn't know there are new file changes. Hope that helps too.
Also Krayziee and other having a similar problem, you can check if File exists too.
That will print out a boolean in the console whether it exist.
Did you try to see if the File exists? If you are developing your mod why are you running minecraft.exe? Shouldn't you be doing everything from MCP. You are using eclipse right, so are you pressing run from there or using the MCP files to compile and run your mod?
This guide works for all, it just tells you how to play sounds. If it works in mcp but not from ./minecraft then there has to be something wrong with the files. What I would do is check the files cause I don't think minecraft crashes if the file isn't found. I could be wrong but I haven't been in the minecraft scene for a while lol.
Of course you would have to run Minecraft.exe from command prompt so you can see the print line statements. If they do exist and still not playing then I don't know.
amazing!!
Want real chalenge and cool mods? My mods:
Amazing Minecraft Mods
†GnR† Slash - Can one man truly make a difference?
What do you mean by auto load? You would load all your sounds in the BaseMod-> load method, then once they are loaded you just play them. If you keep on loading/installing the sounds it will take time, depending on the size. Sorry, could you explain it a little more. S+F3? That loads the sounds? If you are spawning new mobs then the sound should already be installed and you can just play them.
C:\Users\Cirno\Desktop\MCP\jars\.\resources\newsound\cirno\title.ogg (The system cannot find the path specified)
What I'm trying to do
-And the minecraft errors-
EDIT: Figured it out, simple mistake, forgot to put .ogg at the end of the first installresource. It works now and plays the sound, thanks for the tutorial!
Look:
mod_Sound
BlockSound
Please post the error. BTW, as far as I know, the load() method won't work in a block class because it is a method from BaseMod, of which a block class doesn't extend.
together they are powerful beyond imagination."
in mod_sound:
in soundBlock:
Looks at this example
Then look at your code,
Remove "resources.newsound" when playing your sound. So it should look like this,
mod file
Entity File
Look at the first argument in the install method,
"/newsound/mod/aliens/sound/mobs/martian.ogg"
Just remove newsound and file extension to get the sound name.
It's still not working
mod_Aliens
EntityMartian
camelCase should be used for method names.
together they are powerful beyond imagination."
on the line with the mc.installResource in ItemRush8s eclipse brings up these errors:
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on tokens, delete these tokens
- Syntax error on tokens, FormalParameter
expected instead
- Syntax error on token(s), misplaced construct(s)
here is my files:
ItemRush8s.java
package net.minecraft.src;
import java.io.File;
import net.minecraft.client.Minecraft;
public class ItemRush8s extends Item
{
public ItemRush8s(int i)
{
super(i);
maxStackSize = 1;
}
Minecraft mc = ModLoader.getMinecraftInstance();
mc.installResource("/streaming/Rush8s.ogg", new File(mc.mcDataDir,"/resources/streaming/Rush8s.ogg"));
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7)
{
if (par3World.getBlockId(par4, par5, par6) == Block.jukebox.blockID && par3World.getBlockMetadata(par4, par5, par6) == 0)
{
if (par3World.isRemote)
{
return true;
}
else
{
((BlockJukeBox)Block.jukebox).insertRecord(par3World, par4, par5, par6, this.shiftedIndex);
par3World.playAuxSFX(1005, par4, par5, par6, this.shiftedIndex);
--par1ItemStack.stackSize;
return true;
}
}
else
{
return false;
}
}
}
Mod_RushMusic.java
package net.minecraft.src;
public class mod_RushMusic extends BaseMod
{
public static final Item Rush8s = new ItemRush8s(5000).setItemName("Rush8s");
public void load()
{
Rush8s.iconIndex = ModLoader.addOverride("/gui/items.png", "/terrain/Rush8s.png");
ModLoader.addName(Rush8s, "Moving Pictures");
ModLoader.addRecipe(new ItemStack(Rush8s, 1), new Object [] {"#", Character.valueOf('#'), Block.sand});
}
public String getVersion()
{
return "1.2.5";
}
}