I’m still very new to the minecraft modding scene, and im trying to create a guitar that when right-clicked with in the players hand, plays a short .ogg. The Issue is that while the game and items loads in, nothing occurs when right clicked. no use animation, and more importantly no noise.
Here is the code i have right now for calling the sound.
@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.
In Truth, I have been following a tutorial, so while I understand the code itself, I’m ignorant to many functions or exceptions that weren’t shown to me.
Just Another Commenter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.