Couper les musiques d'origine
-
Dans ta classe eventsound :
@ForgeSubscribe public void onSoundPlayed(PlayBackgroundMusicEvent event) { event.setCanceled(true); }Le problème, c’est que la music n’est pas cancelable, donc ça fait crash
Le mieux sera de jouer ton son comme une musique, enfin que le jeu ne joue pas une autre musique en même temps, et qu’il soit fort par tout, donc dans l’event sound :
event.manager.addMusic(“modid:music”) (le son sera dans assets/modid/music/)
Et pour jouer le son :SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("ta music"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(this, soundpoolentry)); if (soundpoolentry != null) { mc.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndSystem.setVolume("BgMusic", this.options.musicVolume); mc.sndSystem.play("BgMusic"); }J’ai pas eu le temps de tester, mais ça devrait être ça.
-
Salut
Merci et désolée de ne pas avoir répondu plus tôtMes erreurs :
mcQue je fasse n’importe quoi, c’est le mot d’après qui bug.
randQue je fasse n’importe quoi, c’est nextInt qui bug.
(new PlayBackgroundMusicEvent(this, soundpoolentry));Le problème, c’est que les 2 options pour régler cette erreur modifient les sources de Forges.
Merci d’avance
-
Oups, j’ai édité, j’ai supprimé la ligne inutile.
Tu as bien mit ce code dans ton tickhandler à la place du son actuelle ? -
J’ai les même erreurs que tout a l’heure, juste le rand en moins.
Merci d’avance -
Je peux avoir ton code entier du tick handler ?
-
package This_is_Halloween; import java.util.EnumSet; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; import net.minecraftforge.event.ForgeSubscribe; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ClientTickHandler implements ITickHandler { @Override public void tickStart(EnumSet <ticktype>type, Object… tickData) { } @ForgeSubscribe public void onSoundPlayed(PlayBackgroundMusicEvent event) { event.setCanceled(true); } @Override public void tickEnd(EnumSet <ticktype>type, Object... tickData) { SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("ta music"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(this, soundpoolentry)); if (soundpoolentry != null) { mc.ticksBeforeMusic = this.rand.nextInt(3060) + 3060; mc.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndSystem.setVolume("BgMusic", this.options.musicVolume); mc.sndSystem.play("BgMusic"); } } @Override public EnumSet <ticktype>ticks() { return EnumSet.of(TickType.PLAYER); } @Override public String getLabel() { return "snow tick handler"; } } ```</ticktype></ticktype></ticktype> -
J’ai pas dit de supprimer tout l’ancien code o_O
Juste le code qui jouait le son, donc world.playsound. -
Ok,
j’ai des erreurs résolus, mais j’ai toujours options qui bug et(new PlayBackgroundMusicEvent(this, soundpoolentry));Et j’ai aussi une nouvelle erreur :
sndSystem -
Je l’ai mis dans TickEnd
Vous pensez que c’est à cause de ça?___
Ou…. Je crois peut être savoir pourquoi y’a des erreurs, mais là je peux pas coder.
Je vous dirai la réponse demain. -
Salut
J’ai tester, non je ne vois pas où peut être l’erreur. -
J’ai recréer le code, réessayer, mais ça ne marche toujours pas
Un de vous a t-il une idée svp ? -
Je vois pas, tu pourrais me renvoyez le code que tu as dans ta classe principale + ton tickhandler pour que je puisse denouveau faire des tests en local ?
-
ClientTickHandler
package This_is_Halloween; import java.util.EnumSet; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundPoolEntry; import net.minecraft.util.MathHelper; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; import net.minecraftforge.client.event.sound.SoundEvent; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ClientTickHandler implements ITickHandler { @Override public void tickStart(EnumSet <ticktype>type, Object… tickData) { } @Override public void tickEnd(EnumSet <ticktype>type, Object... tickData) { Minecraft mc = FMLClientHandler.instance().getClient(); Random rand = mc.theWorld.rand; BiomeGenBase biome = mc.theWorld.getBiomeGenForCoords((int)mc.thePlayer.posX, (int)mc.thePlayer.posZ); if(rand.nextInt(15) > 13) { System.out.println(biome.getFloatTemperature()); int i = MathHelper.floor_double(mc.thePlayer.posX); int k = MathHelper.floor_double(mc.thePlayer.posZ); int k1 = i + rand.nextInt(10) - rand.nextInt(10); int l1 = k + rand.nextInt(10) - rand.nextInt(10); int i2 = mc.theWorld.getPrecipitationHeight(k1, l1); int j2 = mc.theWorld.getBlockId(k1, i2 - 1, l1); float f1 = rand.nextFloat(); float f2 = rand.nextFloat(); double d0 = (double)((float)k1 + f1); double d1 = (double)((float)i2 + 0.1F) - Block.blocksList[j2].getBlockBoundsMinY(); double d2 = (double)((float)l1 + f2); boolean biomeneige = biome.getFloatTemperature() == 0.05F || biome.getFloatTemperature() == 0.0F; if(mc.theWorld.isRaining() && biomeneige) { if(d1 > mc.thePlayer.posY + 1.0D && mc.theWorld.getPrecipitationHeight(MathHelper.floor_double(mc.thePlayer.posX), MathHelper.floor_double(mc.thePlayer.posZ)) > MathHelper.floor_double(mc.thePlayer.posY)) { SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("ta music"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(this, soundpoolentry)); if (soundpoolentry != null) { mc.ticksBeforeMusic = this.rand.nextInt(3060) + 3060; mc.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndSystem.setVolume("BgMusic", this.options.musicVolume); mc.sndSystem.play("BgMusic"); }} else { SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("ta music"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(this, soundpoolentry)); if (soundpoolentry != null) { mc.ticksBeforeMusic = this.rand.nextInt(3060) + 3060; mc.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndSystem.setVolume("BgMusic", this.options.musicVolume); mc.sndSystem.play("BgMusic"); }} } } } @Override public EnumSet <ticktype>ticks() { return EnumSet.of(TickType.PLAYER); } @Override public String getLabel() { return "snow tick handler"; } }Classe principale(dans la méthode load) :
TickRegistry.registerTickHandler(new ClientTickHandler(), Side.CLIENT); ```</ticktype></ticktype></ticktype> -
Le tick handler :
package tutoriel.common; import java.util.EnumSet; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundPoolEntry; import net.minecraft.client.settings.GameSettings; import net.minecraft.util.MathHelper; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; import net.minecraftforge.client.event.sound.SoundEvent; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ClientTickHandler implements ITickHandler { public int timer = 3060; @Override public void tickStart(EnumSet <ticktype>type, Object… tickData) { } @Override public void tickEnd(EnumSet <ticktype>type, Object... tickData) { Minecraft mc = FMLClientHandler.instance().getClient(); Random rand = mc.theWorld.rand; BiomeGenBase biome = mc.theWorld.getBiomeGenForCoords((int)mc.thePlayer.posX, (int)mc.thePlayer.posZ); if(rand.nextInt(15) > 13) { System.out.println(biome.getFloatTemperature()); int i = MathHelper.floor_double(mc.thePlayer.posX); int k = MathHelper.floor_double(mc.thePlayer.posZ); int k1 = i + rand.nextInt(10) - rand.nextInt(10); int l1 = k + rand.nextInt(10) - rand.nextInt(10); int i2 = mc.theWorld.getPrecipitationHeight(k1, l1); int j2 = mc.theWorld.getBlockId(k1, i2 - 1, l1); float f1 = rand.nextFloat(); float f2 = rand.nextFloat(); double d0 = (double)((float)k1 + f1); double d1 = (double)((float)i2 + 0.1F) - Block.blocksList[j2].getBlockBoundsMinY(); double d2 = (double)((float)l1 + f2); boolean biomeneige = biome.getFloatTemperature() == 0.05F || biome.getFloatTemperature() == 0.0F; if(mc.theWorld.isRaining() && biomeneige) { System.out.println(timer); if(timer == 3060) { if(d1 > mc.thePlayer.posY + 1.0D && mc.theWorld.getPrecipitationHeight(MathHelper.floor_double(mc.thePlayer.posX), MathHelper.floor_double(mc.thePlayer.posZ)) > MathHelper.floor_double(mc.thePlayer.posY)) { SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("modtutoriel:test"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(mc.sndManager, soundpoolentry)); if(soundpoolentry != null) { mc.sndManager.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndManager.sndSystem.setVolume("BgMusic", 1.0F); mc.sndManager.sndSystem.play("BgMusic"); } } else { SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("modtutoriel:test"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(mc.sndManager, soundpoolentry)); if(soundpoolentry != null) { mc.sndManager.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndManager.sndSystem.setVolume("BgMusic", 1.0F); mc.sndManager.sndSystem.play("BgMusic"); } } timer = 0; } else { timer++; } } } } @Override public EnumSet <ticktype>ticks() { return EnumSet.of(TickType.PLAYER); } @Override public String getLabel() { return "snow tick handler"; } }À ajouter dans l’event sound :
event.manager.addMusic("modtutoriel:test.ogg");Et le son dans /assets/modtutoriel/music/test.ogg
Testé & approuvé :p</ticktype></ticktype></ticktype>
-
Merci
Mais est-ce que je dois laissez ça ? :@ForgeSubscribe public void onSoundPlayed(PlayBackgroundMusicEvent event) { event.setCanceled(true); }J’ai aussi mis Le MUSIC_INTERVAL à 1 juste pour tester.
Et si je laisse le code, Minecraft crash, et si je l’enlève, ça joue aussi les autres musiques.
Merci d’ava,ce -
Enleve, on peut pas Cancel la music apparemment. J’ai vraiment pas d’idée pour la musique, il faudra modifier
private int ticksBeforeMusic; dans net.minecraft.client.audio.SoundManager, le problème c’est que la variable est private
Au pire, il faudrait voir avec la réflexion si c’est possible.Ha sinon, remplace ça :
mc.sndManager.sndSystem.setVolume(“BgMusic”, 1.0F);
par ça :
mc.sndManager.sndSystem.setVolume(“BgMusic”, mc.gameSettings.musicVolume);
Comme ça le son sera prit dans les options
-
Mais comment je fais pour enlever les musiques originaux, alors ?___
Peut être en utilisant les reflections avec le fichier des musiques, mais je ne sais pas où il se trouve. Et j’ai chercher partout. -
Personne ?
-
Après
if(timer == 3060) {Ajoute ce code :
mc.sndManager.sndSystem.stop("BgMusic"); ObfuscationReflectionHelper.setPrivateValue(SoundManager.class, mc.sndManager, 3060, "ticksBeforeMusic", "");Le premier devrait stoper la musique en cours, j’ai pas eu l’occasion de tester. Le deuxième change la valeur ticksBeforeMusic sur 3060, donc ça laisse le temps à ta musique de ce jouer sans qu’une autre vienne pas dessus. J’ai vérifie avec le System.out.prinln, ça marche, la valeur est bien modifié.
-
Salut
Merci, mais ça ne marche pas
Voilà mon code :package This_is_Halloween; import java.util.EnumSet; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundManager; import net.minecraft.client.audio.SoundPoolEntry; import net.minecraft.client.settings.GameSettings; import net.minecraft.util.MathHelper; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; import net.minecraftforge.client.event.sound.SoundEvent; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.ObfuscationReflectionHelper; import cpw.mods.fml.common.TickType; public class ClientTickHandler implements ITickHandler { public int timer = 3060; @Override public void tickStart(EnumSet <ticktype>type, Object… tickData) { } @Override public void tickEnd(EnumSet <ticktype>type, Object... tickData) { Minecraft mc = FMLClientHandler.instance().getClient(); Random rand = mc.theWorld.rand; BiomeGenBase biome = mc.theWorld.getBiomeGenForCoords((int)mc.thePlayer.posX, (int)mc.thePlayer.posZ); if(rand.nextInt(15) > 13) { System.out.println(biome.getFloatTemperature()); int i = MathHelper.floor_double(mc.thePlayer.posX); int k = MathHelper.floor_double(mc.thePlayer.posZ); int k1 = i + rand.nextInt(10) - rand.nextInt(10); int l1 = k + rand.nextInt(10) - rand.nextInt(10); int i2 = mc.theWorld.getPrecipitationHeight(k1, l1); int j2 = mc.theWorld.getBlockId(k1, i2 - 1, l1); float f1 = rand.nextFloat(); float f2 = rand.nextFloat(); double d0 = (double)((float)k1 + f1); double d1 = (double)((float)i2 + 0.1F) - Block.blocksList[j2].getBlockBoundsMinY(); double d2 = (double)((float)l1 + f2); boolean biomeneige = biome.getFloatTemperature() == 0.05F || biome.getFloatTemperature() == 0.0F; if(mc.theWorld.isRaining() && biomeneige) { System.out.println(timer); if(timer == 3060) { mc.sndManager.sndSystem.stop("BgMusic"); ObfuscationReflectionHelper.setPrivateValue(SoundManager.class, mc.sndManager, 3060, "ticksBeforeMusic", ""); if(d1 > mc.thePlayer.posY + 1.0D && mc.theWorld.getPrecipitationHeight(MathHelper.floor_double(mc.thePlayer.posX), MathHelper.floor_double(mc.thePlayer.posZ)) > MathHelper.floor_double(mc.thePlayer.posY)) { SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("halloween:music"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(mc.sndManager, soundpoolentry)); if(soundpoolentry != null) { mc.sndManager.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndManager.sndSystem.setVolume("BgMusic", 1.0F); mc.sndManager.sndSystem.play("BgMusic"); System.out.println("ca marche :)"); } } else { SoundPoolEntry soundpoolentry = mc.sndManager.soundPoolMusic.getRandomSoundFromSoundPool("halloween:music"); soundpoolentry = SoundEvent.getResult(new PlayBackgroundMusicEvent(mc.sndManager, soundpoolentry)); if(soundpoolentry != null) { mc.sndManager.sndSystem.backgroundMusic("BgMusic", soundpoolentry.func_110457_b(), soundpoolentry.func_110458_a(), false); mc.sndManager.sndSystem.setVolume("BgMusic", 1.0F); mc.sndManager.sndSystem.play("BgMusic"); } } timer = 0; } else { timer++; } } } } @Override public EnumSet <ticktype>ticks() { return EnumSet.of(TickType.PLAYER); } @Override public String getLabel() { return "snow tick handler"; } }J’ai donc mis le code pour que ça affiche des mots dans la console, mais ça ne marche pas
Ce qui veut dire que quelque chose dans le code bug.</ticktype></ticktype></ticktype>