Posted January 2, 20169 yr I've had a look at this tutorial by jebelar and I think I know how I'd play a sound and stop that sound. But how do I change the volume/pitch of that sound while it is playing? And how do I make the sound loop? Thanks in advance for help catch(Exception e) { } Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).
January 2, 20169 yr Continuous sound requires a custom sound "renderer" on the client (@SideOnly). Extend classContinuousPositionedSound (or moving sound). Inside that class, override the update method to adjust volume, pitch etc based on the blockstate passed into it. Use your client-side sound event handler to instantiate the sound and inject it into the event. Here's the one I did for my blower: @SubscribeEvent public void onPlaySound(PlaySoundEvent e) { ResourceLocation r = e.sound.getSoundLocation (); if (r.equals (classBlockBlower.WHIRRLOC)) { // The resource is my sound, so act upon it WorldClient wc = Minecraft.getMinecraft ().theWorld; PositionedSound ps = (PositionedSound) e.sound; e.result = new classContinuousPositionedSoundFan (wc, ps); // Substitute with my continuous sound } } The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
January 2, 20169 yr I think you mean a PositionedSound that implements ITickableSound. There is no ContinuousPositionedSound Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 4, 20169 yr That's one of my own classes, but I so cleverly named it like a vanilla class that I forgot it was mine! The key line is in the constructor, "repeat = true;" Here's my code, from my shared package (shared among all of my mods): package jrfshare; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.audio.ITickableSound; import net.minecraft.client.audio.PositionedSound; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.util.BlockPos; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) abstract public class classContinuousPositionedSound extends PositionedSound implements ITickableSound { protected final Block anchor; protected final WorldClient wc; protected final BlockPos pos; protected boolean donePlaying = false; // Remains false until Block is invalid protected classContinuousPositionedSound(WorldClient wc, PositionedSound sound, Block b) { super (sound.getSoundLocation ()); this.wc = wc; pitch = sound.getPitch (); pos = new BlockPos (sound.getXPosF (), sound.getYPosF (), sound.getZPosF ()); xPosF = sound.getXPosF (); // Sound should already be centered yPosF = sound.getYPosF (); zPosF = sound.getZPosF (); repeat = true; anchor = b; } // Update pitch & volume using bs protected abstract void updatePV(IBlockState bs); @Override public void update() { // Called immediately after playing so that off-fan can be silenced if (donePlaying) return; // Nothing to hear here IBlockState bs = wc.getBlockState (pos); // See if my fan block is still there Block b = bs.getBlock (); if (b != anchor) { // Test if b is my anchor block donePlaying = true; return; } this.updatePV (bs); } public boolean isDonePlaying() { return donePlaying; } } The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
January 4, 20169 yr @jeffryfisher May I ask why you call your class classContinuousPositionedSound with class being in the name? Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
January 4, 20169 yr It's an unpopular naming convention to alert me that something is a class and not an instance. It's mainly for those times when a class is used to invoke a static method or data member, because I'm forgetful and might misunderstand otherwise. And yes, with "class" as a prefix, it's obviously not vanilla, because vanilla classes are not named that way. I'm so used to it after so many years that I don't notice it until I read one of those static references. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
January 4, 20169 yr Proper naming convention would slow that MyClass is a class where myClass is an instance. Or better yet, myLocallyIntelligentName so that you don't HAVE to make the distinction, but Classes should always start with a capital letter and instances a lower case letter. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.