Jump to content

Recommended Posts

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

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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