Procedure : Play a sound when an item is retrieved

Started by eXtra_Geek_Style on

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:
  • 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 !

 

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You need to do the imports
Sun, 06/07/2020 - 21:57

You need to do the imports

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
import net.minecraftforge…
Sun, 06/07/2020 - 22:00
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

 

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm really sorry, i'm a …
Sun, 06/07/2020 - 22:08

I'm really sorry, i'm a "cadet" in java ^^' can you help me... again ? :

Error in the code

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can you post the whole class?
Sun, 06/07/2020 - 22:10

Can you post the whole class?

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's the class of the…
Sun, 06/07/2020 - 22:13

The codeIt's the class of the imports

You talk of that ?

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I mean everything in that…
Sun, 06/07/2020 - 22:19

I mean everything in that file

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
package net.mcreator…
Sun, 06/07/2020 - 22:20
package net.mcreator.morecraftableitems;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.event.ModelRegistryEvent;

import net.minecraft.world.World;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.entity.Entity;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import java.util.List;

@Elementsmorecraftableitems.ModElement.Tag
public class MCreatorBolt extends Elementsmorecraftableitems.ModElement {
	@GameRegistry.ObjectHolder("morecraftableitems:bolt")
	public static final Item block = null;

	public MCreatorBolt(Elementsmorecraftableitems instance) {
		super(instance, 8);
	}

	@Override
	public void initElements() {
		elements.items.add(() -> new ItemCustom());
	}

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

	@SideOnly(Side.CLIENT)
	@Override
	public void registerModels(ModelRegistryEvent event) {
		ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation("morecraftableitems:bolt", "inventory"));
	}

	public static class ItemCustom extends Item {
		public ItemCustom() {
			setMaxDamage(0);
			maxStackSize = 1000;
			setUnlocalizedName("bolt");
			setRegistryName("bolt");
			setCreativeTab(MCreatorRatchetClank.tab);
		}

		@Override
		public int getItemEnchantability() {
			return 0;
		}

		@Override
		public int getMaxItemUseDuration(ItemStack itemstack) {
			return 0;
		}

		@Override
		public float getDestroySpeed(ItemStack par1ItemStack, IBlockState par2Block) {
			return 1F;
		}

		@Override
		public void addInformation(ItemStack itemstack, World world, List<String> list, ITooltipFlag flag) {
			super.addInformation(itemstack, world, list, flag);
			list.add("La monaie classique du jeu, Elle equivaut 1 lingot en fer");
		}

		@Override
		public void onUpdate(ItemStack itemstack, World world, Entity entity, int slot, boolean par5) {
			super.onUpdate(itemstack, world, entity, slot, par5);
			int x = (int) entity.posX;
			int y = (int) entity.posY;
			int z = (int) entity.posZ;
			{
				java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
				$_dependencies.put("entity", entity);
				MCreatorBoltItemInInventoryTick.executeProcedure($_dependencies);
			}
		}
	}
}

 

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You're not using 1.15.2, are…
Sun, 06/07/2020 - 22:27

You're not using 1.15.2, are you? What Minecraft version are you using?

 

Besides that replace this;

	public MCreatorBolt(Elementsmorecraftableitems instance) {
		super(instance, 8);
		MinecraftForge.EVENT_BUS.register(new MCreatorBolt());
	}

 

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I use 1.12.2
Mon, 06/08/2020 - 05:16

I use 1.12.2

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Welp, that code is for 1.15…
Mon, 06/08/2020 - 05:30

Welp, that code is for 1.15.2. I will redo this code in my 1.12.2 test environment tomorrow.

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What news ?
Tue, 07/07/2020 - 22:39

What news ?