Oh, by the way for anyone else doing this (looping audio), I solved the resource retention issue the simpler way in the end.
A keyed registry seemed like overkill and there's already a Minecraft ITickableSound interface the sound manager checks for.
You just need to implement isDonePlaying on the PositionedSound object and in that check back with the parent TileEntity.
The only thing that annoys me about the solution is the call to GetTileEntity() each sound manager tick - seems like overkill.
A quick guide to looping audio in 1.7.10 - in so far as it works for me.
Define this and Implement it on your Tile Entity.
public interface IShouldLoop {
boolean continueLoopingAudio();
}
Create this class.
public class LoopingSound extends PositionedSound implements ITickableSound {
private int x,y,z;
private boolean shouldBePlaying = true;
public LoopingSound(ResourceLocation resource,TileEntity parent) {
super(resource);
repeat = true;
xPosF = parent.xCoord+0.5f;
yPosF = parent.yCoord+0.5f;
zPosF = parent.zCoord+0.5f;
x = parent.xCoord;
y = parent.yCoord;
z = parent.zCoord;
}
@Override
public void update() {
}
@Override
public boolean isDonePlaying() {
if (shouldBePlaying)
{
// we should only be playing if parent still exists and says we are playing - assume not
shouldBePlaying = false;
// should never be here on the server, but just in case
World world = Minecraft.getMinecraft().theWorld;
if (world.isRemote)
{
TileEntity parent = world.getTileEntity(x, y, z);
if (parent != null)
{
if (parent instanceof IShouldLoop)
{
IShouldLoop iShouldLoop = (IShouldLoop)parent;
shouldBePlaying = iShouldLoop.continueLoopingAudio();
}
}
}
}
return !shouldBePlaying;
}
}
You kick the loop off like this (has to be client side obviously).
ResourceLocation audioLoop = new ResourceLocation("mymod","loopname");
LoopingSound myLoop = new LoopingSound(audioLoop,this);
Minecraft.getMinecraft().getSoundHandler().playSound(myLoop);
The sound files are specified the same way you'd do normal one shot audio, i.e. they go in assets/mymod/sounds/ (use .ogg format)
Create a sounds.json in assets/mymod - use the format of the minecraft one as a template or use something like this.
{
"loopname": {
"category": "master",
"sounds": [
"loopname"
]
},
"bigswitch": {
"category": "master",
"sounds": [
"bigswitch"
]
}
}