StUnTmAKEr
Members-
Posts
3 -
Joined
-
Last visited
StUnTmAKEr's Achievements
Tree Puncher (2/8)
0
Reputation
-
How to play vanilla sound when spawning an item on right click
StUnTmAKEr replied to StUnTmAKEr's topic in Modder Support
if (player.isShiftKeyDown() && hand == InteractionHand.MAIN_HAND && block == Blocks.MOSS_BLOCK){ if (!level.isClientSide){ player.drop(ItemInit.STONE_PEBBLE.get().getDefaultInstance(), false); level.playSound(null, event.getPos(), SoundEvents.MOSS_PLACE, SoundSource.BLOCKS, 1f, 1f); //player null plays to everyon near block } } GOT IT! Thanks all. The player being passed in the first code I commented stopped it from playing to me. The link you send me @warjort finished it up for me! -
How to play vanilla sound when spawning an item on right click
StUnTmAKEr replied to StUnTmAKEr's topic in Modder Support
if (player.isShiftKeyDown() && hand == InteractionHand.MAIN_HAND && block == Blocks.MOSS_BLOCK){ if (!level.isClientSide){ player.drop(ItemInit.STONE_PEBBLE.get().getDefaultInstance(), false); } else { level.playSound(player, event.getPos(), SoundEvents.MOSS_PLACE, SoundSource.BLOCKS, 1f, 1f); } } That worked! Thanks. I'm not quite sure why though? Does it have to do with sounds only being able to play on the client/server? -
I am trying to play a vanilla Minecraft sound when I am spawning an item into the world. I think I am close but the sound does not play when the item spawns into the world. @SubscribeEvent public static void onRightClickBlock(RightClickBlock event) { Player player = event.getEntity(); Level level = event.getLevel(); InteractionHand hand = event.getHand(); BlockState blockState = event.getLevel().getBlockState(event.getPos()); Block block = blockState.getBlock(); if (player.isShiftKeyDown() && hand == InteractionHand.MAIN_HAND && block == Blocks.MOSS_BLOCK && !level.isClientSide){ player.drop(ItemInit.STONE_PEBBLE.get().getDefaultInstance(), false); level.playSound(player, event.getPos(), SoundEvents.MOSS_PLACE, SoundSource.BLOCKS, 1f, 1f); } I am still new to modding and coding so this may be a little ugly haha. Trying to learn!