I have an issue with audio playback in my mod.
First I created a SoundEvents Class
public class SoundEvents
{
@ForgeSubscribe
public void onSound(SoundLoadEvent e)
{
URL u=DirtyMod.class.getResource(CommonProxy.FURNACE_SOUND);
if(u!=null)
{
e.manager.soundPoolSounds.addSound(CommonProxy.FURNACE_SOUNDID, u);
System.out.println(CommonProxy.FURNACE_SOUND+" registered as "+u.toString());
}
else
{
System.out.println(CommonProxy.FURNACE_SOUND+" not found");
}
}
}
I then call it in my PreInit function with
MinecraftForge.EVENT_BUS.register(new SoundEvents());
I then created a packet handler. whenever I place a dirtfurnace the coords are transferred to the player placing the furnace.
The receiver end looks like the folowing:
public class PacketHandler implements IPacketHandler
{
@Override
@SideOnly(Side.CLIENT)
public void onPacketData(INetworkManager manager,Packet250CustomPayload packet, Player player)
{
int x,y,z;
World w;
EntityClientPlayerMP p;
if (packet.channel.equals("DirtyNetwork"))
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
try
{
x=inputStream.readInt();
y=inputStream.readInt();
z=inputStream.readInt();
p = (EntityClientPlayerMP) player;
w=p.worldObj;
w.playSoundEffect((double)x+0.5D,(double)y+0.5D,(double)z+0.5D,CommonProxy.FURNACE_SOUNDID,1.0F,w.rand.nextFloat()*.1F+0.9F);
System.out.println("FURNACE!!! "+x+","+y+","+z);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
the folowing constants are defined in my CommonProxy class:
public static final String FURNACE_SOUND= "/ayra/dirtyMod/furnace.ogg";
public static final String FURNACE_SOUNDID="ayra.dirtyMod.furnace";
My issue is, that the sound is not playing. The initialization function gets called. The output to the console looks like this:
/ayra/dirtyMod/furnace.ogg registered as file:/D:/Programme/Games/minecraft/develop/1.4.7/forge/mcp/eclipse/Minecraft/bin/ayra/dirtyMod/furnace.ogg
The ogg file exists at the specified location.
The placement function also gets called because the receiver function outputs to the console:
FURNACE!!! -43,74,308
There is no error printed to the console.
Does somebody know how to correctly do this? I also tried using a .wav file.