Posted April 1, 201510 yr In forge is there a way to add Background Music? Like "Calm 1" sound in Minecraft?
April 2, 201510 yr Hi Yes there is, have a look at vanilla MovingSoundMinecartRiding and/or RenderGlobal.playRecord(). You can play the sound using something like ResourceLocation mySoundRes = new ResourceLocation("mymodid:mysound"); PositionedSoundRecord mySoundRes = PositionedSoundRecord.create(mySoundRes); Minecraft.getMinecraft().getSoundHandler().playSound(mySoundRes); put a sounds.json in resources/assets/mymodid/ { "mysound": {"category": "ambient", "sounds": ["mysoundfilename"]} } and your .ogg sound file in resources/assets/mymodid/sounds mysoundfilename.ogg It's a bit fiddly to get right.... the console often gives you a relevant error message. -TGG
April 2, 201510 yr Author Ok, I got how to play the sound! It Works! Now I just need like a random event, you know, minecraft music random plays, something like that.
April 2, 201510 yr You can subscribe ClientTickEvent and play the background music randomly. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
April 2, 201510 yr Author You can subscribe ClientTickEvent and play the background music randomly. Can you give me a little example?
April 2, 201510 yr You can subscribe ClientTickEvent and play the background music randomly. Can you give me a little example? For learning how to handle events (this is worth learning as it is a powerful modding approach) I have a tutorial here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html For the random part, that is just Java. Always remember that in Minecraft modding that you can do anything that Java can do. For example, Java has the Random class: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html Use the random class to generate a number, use an if statement to compare that number to some chance, and if the chance happens play the sound. Note that the client tick handler is fired 20 times per second. So if you want 6 minutes on average between playing the sound, you need the chance to play to be less than 1/3600. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
April 2, 201510 yr Author You can subscribe ClientTickEvent and play the background music randomly. Can you give me a little example? For learning how to handle events (this is worth learning as it is a powerful modding approach) I have a tutorial here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html For the random part, that is just Java. Always remember that in Minecraft modding that you can do anything that Java can do. For example, Java has the Random class: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html Use the random class to generate a number, use an if statement to compare that number to some chance, and if the chance happens play the sound. Note that the client tick handler is fired 20 times per second. So if you want 6 minutes on average between playing the sound, you need the chance to play to be less than 1/3600. I am getting an Error in My Event Class: ---- Minecraft Crash Report ---- // I bet Cylons wouldn't have this problem. Time: 02/04/15 12:57 Description: Initializing game java.lang.IllegalArgumentException: Method public void com.gpa.startrekmod.EventHandler.STMusicEvent.playSound1(cpw.mods.fml.common.gameevent.TickEvent$ClientTickEvent,java.util.Random) has @SubscribeEvent annotation, but requires 2 arguments. Event handler methods must require a single argument. at cpw.mods.fml.common.eventhandler.EventBus.register(EventBus.java:72) at com.gpa.startrekmod.STModInfo.preInit(STModInfo.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513) at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239) at net.minecraft.client.Minecraft.startGame(Minecraft.java:522) at net.minecraft.client.Minecraft.run(Minecraft.java:931) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) at GradleStart.main(GradleStart.java:45) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at cpw.mods.fml.common.eventhandler.EventBus.register(EventBus.java:72) at com.gpa.startrekmod.STModInfo.preInit(STModInfo.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513) at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239) at net.minecraft.client.Minecraft.startGame(Minecraft.java:522) -- Initialization -- Details: Stacktrace: at net.minecraft.client.Minecraft.run(Minecraft.java:931) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) at GradleStart.main(GradleStart.java:45) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.8.0_11, Oracle Corporation Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 653559320 bytes (623 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized FML{7.10.85.1291} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized Forge{10.13.2.1291} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized gpa_startrekmod{0.1.5} [star Trek Mod] (bin) Unloaded->Constructed->Errored Launched Version: 1.7.10 LWJGL: 2.9.1 OpenGL: AMD Radeon HD 6800 Series GL version 4.4.12874 Compatibility Profile Context 14.100.0.0, ATI Technologies Inc. GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Anisotropic filtering is supported and maximum anisotropy is 16. Shaders are available because OpenGL 2.1 is supported. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Anisotropic Filtering: Off (1) My EventClass: package com.gpa.startrekmod.EventHandler; import java.util.Random; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.util.ResourceLocation; import cpw.gpa.startrekmod.help.STReferencies; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; public class STMusicEvent { @SubscribeEvent public void playSound1(ClientTickEvent event, Random rand){ int i = (int)Math.random(); if(i <= 10){ Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147673_a(new ResourceLocation(STReferencies.MODID + ":" + "ST_Back_1"))); } } }
April 2, 201510 yr Author Read the error. It's an english sentence that tells you EXACTLY what you need to do... Lol, I din't noticed... Fixed! Thanks!
April 6, 201510 yr Is there a way to check that no background music is already playing first before I play mine?
April 6, 201510 yr Author Is there a way to check that no background music is already playing first before I play mine? Yes, there is: 1. In your Event use this: Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(ISound)
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.