Jump to content

My tickable sound wont play


YaBoiChips

Recommended Posts

here is the sound event i made

 

public class SaberSoundEvent extends TickableSound {
    private final ClientPlayerEntity player;

    public SaberSoundEvent(ClientPlayerEntity playerIn){
        super(SoundList.BUZZ, SoundCategory.NEUTRAL);
        this.player = playerIn;
        this.attenuationType = ISound.AttenuationType.NONE;
        this.repeat = true;
        this.repeatDelay = 0;
        this.volume = 0.1F;
    }


    public void tick() {
        if (this.player.getHeldItemMainhand().getItem() == ItemList.blue_lightsaber) {
            this.x = (float) this.player.getPosX();
            this.y = (float) this.player.getPosY();
            this.z = (float) this.player.getPosZ();
            this.volume = 0.0F + 1.0F;
            this.pitch = 0.7F + 0.5F;
        }
        else { this.donePlaying = true;
        }
    }
}

what have i done wrong do i have to override or subscribe the event?

Link to comment
Share on other sites

Well let me ask a better question. What specifically do you want to use this sound for? If its just a simple request on another entity then using Minecraft#getSoundHandler and playing the sound through there would work. If its for ambiance, you need to access and write to ClientPlayerEntity#ambientSoundHandlers.

Link to comment
Share on other sites

Ah okay. So there are multiple ways to do this. One way is to call it using SoundHandler#play but you should store the current instance of the sound playing in a variable. Then using a combination of SoundHandler#playSoundHandler#isPlaying, and SoundHandler#stop you can manage the sound looping in some sort of tick event I would say. Another way would be attaching it through an ambient sound handler.

Link to comment
Share on other sites

36 minutes ago, ChampionAsh5357 said:

Ah okay. So there are multiple ways to do this. One way is to call it using SoundHandler#play but you should store the current instance of the sound playing in a variable. Then using a combination of SoundHandler#playSoundHandler#isPlaying, and SoundHandler#stop you can manage the sound looping in some sort of tick event I would say. Another way would be attaching it through an ambient sound handler.

i have no idea how to use SoundHandler. can u send me an example? i cant find one online. thanks for all ur help so far :)

Link to comment
Share on other sites

I don't really have an example. The most I could do is give you classes that use it such as UnderwaterAmbientSoundHandler or BeeSound. You can get an instance of the SoundHandler from Minecraft#getSoundHandler. Then using a player tick event, play the sound if it isn't already playing and item is held. If the sound is already playing, do nothing. Finally, if the item is not held, stop the sound using the methods above. I hope this description can show you some usage of the classes.

Link to comment
Share on other sites

1 hour ago, ChampionAsh5357 said:

I don't really have an example. The most I could do is give you classes that use it such as UnderwaterAmbientSoundHandler or BeeSound. You can get an instance of the SoundHandler from Minecraft#getSoundHandler. Then using a player tick event, play the sound if it isn't already playing and item is held. If the sound is already playing, do nothing. Finally, if the item is not held, stop the sound using the methods above. I hope this description can show you some usage of the classes.

alright here's what i got

 

Sound: https://pastebin.com/mYrzU3vn

SoundHandler: https://pastebin.com/g3QxTusJ

 

still isnt working. what do i need to change i dont see anything that i did 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.



×
×
  • Create New...

Important Information

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