Jump to content

[1.19.2] Making a sound while right clicking


Ribura

Recommended Posts

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);
    }
Link to comment
Share on other sites

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).

  • Thanks 1
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.

Announcements



×
×
  • Create New...

Important Information

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