Jump to content

richfell

Members
  • Posts

    4
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

richfell's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. OK, thank you for that LexManos! Works great now.
  2. I want to access my assets/MODID/sounds.json file during runtime to parse out some info while handling a command in my mod's ICommand implementor. So there is this bit of code that accesses the JSON file as a stream: java.io.InputStream in = ClassLoader.getSystemClassLoader().getSystemResourceAsStream("assets/MODID/sounds.json"); Works fine when run in the debugger (I'm using eclipse IDE) but does not work in the actual game runtime environment. I also tried using: FMLClientHandler.instance().getResourcePackFor(ModInfo.ID).getInputStream(new ResourceLocation("assets/MODID/sounds.json")); which also did not work. Does anyone know how to access my files in the assets/ area at runtime?
  3. Thank you coolAlias. EntityPlayerSP.playSound is what I needed to get it working. In this case I only want the one player hearing the sound, so that method is perfect. I will send you some karma (assuming I can figure out how ).
  4. I have a small mod that I want to be client-side only. I want the mod to play a short sound when some matching text is seen in the player's chat. I have the mod working when in single player mode (even when it is "opened to LAN") but when I connect to a server on another host the sound is not heard. I have a class which receives ClientChatReceivedEvent events. In the event handler method I play the sound if the text matches what I am looking for: public class ChatEventHandler { net.minecraft.world.World worldClient; @SubscribeEvent @SideOnly(Side.Client) public void onChatMessage(ClientChatReceivedEvent) { // check for matching text if(event.message.getUnformattedText.beginsWith("blabla")) { EntityClientPlayer player = Minecraft.getMinecraft().thePlayer; if(worldClient != null) worldClient.playSoundAtEntity(player, "mymod:chatsound", 1.0f, 1.0f); else player.worldObj.playSoundAtEntity(player, "mymod:chatsound", 1.0f, 1.0f); } } @SubscribeEvent @SideOnly(Side.Client) public void onWorldEvent(WorldEvent.Load event) { if((event.world != null) && !event.world.isRemote) worldClient = event.world; } } When the onWorldEvent handler is called and the worldClient member gets set with a world that is not remote then the sound plays. That is what happens when in single player mode. When I connect to a remote server worldClient never gets set and Minecrat.thePlayer.worldObj is used to play the sound. That world instance is remote and that is (I believe) where the problem is. So is there a consistent way to play a short sound on the client?
×
×
  • Create New...

Important Information

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