Posted May 20, 20205 yr 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?
May 20, 20205 yr You need to add a sound handler to the client player. Edited May 20, 20205 yr by ChampionAsh5357 Incorrect interpretation of question.
May 20, 20205 yr Author 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
May 20, 20205 yr 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.
May 20, 20205 yr Author 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
May 20, 20205 yr 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#play, SoundHandler#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.
May 20, 20205 yr Author 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#play, SoundHandler#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
May 20, 20205 yr 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.
May 20, 20205 yr Author 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
May 20, 20205 yr 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.