Posted November 21, 201311 yr 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) { } }
November 21, 201311 yr Do you want it to play the sound when it gets a redstone signal? When it is placed? All the time never stopping, or what? Specifics be needed.
November 21, 201311 yr Author I'd like to do, if I put down a block, the sound does repeat itself constantly.
November 21, 201311 yr 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
November 22, 201311 yr In Block#updateTick(World,...) use World#playSound(String,...) then World#scheduleBlockUpdate(...) try to set the delay to something close to the sound length in ticks.
November 22, 201311 yr Author 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)); } }
November 23, 201311 yr Author 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?
November 24, 201311 yr You don't need a TileEntity. But the updateTick needs a first call so then the ticks will be scheduled. For example with Block#onBlockPlacedBy(...)
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.