Jump to content

[1.7.10][Solved]Sound start from a coordinate and stopping it, server-wide


Filloax

Recommended Posts

To be more clear, I'm trying to make a playsound alternative that is also able to stop the sound from a coordinate (if it has been started by the same command) and loop it.

 

I managed to make the start/stop thing for now, but it only on cient side. Any help on how to make it work for other players?

 

Code of the play sound part:

In the command:
   Main.proxy.playSoundFromCoords(sound, x, y, z, vol, pitch);

In the client proxy:
    private final Map<ChunkCoordinates, ISound> mapSoundPositions = new HashMap<ChunkCoordinates, ISound>();    
    
    @Override
    public void playSoundFromCoords(String sound, int x, int y, int z, float vol, float pitch) {
    	ChunkCoordinates chunkcoordinates = new ChunkCoordinates(x, y, z);
    	ISound isound = mapSoundPositions.get(chunkcoordinates);
    	if (isound != null) {
    		System.out.println("Sound already playing at " + x + "/" + y + "/" + z + "; stopping sound");
    		Minecraft.getMinecraft().getSoundHandler().stopSound(isound);
    		mapSoundPositions.remove(chunkcoordinates);
    	}
    	if (sound != null) {
    		System.out.println("Playing sound at " + x + "/" + y + "/" + z + ": " + sound);
    		ResourceLocation resource = new ResourceLocation(sound);
    		PositionedSoundRecord psr = new PositionedSoundRecord(resource, vol, pitch, x, y, z);
    		mapSoundPositions.put(chunkcoordinates, psr);
    		Minecraft.getMinecraft().getSoundHandler().playSound(psr);
    	}
    }

 

Edit: forgot to say that the code mostly comes from this thread:http://www.minecraftforge.net/forum/index.php?topic=24230.0

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.