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 simply wondering what method to override in my item in order to put use the playSoundAtEntity method so I can play a sound when the player holds an item.

onUpdate(ItemStack, World, Entity)

 

The only downside to this is that it will constantly play while the item is in inventory.

It is called so long as it is in your inventory. But yes, checking if the currently held item is the passed stack will keep it from humming constantly unless it is otherwise in your hand.

It is NOT only called in the hotbar. I am testing this as we speak with a shield and it constantly updates as long as it is in your inventory, any slot.

 

 

Javadoc:

Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and update it's contents.

  • Author

Is there a specific method I should use? Or do I just compare the result of getCurrentItem with the item I want the sound to play on?

you could check if it's in slots 0-9 if you want it to play while on the hotbar, otherwise check if it's the selected item.

  • Author

Hey, so in case anyone was looking at this thread and wanted to know the working code I used, here it is:

public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5){
     if (par5){
          par2World.playSoundAtEntity(par3Entity, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); //"random.bow" just used as a test
     }
}

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.