Posted May 15, 20205 yr I have made a sound event to play a sound when holding an item. but now i cant figure out how to stop playing the sound when you stop holding the item public class ModSoundEvent { @SubscribeEvent public void SoundEvent(TickEvent.PlayerTickEvent event) { { if (event.player.getHeldItemMainhand().getItem() == ItemList.blue_lightsaber) { event.player.playSound(SoundList.BUZZ, 0.5f, 1.0f); } } how would i make this happen would i add an if statement after and is there something like .stopSound available to use??? thanks in advance
May 17, 20205 yr Author @OnlyIn(Dist.CLIENT) public class ModSoundEvent { @SubscribeEvent public void soundEvent(TickEvent.PlayerTickEvent event){ { if (event.player.getHeldItemMainhand().getItem() == ItemList.blue_lightsaber) { event.player.playSound(SoundList.BUZZ, 0.5f, 1.0f);} else { event.player.playSound(SoundList.HURT,0.5f, 1.0f); } } alright (srry for late didnt code for a few days) i made it only in the client and i figured out kinda what i need to do but i dont know how to stop a sound with TickEvent. is it possible or do i have to redo it (i tried doing it the way MinecrartTickableSound does it and it didnt work. thanks for the tip anyways i figured out some stuff with it)
May 17, 20205 yr Author so i cant use playertickevent then. so i have to re-write it (also @OnlyIn is what they use in vanilla)
May 17, 20205 yr 32 minutes ago, YaBoiChips said: so i cant use playertickevent then. so i have to re-write it (also @OnlyIn is what they use in vanilla) OnlyIn does literally nothing for modders. It's an internal marker for Forge/FML only, so modders shouldn't use it. A TickableSound would probably be ideal for this, as already mentioned. You could use Item#inventoryTick to start the sound by checking the item in the player's hand, kind of like how maps work . I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
May 19, 20205 yr On 5/17/2020 at 7:08 PM, imacatlolol said: OnlyIn does literally nothing for modders. It's an internal marker for Forge/FML only, so modders shouldn't use it. How true is this? Does it do nothing, or are the methods stripped during build/run? I have used it in the past as a marker for methods which I know must only be used on the client. Does this have a functional use or is it safe to use as a marker?
May 19, 20205 yr Author alright so ive converted it to a tickable sound 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; } } } kinda based it on a few things. but it wont play the sound now, do i need to subscribe it or register it?
May 20, 20205 yr 16 hours ago, Alpvax said: How true is this? Does it do nothing, or are the methods stripped during build/run? I have used it in the past as a marker for methods which I know must only be used on the client. Does this have a functional use or is it safe to use as a marker? I'm... not too sure, to be honest. Stripping the methods seems like a viable use case, but the annotation itself doesn't seem to be referenced anywhere (except for annotating things obviously). It's intended to only be used by FML/Forge and the javadocs say for modders not to use it, so I personally advocate against it. As far I'm aware, it's just a marker; FML/Forge merges the client and server and @OnlyIn is used to indicate the differences. So it's probably safe for you to use as a marker yourself, but I'm not sure. I imagine one reason for not using it is because people might misunderstand it and somehow believe that it'll magically make certain code not run on the server/client, when it seemingly does nothing in reality. Probably a good question for Lex or someone else who works on the lower levels of Forge, I'm curious as well. I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
May 22, 20205 yr On 5/20/2020 at 8:13 AM, diesieben07 said: There is no reason to use the marker. It does not save you from accessing client only code. I understand that (I also understand how to use DistExecutor, and use it when I need to call client side methods). My question is is it safe for me to use it as a marker, just something to double check when I'm calling my methods so I know not to call them from the wrong side. Or would javadoc be better? Apologies for somewhat hijacking the thread, I won't reply again.
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.