Posted May 30, 20232 yr I wanted to make a mod to play a violin while right clicking and stop when not, with the code i have until now i can play it. But now i need to use another function so it stops when you don't right click anymore. The function that i encounter most useful was "onUsingTick", but as i understand know its deprecated and i don't find the replacement. At the same time, i think something to stop the sound in a function like "useOnRelease" or "finishUsingItem" would be more helpful, but that is equally complicated without sound events management as i understand. (sorry if my english is a little broken, i am from Argentina). @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { if(!level.isClientSide() && hand == InteractionHand.MAIN_HAND) { level.playSound(null, player.getX(), player.getY(), player.getZ(), ModSounds.VIOLIN.get(), SoundSource.PLAYERS, 1F, 1.F); } return super.use(level, player, hand); }
May 31, 20232 yr 15 hours ago, Ribura said: At the same time, i think something to stop the sound in a function like "useOnRelease" or "finishUsingItem" would be more helpful, but that is equally complicated without sound events management as i understand. (sorry if my english is a little broken, i am from Argentina). You can look at `SpyglassItem` to see how it's implemented, but it's limited by the use duration. Additionally, you would probably need to manage this with packets. You make a sound manager on the client that works similar to how bee sounds work (see `BeeSoundInstance` for more details there).
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.