Procedure : Play a sound when an item is retrieved

Started by eXtra_Geek_Style on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Procedure : Play a sound when an item is retrieved

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 !

 

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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);
        }
    }

 

Joined Jun 2019
Points:

User statistics:

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

What line should I put this code on?

Joined Sep 2019
Points:

User statistics:

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

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

Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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?

 

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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);
        }
    }

 

Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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"?

 

Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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" ?

 

Joined Sep 2019
Points:

User statistics:

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

add a ")" at the end

Joined Sep 2019
Points:

User statistics:

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

👍

Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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 ?

Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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