Posted July 9, 20205 yr How can i make my music play at the background, like the vanilla soundtrack? I want to not just replace the vanilla soundtrack with my own, as in a resourcepack, but add new tracks to it
July 9, 20205 yr You could register your own SoundEvents as detailed here, and then for example play those SoundEvents (your music) in a tick event at random.
July 9, 20205 yr Author 1 hour ago, vemerion said: You could register your own SoundEvents as detailed here, and then for example play those SoundEvents (your music) in a tick event at random. I have already registered all the sound events, but i have never worked with tick events. Could you explain me how it works or give an example code?
July 9, 20205 yr 39 minutes ago, kemika1girl said: example code This would play your music once every 1000 ticks (every 50 seconds): private static int musicTimer = 1000; @SubscribeEvent public static void onTick(ClientTickEvent event) { if (event.phase == Phase.END && event.side == LogicalSide.CLIENT) { if (musicTimer-- <= 0 && Minecraft.getInstance() != null && Minecraft.getInstance().player != null) { musicTimer = 1000; Minecraft.getInstance().player.playSound(YOUR MUSIC HERE, 2f, 1f); Minecraft.getInstance().getMusicTicker().stop(); } } } Although I think the vanilla Minecraft music could potentially start while your music is playing, so you would have to handle that also.
July 9, 20205 yr Author ah, thanks! 36 minutes ago, vemerion said: Although I think the vanilla Minecraft music could potentially start yes, vanilla music can start playing, but i will try to make vanilla music stop playing if mine is already playing
July 9, 20205 yr Author @vemerion strange, but seems like nothing happens after i added the code.. did i do something wrong? @Mod.EventBusSubscriber(modid = Atmospheric.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) @Mod("atmospheric") public class Atmospheric { public static final String MOD_ID = "atmospheric"; Minecraft minecraft = Minecraft.getInstance(); private static int musicTimer = 10; @SubscribeEvent public static void onTick(TickEvent.ClientTickEvent event) { if (event.phase == TickEvent.Phase.END && event.side == LogicalSide.CLIENT) { if (musicTimer-- <= 0 && Minecraft.getInstance() != null && Minecraft.getInstance().player != null) { musicTimer = 10; Minecraft.getInstance().player.playSound(AtmosphericSoundEvents.SOLACE_1, 2f, 1f); Minecraft.getInstance().getMusicTicker().stop(); } } } }
July 9, 20205 yr 11 minutes ago, kemika1girl said: strange, but seems like nothing happens after i added the code.. did i do something wrong? ClientTickEvent is fired on the Forge bus, try changing bus = Mod.EventBusSubscriber.Bus.MOD to bus = Mod.EventBusSubscriber.Bus.FORGE
July 9, 20205 yr Author 4 minutes ago, vemerion said: ClientTickEvent is fired on the Forge bus, try changing bus = Mod.EventBusSubscriber.Bus.MOD to bus = Mod.EventBusSubscriber.Bus.FORGE really, now it works thanks you very much!
July 9, 20205 yr 27 minutes ago, kemika1girl said: thanks you very much! No problem, glad I could help!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.