Jump to content

Recommended Posts

Posted

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?

Posted
17 minutes ago, ChampionAsh5357 said:

You need to add a sound handler to the client player.

ya uhhhhhhhh can u link me to something that uses that im not 100% sure on how they work

Posted

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.

Posted

i want to play a sound when i hold an item (specificaly a lightsaber and have it buzz) i got that to work before but the sound wouldnt stop so im trying a different method

Posted

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.

Posted
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 :)

Posted

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.

Posted
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

Posted

First, don't use @OnlyIn. Second, you just pretty much copied the classes without viewing your situation. You already had the tickable sound done. You just need to play, check if playing, and stop it from the SoundHandler in a player tick event.

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.