Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.