Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Can't get custom sounds to play
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
DoomFruit

[SOLVED] Can't get custom sounds to play

By DoomFruit, January 17, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

DoomFruit    1

DoomFruit

DoomFruit    1

  • Tree Puncher
  • DoomFruit
  • Members
  • 1
  • 12 posts
Posted January 17, 2013

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]);
      }
    }          
  }
}

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted January 17, 2013

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.

  • Quote

Share this post


Link to post
Share on other sites

DoomFruit    1

DoomFruit

DoomFruit    1

  • Tree Puncher
  • DoomFruit
  • Members
  • 1
  • 12 posts
Posted January 17, 2013

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.
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted January 17, 2013

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

  • Quote

Share this post


Link to post
Share on other sites

DoomFruit    1

DoomFruit

DoomFruit    1

  • Tree Puncher
  • DoomFruit
  • Members
  • 1
  • 12 posts
Posted January 17, 2013

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 :(.

  • Quote

Share this post


Link to post
Share on other sites

DoomFruit    1

DoomFruit

DoomFruit    1

  • Tree Puncher
  • DoomFruit
  • Members
  • 1
  • 12 posts
Posted January 18, 2013

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);

  • Quote

Share this post


Link to post
Share on other sites

pdunham    0

pdunham

pdunham    0

  • Tree Puncher
  • pdunham
  • Members
  • 0
  • 2 posts
Posted April 24, 2013

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!

  • Quote

Share this post


Link to post
Share on other sites

pdunham    0

pdunham

pdunham    0

  • Tree Puncher
  • pdunham
  • Members
  • 0
  • 2 posts
Posted April 24, 2013

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!

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Simon_kungen
      [1.14.4] Sync ItemStack Capability Data + Multi-Capability Provider casting error

      By Simon_kungen · Posted 21 minutes ago

      Hi   My item has ItemHandler capability, which works fine. But one of the things I have when storing a item on the capability is overring the translation key with the contained stack's translation key.     The problem is that this will only sync when opening the item again. I need to send a message to the client with the new contained stack which I do not know how to do. I don't know which ItemStack I need to change on the client when the container is closed.     My item needs to have two capabilities attached to it. One is the Forge ItemHandler Capability while the other that is exclusive to the glass variant should be able to store a liquid too. For this, I made a provider that includes these capabilities: public class StackFluidContainerProvider implements ICapabilitySerializable { private final FluidContainer fluid; private final ItemStackHandler inventory; private final LazyOptional<IItemHandler> itemHandler = LazyOptional.of(this::getInventory); private final LazyOptional<IFluidContainer> fluidHandler = LazyOptional.of(this::getFluid); public StackFluidContainerProvider(short slots, short maxVolume) { inventory = new ItemStackHandler(slots); fluid = new FluidContainer(maxVolume); } protected FluidContainer getFluid() { return fluid; } protected ItemStackHandler getInventory() { return inventory; } @SuppressWarnings("ConstantConditions") @Override public INBT serializeNBT() { CompoundNBT compoundNBT = new CompoundNBT(); compoundNBT.put("items", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getStorage().writeNBT(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,getInventory(),null)); compoundNBT.put("fluid", FluidContainerStorage.FLUID_CONTAINER_CAPABILITY.getStorage().writeNBT(FluidContainerStorage.FLUID_CONTAINER_CAPABILITY,getFluid(),null)); return compoundNBT; } @Override public void deserializeNBT(INBT nbt) { if (nbt instanceof CompoundNBT) { CompoundNBT compoundNBT = (CompoundNBT)nbt; CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getStorage().readNBT(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getInventory(), null, compoundNBT.get("items")); FluidContainerStorage.FLUID_CONTAINER_CAPABILITY.getStorage().readNBT(FluidContainerStorage.FLUID_CONTAINER_CAPABILITY, getFluid(), null, compoundNBT.get("fluid")); } } @SuppressWarnings("unchecked") public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, Direction side) { if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return itemHandler.cast(); else if (cap == FluidContainerStorage.FLUID_CONTAINER_CAPABILITY) return fluidHandler.cast(); return (LazyOptional<T>) LazyOptional.empty(); } }   But when I try and fetch the capability the parameter cap seems to always be null, which means it always returns the first statement (in this case the ItemHandler) which results in a casting error.
    • DragonITA
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA · Posted 35 minutes ago

      No, you have said that i should make that modelUnicorn extends ModelEntity and not ModelHorse, but i need the AbstractHorseEntity, else the gui, animations and etc. wont work and i should rewrite the code.
    • Simon_kungen
      [1.14.4] TileEntityItemStackSpecialRenderer (TEISR)

      By Simon_kungen · Posted 40 minutes ago

      Other mods I can find add their TEISR directly in the item constructor (which crashes the server). But doing the same I at least expect it to do something while in Single Player.
    • salvestrom
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By salvestrom · Posted 53 minutes ago

      ModelUnicorn should extend ModelHorse. Everything else you want will come from your UnicornEntity class extending EntityHorse.
    • mindstorm3223
      1.12.2-Problem with tile entity custom crafting table

      By mindstorm3223 · Posted 58 minutes ago

      Sorry, I looked around and couldn't figure out how to do that, do you know of any good place where it can tell me how to?
  • Topics

    • Simon_kungen
      0
      [1.14.4] Sync ItemStack Capability Data + Multi-Capability Provider casting error

      By Simon_kungen
      Started 21 minutes ago

    • DragonITA
      26
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA
      Started Monday at 10:06 AM

    • Simon_kungen
      3
      [1.14.4] TileEntityItemStackSpecialRenderer (TEISR)

      By Simon_kungen
      Started Saturday at 02:50 PM

    • mindstorm3223
      2
      1.12.2-Problem with tile entity custom crafting table

      By mindstorm3223
      Started Yesterday at 02:18 AM

    • Jaffaaaaa
      0
      ScreenGui does nothing

      By Jaffaaaaa
      Started 1 hour ago

  • Who's Online (See full list)

    • Yanny7
    • Jaffaaaaa
    • StefanDeSterke
    • Cuz_Tobi
    • LexManos
    • Lea9ue
    • Simon_kungen
    • DragonITA
    • diesieben07
    • matorassan
    • Alpvax
    • MoeBoy76
    • DaemonUmbra
    • willydd123456
    • Arcratist
    • deerangle
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Can't get custom sounds to play
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community