Jump to content

Looping TileEntity sound


Jwosty

Recommended Posts

I'm trying to play a sound for a custom tile entity for its whole existence. Minecraft doesn't do many constantly looping sounds; the only instances of this in action (that I can find) are MovingSoundMinecart and MovingSoundMinecartRiding. I've come up with the following class based on the vanilla code, mainly only changing it to use a tile entity instead of an entity:

 

public class LoopableTileEntitySound extends PositionedSound implements ITickableSound {
protected boolean donePlaying = false;
private TileEntity tileEntity; 

public LoopableTileEntitySound(ResourceLocation path, TileEntity tileEntity, float volume, float pitch) {
	super(path);
	this.repeat = true;
	this.tileEntity = tileEntity;
	this.volume = volume;
	this.field_147663_c = pitch;
	this.xPosF = tileEntity.xCoord;
	this.yPosF = tileEntity.yCoord;
	this.zPosF = tileEntity.zCoord;
	this.field_147665_h = 0;
}

public LoopableTileEntitySound(String path, TileEntity tileEntity, float volume, float pitch) {
	this(new ResourceLocation(path), tileEntity, volume, pitch);
}

@Override
public void update() {	
	if (this.tileEntity.isInvalid()) {
		this.donePlaying = true;
	}
}

@Override
public boolean isDonePlaying() {
	return this.donePlaying;
}
}

 

Here's how I use it -- it starts when this custom block is added into the world:

 

@Override
public void onBlockAdded(World world, int x, int y, int z) {
	if (!world.isRemote) { 
		TileEntity tileEntity = world.getTileEntity(x, y, z);
		ISound eventHorizonSound = new LoopableTileEntitySound(CommonProxy.MOD_ID + ":stargate.eventhorizon", tileEntity, 0.1F, 1);
		Minecraft.getMinecraft().getSoundHandler().playSound(eventHorizonSound);
	}
}

 

However, the following error crashes the game:

 

java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859)
at java.util.ArrayList$Itr.next(ArrayList.java:831)
at net.minecraft.client.audio.SoundManager.updateAllSounds(SoundManager.java:245)
at net.minecraft.client.audio.SoundHandler.update(SoundHandler.java:222)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2111)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1036)
at net.minecraft.client.Minecraft.run(Minecraft.java:951)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

And the game doesn't crash and the sound loops until you exit to the main menu if I don't call

this.tileEntity.isInvalid()

in the update() method. Any idea what's going on here?

I like to make mods, just like you. Here's one worth checking out

Link to comment
Share on other sites

Right, really stupid mistake. I guess I'm just used to checking for server side... :P

But is seems that Block#onBlockAdded is only executed on the server and never the client (I've confimed this through the Minecraft source).

 

EDIT: Block#onPostBlockPlaced executed both server and client side, but I realized it only works for blocks placed by an entity, which makes sense. Do you know of any ways for the client side to handle when a block is placed? It's almost like everything but this is executed on both server _and_ client.

I like to make mods, just like you. Here's one worth checking out

Link to comment
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.
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.