Jump to content

Adding and playing custom sounds


PlatonCraft

Recommended Posts

Hello there! I want to add my custom sound to game and then play it. I have .ogg file (vorbis 2.0 codec) in assets.flintstonetools.sound folder in project.

 

 

[spoiler=My Base of mod]

package platon.mods.flintstonetools;

import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetServerHandler;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod (modid = FlintBase.modid, name = "Flintstone Tools", version = "1.1.1a") 
@NetworkMod (clientSideRequired = true, serverSideRequired = false)

public class FlintBase {
public static final String modid = "flintstonetools";
@Instance(FlintBase.modid)
public static FlintBase instance;
public static Item flintpickaxe;
static int flintpickaxeid;
public static Item flintshovel;
static int flintshovelid;
public static Item flintaxe;
static int flintaxeid;
public static Item flinthoe;
static int flinthoeid;
public static Item flintsword;
static int flintswordid;
@EventHandler
public void reg(FMLPreInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new SoundLoader());
}
@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
config.defaultEncoding="windows-1251";
flintpickaxeid = config.get("Mod IDs", "flintpickaxeid", 650).getInt();
flintshovelid = config.get("Mod IDs", "flintshovelid", 651).getInt();
flintaxeid = config.get("Mod IDs", "flintaxeid", 652).getInt();
flinthoeid = config.get("Mod IDs", "flinthoeid", 653).getInt();
flintswordid = config.get("Mod IDs", "flintswordid", 654).getInt();
SetBlockOnFire.fireableids = config.get("flintstonetools", "fireableids", SetBlockOnFire.deffireableids).getIntList();
config.addCustomCategoryComment("flintstonetools", "Here is the list of IDs of blocks that can be setted on fire by the flint pickaxe.\nThat list can be modified. Just add the Ids you want in column.\n\nЗдесь в столбик указаны ID блоков, которые можно поджигать кремневой киркой.\nВы можете изменять его. Просто добавьте свои ID в колонку с новой строки");
config.save();
}
@EventHandler
public void load(FMLInitializationEvent event)
{
flintpickaxe = new ItemFlintPickAxe(flintpickaxeid).setUnlocalizedName("flintpickaxe");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintpickaxe, 1), new Object[]{ "XXX", " # ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintpickaxe, "en_US", "Flint Pickaxe");
LanguageRegistry.instance().addNameForObject(flintpickaxe, "ru_RU", "Кремневая Кирка");

flintshovel = new ItemFlintShovel(flintshovelid).setUnlocalizedName("flintshovel");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintshovel, 1), new Object[]{ " X ", " # ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintshovel, "en_US", "Flint Shovel");
LanguageRegistry.instance().addNameForObject(flintshovel, "ru_RU", "Кремневая Лопата");

flintaxe = new ItemFlintAxe(flintaxeid).setUnlocalizedName("flintaxe");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintaxe, 1), new Object[]{ " XX", " #X", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintaxe, "en_US", "Flint Axe");
LanguageRegistry.instance().addNameForObject(flintaxe, "ru_RU", "Кремневый Топор");

flinthoe = new ItemFlintHoe(flinthoeid).setUnlocalizedName("flinthoe");
GameRegistry.addRecipe(new ItemStack(FlintBase.flinthoe, 1), new Object[]{ " XX", " # ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flinthoe, "en_US", "Flint Hoe");
LanguageRegistry.instance().addNameForObject(flinthoe, "ru_RU", "Кремневая Мотыга");

flintsword = new ItemFlintSword(flintswordid).setUnlocalizedName("flintsword");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintsword, 1), new Object[]{ " X ", " X ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintsword, "en_US", "Flint Sword");
LanguageRegistry.instance().addNameForObject(flintsword, "ru_RU", "Кремневый Меч");
}
static EnumToolMaterial FLINT = EnumHelper.addToolMaterial("FLINT", 2, 150, 5.0F, 2.0F, 10);
}

 

 

 

[spoiler=SoundLoader]

package platon.mods.flintstonetools;

import net.minecraft.client.audio.SoundManager;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class SoundLoader
{
@ForgeSubscribe
public void onSoundsLoaded(SoundLoadEvent event)
{

event.manager.soundPoolSounds.addSound("flintstonetools/sound/stonestrike.ogg");

}
}

 

 

 

[spoiler=My item i want to play this sound]

package platon.mods.flintstonetools;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.Property;

import java.util.Random;

public class ItemFlintPickAxe extends ItemPickaxe{

public ItemFlintPickAxe(int par1)
{
super(par1,FlintBase.FLINT);
	this.setCreativeTab(CreativeTabs.tabTools);
}
@Override
public void registerIcons(IconRegister reg){
this.itemIcon = reg.registerIcon("flintstonetools:ItemFlintPickAxe");
}

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{

par3World.playSoundAtEntity(par2EntityPlayer, "flintstonetools.sound.stonestrike", 1.0F, 1.0F);
return true;

}
}

 

 

 

Please help me!!! What should i do to make it work??? Minecraft 1.6.2 Forge 804

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I already tried this and its wasnt work but now i guessed that this is eclipse's problem i compiled my code and put it to minecraft mods folder and all get work but now in eclipse it doesn't works anyway.

When i use my tool, all sounds are disappearing and minecraft writes the error code:

2013-08-18 22:00:04 [iNFO] [sTDERR] Exception in thread "Thread-15" java.lang.NullPointerException
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.readHeader(CodecJOrbis.java:448)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:301)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.CommandThread.run(CommandThread.java:121)

 

In what package in eclipe my sound must to be?

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

maybe common package?

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

There are tutorials on this, if you have trouble finding them you could try my website (self promoting, I know :P ):

mazetar.com/mctuts/displayTutorials.php

 

For sounds I wrote a tutorial which may aid you:

www.minecraftforum.net/topic/1886370-forge16x-mazs-tutorials-working-custom-sounds-w-random-sound-from-soundpool-190713/

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I already get mod works but not in eclipse. Where must assets/modname/sound directory must to be in eclipse, say please. I would be glad to some screenshot.

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I just copied all i need to the src folder which in the mcp's home (where is files recomp and reobf). And it doesn't works and gives me an error described upper

hsWn6OW.png

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I already tried this and its wasnt work but now i guessed that this is eclipse's problem i compiled my code and put it to minecraft mods folder and all get work but now in eclipse it doesn't works anyway.

When i use my tool, all sounds are disappearing and minecraft writes the error code:

2013-08-18 22:00:04 [iNFO] [sTDERR] Exception in thread "Thread-15" java.lang.NullPointerException
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.readHeader(CodecJOrbis.java:448)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:301)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.CommandThread.run(CommandThread.java:121)

 

In what package in eclipe my sound must to be?

Looks like a codec error.

Can you try with a .wav file ?

Link to comment
Share on other sites

If you mean code - yes, all the code here, too. in mcp/src/minecraft

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

@Gotolink

Just another error, and as I said if i compiling mod and put it to minecraft mods folder, all works

 

2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'CodecWav'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Error setting up audio input stream in method 'initialize'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     ERROR MESSAGE:
2013-08-18 23:24:30 [iNFO] [sTDOUT]         Stream closed
2013-08-18 23:24:30 [iNFO] [sTDOUT]     STACK TRACE:
2013-08-18 23:24:30 [iNFO] [sTDOUT]         java.io.BufferedInputStream.getInIfOpen(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         java.io.BufferedInputStream.fill(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         java.io.BufferedInputStream.read(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.RIFFReader.read(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.RIFFReader.<init>(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.WaveFloatFileReader.internal_getAudioFileFormat(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.WaveFloatFileReader.getAudioFileFormat(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.WaveFloatFileReader.getAudioInputStream(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.codecs.CodecWav.initialize(CodecWav.java:128)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.CommandThread.run(CommandThread.java:121)
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'CodecWav'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Audio input stream null in method 'readAll'
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Sound buffer null in method 'loadSound'
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Source 'sound_29' was not created because an error occurred while loading flintstonetools:stonestrike.wav
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Source 'sound_29' not found in method 'play'

 

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

In a sence? I just copied this sound to src. I tried to create package and folder named assets.flintstonetools.sound but the result is same - error

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

YEAH!!! I fixed it. I put the sound in mcp/eclipse folder.

My sound is very bad. I need the sound of flint scratching stone. Can anyone help me with that?

at least give me a link to site with different sounds.

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

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.