Procedure : Play a sound when an item is retrieved

Started by eXtra_Geek_Style on Sun, 06/07/2020 - 00:02

Topic category: Help with modding (Java Edition)

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Procedure : Play a sound when an item is retrieved
Sun, 06/07/2020 - 00:02

Hello, I need help, I'm making a mod whose when you retrieve a Item, it play a sound, but I don't know how to do, does anyone know ? Thank you !

 

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Use sumtang like 'dis; …
Sun, 06/07/2020 - 00:20

Use sumtang like 'dis;

    @SubscribeEvent
    public void pickupItem(PlayerEvent.ItemPickupEvent event)
    {
        if (event.getStack().getItem() == Items.CAKE) {
            event.getPlayer().world.playSound(event.getPlayer(), event.getPlayer().getPosition(), SoundEvents.AMBIENT_CAVE, SoundCategory.NEUTRAL, 1F, 1F);
        }
    }

 

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
What line should I put this…
Sun, 06/07/2020 - 10:52

What line should I put this code on?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Anywhere in any class, just…
Sun, 06/07/2020 - 16:43

Anywhere in any class, just make sure it is registered.

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
What if I want it to be a…
Sun, 06/07/2020 - 17:44

What if I want it to be a sound that I imported into my MCreator workspace?

 

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
So I did some looking around…
Sun, 06/07/2020 - 17:55

So I did some looking around, and I found this;

(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("modid:nameofsound")

So, in the end, it should look similar to this;

    @SubscribeEvent
    public void pickupItem(PlayerEvent.ItemPickupEvent event)
    {
        if (event.getStack().getItem() == Items.CAKE) {
            event.getPlayer().world.playSound(event.getPlayer(), event.getPlayer().getPosition(), (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("modid:nameofsound"), SoundCategory.NEUTRAL, 1F, 1F);
        }
    }

 

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
So compared to my…
Sun, 06/07/2020 - 21:12

So compared to my modifications, should I just modify the "modid: nameofsound"?

 

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
and if my item is named …
Sun, 06/07/2020 - 21:14

and if my item is named "bolt" modify "Item.CAKE" and set "Item.bolt" ?

 

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
(No subject)
Sun, 06/07/2020 - 21:34

Error in the code, anyone have an idea ?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
add a ")" at the end
Sun, 06/07/2020 - 21:36

add a ")" at the end

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thank you ! 😀
Sun, 06/07/2020 - 21:38

Thank you ! 😀

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
👍
Sun, 06/07/2020 - 21:39

👍

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
So it will be like this ?
Sun, 06/07/2020 - 21:42

So it will be like this ?So it will be like this ?

Last seen on 11:44, 19. May 2021
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
So... I've not the same…
Sun, 06/07/2020 - 21:53

So... I've not the same result... It do this :

Error in the code