Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am trying to play a vanilla Minecraft sound when I am spawning an item into the world. I think I am close but the sound does not play when the item spawns into the world.

 

@SubscribeEvent
    public static void onRightClickBlock(RightClickBlock event) {
        Player player = event.getEntity();
        Level level = event.getLevel();
        InteractionHand hand = event.getHand();

        BlockState blockState = event.getLevel().getBlockState(event.getPos());
        Block block = blockState.getBlock();

        if (player.isShiftKeyDown() && hand == InteractionHand.MAIN_HAND && block == Blocks.MOSS_BLOCK && !level.isClientSide){

            player.drop(ItemInit.STONE_PEBBLE.get().getDefaultInstance(), false);  
          
            level.playSound(player, event.getPos(), SoundEvents.MOSS_PLACE, SoundSource.BLOCKS, 1f, 1f);

        }

 

I am still new to modding and coding so this may be a little ugly haha. Trying to learn!

try this:

if first three conditions
{
if not clientside drop pebble
else play sound
}

i can't fire up the ide now but something like this should work.

  • Author
if (player.isShiftKeyDown() && hand == InteractionHand.MAIN_HAND && block == Blocks.MOSS_BLOCK){

            if (!level.isClientSide){
                player.drop(ItemInit.STONE_PEBBLE.get().getDefaultInstance(), false);
            }
            else {
                level.playSound(player, event.getPos(), SoundEvents.MOSS_PLACE, SoundSource.BLOCKS, 1f, 1f);
            }

        }

 

That worked! Thanks. I'm not quite sure why though? Does it have to do with sounds only being able to play on the client/server?

That code only plays the sound on the client for the player dropping the pebble.

https://forge.gemwire.uk/wiki/Sounds#Level

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author
if (player.isShiftKeyDown() && hand == InteractionHand.MAIN_HAND && block == Blocks.MOSS_BLOCK){

            if (!level.isClientSide){
                player.drop(ItemInit.STONE_PEBBLE.get().getDefaultInstance(), false);
                level.playSound(null, event.getPos(), SoundEvents.MOSS_PLACE, SoundSource.BLOCKS, 1f, 1f); //player null plays to everyon near block
            }

        }

GOT IT! Thanks all. The player being passed in the first code I commented stopped it from playing to me. The link you send me @warjort finished it up for me!

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.