Posted July 17, 201312 yr 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.
July 17, 201312 yr onUpdate(ItemStack, World, Entity) The only downside to this is that it will constantly play while the item is in inventory.
July 17, 201312 yr 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.
July 17, 201312 yr 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.
July 17, 201312 yr 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?
July 17, 201312 yr 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.
July 18, 201312 yr 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.