Jump to content

Sound play problem.


naburus

Recommended Posts

I want to add a sound to a block. How can I do it? I'd like to add a machine to minecraft and that should repeat the sound of itself.

I can't play the sound.

 

TestOre.java

package naburus.mod.bc_sounds;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockOre;
import net.minecraft.block.StepSound;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.block.material.Material;
import net.minecraftforge.client.event.sound.PlaySoundEffectEvent;
public class TestOre extends Block{
public TestOre(int id, Material material) {
     super(id, material);        
         setHardness(2.0F);
         setStepSound(Block.soundLadderFootstep);
         setUnlocalizedName("testOre");
         setCreativeTab(CreativeTabs.tabBlock);        
         // How can I play my sound? <------------------------------------------------
}

}

 

Test.java

package naburus.mod.bc_sounds;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;
public class Test {
@ForgeSubscribe
public void onSound(SoundLoadEvent event) {
     event.manager.addSound("bc_sounds:death.ogg");
}

}

 

Main.java

package naburus.mod.bc_sounds;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
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;
import naburus.mod.bc_sounds.TestOre;
@Mod(modid = "bc_sounds", name = "Build Craft Sounds", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Main {

// --> DEL
public static Block TestOre_;
// <-- DEL

@Instance(value = "bc_sounds")
public static Main instance;

@SidedProxy(clientSide="naburus.mod.bc_sounds.client.ClientProxy", serverSide="naburus.mod.bc_sounds.CommonProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
     TestOre_ = new TestOre(501, Material.rock);
}

@EventHandler
public void load(FMLInitializationEvent event) {
     // --> DEL
     LanguageRegistry.addName(TestOre_, "Test Ore");
     MinecraftForge.setBlockHarvestLevel(TestOre_, "pickaxe", 3);
     GameRegistry.registerBlock(TestOre_, "testOre");
     // <-- DEL    
    
     proxy.registerRenderers();
}

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
}

Link to comment
Share on other sites

Hmm... Try using the "onBlockPlaced" method. Then in that do a for statement for as long as x > 0 play a sound, and then constantly add to x. Not the best method ever. But it is what I can think of off the top of my head without having tried to do this before. To actually play the sound, use this statement inside the for statement: par2World.playSound

 

 

Link to comment
Share on other sites

Could you explain to me why this code is not working properly?

 

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockOre;
import net.minecraft.block.StepSound;
import net.minecraft.client.audio.SoundManager;
import net.minecraft.client.audio.SoundPoolEntry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.world.World;
import net.minecraft.block.material.Material;
import net.minecraftforge.client.event.sound.PlaySoundEffectEvent;

public class TestOre extends Block{

    public TestOre(int id, Material material) {
    	super(id, material);           
        setHardness(2.0F);
        setStepSound(Block.soundLadderFootstep);
        setUnlocalizedName("testOre");
        setCreativeTab(CreativeTabs.tabBlock);                 
   }  
    
    public void updateTick(World world, int i, int j, int k, Random random) {
    	world.playSound(i, j, k, "liquid.swim", 0.3f, 0.6f, false);
    	world.scheduleBlockUpdate(i, j, k, this.blockID, this.tickRate(world));
    }
}

Link to comment
Share on other sites

So, the main problem is the updateTick is not running down. setStepSound(Block.soundGlassFootstep); if I step above the block it should play the sound of the glass.

public void updateTick(World world, int x, int y, int z, Random random) {
setStepSound(Block.soundGlassFootstep);
world.playSound(x, y, z, "bc_sounds:death.ogg", 0.3f, 0.6f, false);
world.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate(world));
}

So, in my understanding the updateTick at every tick runs down what it contain? Or am I wrong?

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.

Announcements



×
×
  • Create New...

Important Information

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