• 0

    posted a message on Can't call sound events for custom item

    I'm still very new to the Minecraft modding scene, and I'm trying to create a guitar that when right-clicked within the players hand, plays a short .ogg. The issue is that while the game and items load in, nothing occurs when right-clicking with the item. No use animation, and more importantly no noise.

    Here is the code for calling the Sound effect when right clicked

    @Override
    public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
        pLevel.playSound(null, pPlayer.getX(), pPlayer.getY(), pPlayer.getZ(), ModSounds.GUITAR_STRUMMED.get(), SoundSource.PLAYERS, 1f, 1.f);
        return super.use(pLevel, pPlayer, pUsedHand);
    }

     Here is the code for the sounds itself:

    {
      "guitar_stummed": {
        "subtitles": "sounds.learningmod.guitar_strummed",
        "sounds": [
          "learningmod:guitar_strummed",
          "learningmod:guitar_strummedb"
        ]
      }
    }
    

     And creating its registry:

    public class ModSounds {
        public static final DeferredRegister<SoundEvent> SOUND_EVENTS =
                DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, LearningMod.MOD_ID);
    
        public static final RegistryObject<SoundEvent> GUITAR_STRUMMED = registerSoundEvents("guitar_strummed");
    
        private static RegistryObject<SoundEvent> registerSoundEvents(String name) {
            return SOUND_EVENTS.register(name, () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(LearningMod.MOD_ID, name)));
        }
    
        public static void register(IEventBus eventBus){
            SOUND_EVENTS.register(eventBus);
        }

     At first I tried changing the @Override to a useon to see if forcing it to a block would give a consistent trigger for it, but that went nowhere as I didn't have the variables for even filling out the command. I tried shifting the order of the registry to see if there was a conflict I wasn't seeing, but that didn't help. Got rid of the second SFX, yet nothing changed. So far everything I've tried was a dud, and the guitar has absolutely no functionality.

     

     

    Posted in: Mod Development
  • To post a comment, please or register a new account.