Jump to content

Recommended Posts

Posted

Hi, all.

 

I'm trying to port one of my 1.2.5 mods (it used Audiomod and a bit of base class editing) to 1.4.6 and pure Forge. In its current state, it should play a sound at your location (and that of any other player) when you/they jump. However, I can't get sounds to play and I have no idea why. The jump event triggers, but the sound playback code fails.

 

I'm pretty sure that the sound files are in the correct place - a bit of debug code in the sound file loading section told me that Minecraft is trying to locate the files at forge/mcp/bin/minecraft/(sound path) - so in my case, it's forge/mcp/bin/minecraft/fruitmods/playersounds/sound/jumpsound.ogg

 

Anyone know what I'm doing wrong?

 

(yes, I know, I should use spoiler tags to collapse the code segments, but I don't seem to be able to expand them in my browser)

 

Base mod class:

 

package fruitmods.playersounds;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
// import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
//import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

// Quake jump and pain sounds, C&C death sounds
// mod structure taken directly from the Forge tutorial at http://www.minecraftforge.net/wiki/Basic_Modding
// no, I probably don't need half of these includes
// but I'm not entirely sure what some of them do

@Mod(modid="PlayerSounds", name="Player Sounds", version="r1.4.6-v1")
public class PlayerSounds
{
  @Instance("PlayerSounds")
  public static PlayerSounds instance;
  
  @SidedProxy(clientSide="fruitmods.playersounds.PlayerSounds_ClientProxy", serverSide="fruitmods.playersounds.PlayerSounds_CommonProxy")
  public static PlayerSounds_CommonProxy proxy;
  
  @PreInit
  public void preInit(FMLPreInitializationEvent event)
  {
    // register the event handler here
    // the event handler actually does all of the work for this mod
    proxy.registerJumpCatcher();
  }
  
  @Init
  public void load(FMLInitializationEvent event)
  {
    proxy.registerSounds();
    // other mods that deal in sounds seem to load their sound files in the load stage
  }
}

 

 

Common proxy:

package fruitmods.playersounds;

public class PlayerSounds_CommonProxy
{
  public void registerSounds()
  {
    // server no likey soundy
  }
  
  public void registerJumpCatcher()
  {
    // the server don't care about handling jump events either
  }
}

 

 

Client proxy:

package fruitmods.playersounds;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.client.MinecraftForgeClient;
import fruitmods.playersounds.PlayerSounds_CommonProxy;

public class PlayerSounds_ClientProxy extends PlayerSounds_CommonProxy
{
  @Override
  public void registerSounds()
  {
    System.out.println("Loading Player Sounds audio files");
    MinecraftForge.EVENT_BUS.register(new PlayerSounds_AudioLoader());
  }
  
  @Override
  public void registerJumpCatcher()
  {
    System.out.println("Registering Player Sounds event handler.");
    MinecraftForge.EVENT_BUS.register(new PlayerSounds_PlayerHandler());
  }
  
  // also, we stick the event handlers for jump events, death events and hurt events here
  // pain sounds might be a little difficult without basemod editing
  // since there are already default pain sounds (I think)
  // sure, we can replace the sound files, but that won't give us lava pain sounds
  
}

 

 

Player action event handler code:

package fruitmods.playersounds;

import net.minecraft.client.Minecraft;
import cpw.mods.fml.client.FMLClientHandler;
// old-style: import net.minecraft.src.ModLoader;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingEvent;

public class PlayerSounds_PlayerHandler
{
  protected Minecraft mc = FMLClientHandler.instance().getClient();
  // was ModLoader.getMinecraftInstance() in previous versions
  // probably won't be needed once we remove the debug strings
  
  @ForgeSubscribe
  public void EntityJumped(LivingEvent.LivingJumpEvent jumpEvent)
  {
    if(jumpEvent.entityLiving instanceof net.minecraft.entity.player.EntityPlayer)
    {
      // this bit works fine
      String jump_debug_string = "Jump by " + jumpEvent.entityLiving.getEntityName() + " at (" + jumpEvent.entityLiving.posX + ", " + jumpEvent.entityLiving.posY + ", " + jumpEvent.entityLiving.posZ + ")";
      
      this.mc.ingameGUI.getChatGUI().printChatMessage(jump_debug_string);
      
      // after a bit of debug code has been tried out, it seems that you need to put your sound files
      // in the forge/mcp/bin/minecraft/(sound path) directory
      // eg: forge/mcp/bin/minecraft/fruitmods/playersounds/sound/jumpsound.ogg
      
      jumpEvent.entityLiving.worldObj.playSoundAtEntity(jumpEvent.entityLiving, "fruitmods.playersounds.sound.jumpsound", 1.0F, 1.0F);
      // a debug entry explicitly designed to fail does not produce an error message
      // jumpEvent.entityLiving.worldObj.playSoundAtEntity(jumpEvent.entityLiving, "fruitmods.playersounds.sound.jumpsoundOMGTEMP", 1.0F, 1.0F);
      
      // we can't play already-loaded sounds
      // jumpEvent.entityLiving.worldObj.playSoundAtEntity(jumpEvent.entityLiving, "step.wood", 1.0F, 1.0F);
      
      // this is the code from our 1.2.5 version
      // it still doesn't play and there is absolutely no indication as to why it's not playing
      // mc.theWorld.playSoundAtEntity(jumpEvent.entityLiving, "fruitmods.playersounds.sound.jumpsound", 1.0F, 1.0F);
      
      // SoundManager.playEntitySound("fruitmods.playersounds.sound.jumpsound", jumpEvent.entityLiving, 1.0F, 1.0F, false);
      // can't call the relevant function directly, because it's not a static function
      
    }
  }
}

 

 

Audio file loading event handler:

package fruitmods.playersounds;

import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.client.event.sound.SoundLoadEvent;

public class PlayerSounds_AudioLoader
{
  // this little trick with the array, along with the rest of the sound loading code came from:
  // http://www.minecraftforge.net/forum/index.php/topic,298.0.html
  String[] sound_files = {"jumpsound.ogg", "playerpain1.ogg", "playerpain2.ogg", "playerdeath1.ogg", "playerdeath2.ogg", "playerdeath3.ogg", "playerdeath4.ogg"};
  
  @ForgeSubscribe
  public void onSoundsLoaded(SoundLoadEvent SLEvent)
  {
    System.out.println("SLEvent called, loading Player Sounds...");
    for (int i = 0; i < sound_files.length; i++)
    {
      System.out.println("Attempting to load file: " + this.getClass().getResource("/fruitmods/playersounds/sound/" + sound_files[i]));
      try
      {
SLEvent.manager.soundPoolSounds.addSound("fruitmods/playersounds/sound/" + sound_files[i], this.getClass().getResource("/fruitmods/playersounds/sound/" + sound_files[i]));
      
      }
      catch (Exception e)
      {
System.err.println("PlayerSounds: Failed to register sound file " + i + ": " + sound_files[i]);
      }
    }          
  }
}

Posted

I think you have to register the Sound event handler in preInit, otherwise it is registered after the SoundLoadEvent fires, so it has no use. At least that was the case with my mod.

I've moved the sound loading event handler to preInit, but the sounds still aren't playing. The load event is being called now, so that's something at least.
Posted

And you are absolutely sure that there are no exceptions during registering the sounds? And is the jump-debug message printed?

There are no error messages on the command line - here's the relevant part of the startup logs:

 

[11:37:52] 2013-01-17 11:37:52 [iNFO] [sTDOUT] Registering Player Sounds event handler.
[11:37:52] 2013-01-17 11:37:52 [iNFO] [sTDOUT] Loading Player Sounds audio files
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Starting up SoundSystem...
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Initializing LWJGL OpenAL
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT]     (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] OpenAL initialized.
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] SLEvent called, loading Player Sounds...
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Attempting to load file: file:/home/ltls2/Minecraft/mcp725%20(MC%20r1.4.6)/forge/mcp/bin/minecraft/fruitmods/playersounds/sound/jumpsound.ogg
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Attempting to load file: file:/home/ltls2/Minecraft/mcp725%20(MC%20r1.4.6)/forge/mcp/bin/minecraft/fruitmods/playersounds/sound/playerpain1.ogg
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Attempting to load file: file:/home/ltls2/Minecraft/mcp725%20(MC%20r1.4.6)/forge/mcp/bin/minecraft/fruitmods/playersounds/sound/playerpain2.ogg
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Attempting to load file: file:/home/ltls2/Minecraft/mcp725%20(MC%20r1.4.6)/forge/mcp/bin/minecraft/fruitmods/playersounds/sound/playerdeath1.ogg
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Attempting to load file: file:/home/ltls2/Minecraft/mcp725%20(MC%20r1.4.6)/forge/mcp/bin/minecraft/fruitmods/playersounds/sound/playerdeath2.ogg
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Attempting to load file: file:/home/ltls2/Minecraft/mcp725%20(MC%20r1.4.6)/forge/mcp/bin/minecraft/fruitmods/playersounds/sound/playerdeath3.ogg
[11:37:53] 2013-01-17 11:37:53 [iNFO] [sTDOUT] Attempting to load file: file:/home/ltls2/Minecraft/mcp725%20(MC%20r1.4.6)/forge/mcp/bin/minecraft/fruitmods/playersounds/sound/playerdeath4.ogg
[11:37:54] 2013-01-17 11:37:54 [iNFO] [sTDOUT] Armour HUD Status v2.4a [MC r1.4.6] loaded.
[11:37:54] 2013-01-17 11:37:54 [iNFO] [sTDOUT] Fruit Display Library v1.3 initialised.
[11:37:54] 2013-01-17 11:37:54 [iNFO] [ForgeModLoader] Forge Mod Loader has successfully loaded 6 mods

 

EDIT: putting in a sound file that I know isn't present (another entry for "OMGIDONTEXIST.ogg" in the sound_files String[]) gives me this:

[12:35:39] 2013-01-17 12:35:39 [iNFO] [sTDOUT] Attempting to load file: null

So it at can at the very least resolve a path to the sound files.

 

The jump debug message gets printed to chat every time I jump, so I know that the event is triggering. It's only the sound playback that's giving me problems :(.

Posted

And I found the problem. PlaySoundAtEntity doesn't work - you need to use PlaySound instead (thanks AtomicStryker, looking at your mod code was most useful).

 

mc.theWorld.playSound(jumpEvent.entityLiving.posX, jumpEvent.entityLiving.posY, jumpEvent.entityLiving.posZ, "fruitmods.playersounds.sound.jumpsound", 1.0F, 1.0F, false);

  • 3 months later...
Posted

I've done all this and my sounds work great. If I run them w/ FeedTheBeast, they don't play. If I remove all of the other mods from FTB, my sounds play fine. So it seems like there is an interaction bug between my mod's sounds and another one. Any idea how I determine the problem? I am stumped!

Posted

I've done all this and my sounds work great. If I run them w/ FeedTheBeast, they don't play. If I remove all of the other mods from FTB, my sounds play fine. So it seems like there is an interaction bug between my mod's sounds and another one. Any idea how I determine the problem? I am stumped!

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.