Jump to content

Recommended Posts

Posted

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

Posted
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?

Posted
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.

Posted

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

Posted

@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();
            }
        }
    }
}


 

Posted
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

 

Posted
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!

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.