Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10][SOLVED] Stopping records once started
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
coolAlias

[1.7.10][SOLVED] Stopping records once started

By coolAlias, October 11, 2014 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 11, 2014

I've been looking all over in vanilla code for how records are handled, and I'm stumped on 2 things:

 

1. Where do the records actually START playing in vanilla code?

2. How can I stop the record track once it starts without terminating all sounds?

 

So far, I've looked through BlockJukebox and its nested TileEntity, ItemRecord, the World playRecord and playAuxSFX methods, and the Client and Server NetPlayHandlers for S24PacketBlockAction and S28PacketEffect, thinking that there might have been some 'special cases' tucked away in the packet handling, but nope.

 

When ItemRecord is inserted, it plays auxiliary sound effect #1005 with the item id and sets the itemstack in the tile entity. When the record is ejected from the BlockJukebox, it plays aux #1005, with 0 as the 'id' and calls playRecord(null, x, y, z). All of that happens only on the server side, btw.

 

I suspect that the auxiliary sound effect is what's playing the record track, since nothing in BlockJukebox appears to play the record, but I can't find where aux SFX actually get handled. Not in World, WorldClient, WorldServer, packets...

 

Now, I'm playing the record on the client side for now from a Gui (I know how to broadcast via packets if I need), and I can play the record using mc.theWorld.playRecord, BUT I can't get it to stop!

 

For the x/y/z coordinates, I tried using MathHelper.floor_double of mc.thePlayer's position, as well as passing in the x/y/z from the GuiHandler when the gui is opened (which are also from the player's position). I use the same coordinates for playing the song as I do for attempting to stop it.

@Override
public void onGuiClosed() {
if (song != null) { // && ticksSinceLastNote < song.getDuration()
	LogHelper.info("Gui closed, stopping song"); // prints
	mc.theWorld.playAuxSFX(1005, x, y, z, 0); // no effect, but this is what BlockJukebox does when the disc is ejected
	mc.theWorld.playRecord((String) null, x, y, z); // no effect, but this is what BlockJukebox does when the disc is ejected
}
}

I have also sent a packet to the server making the exact same method calls (obviously NOT with mc.theWorld), but to no avail.

 

It looked so obvious when I first wrote the code, but it doesn't work at all. The record just keeps on playing. Does anyone know how the vanilla code actually works in this case?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted October 11, 2014

This is what happens when you play a record:

 

> ItemRecord#onItemUse

> World#playAuxSFXAtEntity (serverside)

> WorldManager#playAuxSFX (serverside)

> S28PacketEffect is sent to all nearby clients

> [... network stuff ...]

> World#playAuxSFX (clientside)

> RenderGlobal#playAuxSFX (clientside)

> World#playRecord (clientside)

> RenderGlobal#playRecord <-- Actually plays the sound

 

Stopping the record when it's removed works similarly. The last method in the chain should give you an idea of how to stop a sound for any Jukebox, you just need to access the private field

mapSoundPositions

in RenderGlobal.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 11, 2014

RenderGlobal... lol, of course that's where the code was hiding lol. Thanks!

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted October 11, 2014

This was very easy to find out. Learn to use your IDE ;)

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 11, 2014

This was very easy to find out. Learn to use your IDE ;)

When I searched for references, RenderGlobal#playAuxSFX never showed up, neither from World nor IWorldAccess :\

 

Nevertheless, you are right - I am not very good with my IDE. Something to work on xD

 

EDIT: Derp... opened up the type hierarchy and voilá. Lol.

 

However, I'm still confused: calling WorldClient#playRecord iterates through all the IWorldAccesses and calls playRecord, so when I call mc.theWorld.playRecord(null) it should also call RenderGlobal#playRecord(null) automatically, should it not?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted October 11, 2014

If it is a client world, yes. You only have either RenderGlobal or WorldManager as a IWorldAccess. WorldManager for a server world, RenderGlobal for a client world.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 11, 2014

Exactly - WorldManager sends packets, RenderGlobal actually plays the record.

 

In my Gui#keyTyped, I call 'mc.theWorld.playRecord("records.cat", x, y, z);', then in #onGuiClosed(), I call 'mc.theWorld.playAuxSFX(1005, x, y, z, 0);' and 'mc.theWorld.playRecord((String) null, x, y, z);', but the record keeps playing.

 

Pastebin of Gui code; don't mind the ZeldaSongPacket - it doesn't play the record again.

 

Thanks for the help so far.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted October 11, 2014

I can't see anything wrong with that.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 11, 2014

Glad it's not just me xD

 

So I went ahead and created my own mapped sound positions in my ClientProxy to see more closely what's going on. Now it gets even more interesting - the sound is found playing at the position, but calling 'stopSound(isound)' does not stop it! SoundHandler#stopSounds() works, with the downside that it will stop all other sounds from playing at the same time.

 

Code:

 

// In GuiOcarina#onGuiClosed: replaced vanilla mc.theWorld method calls with this:
ZSSMain.proxy.playRecord(null, x, y, z);

// And starting the music with:
ZSSMain.proxy.playRecord("records.cat", x, y, z);

// in ClientProxy
/** Map of all custom streaming sounds for this client. See RenderGlobal#mapSoundPositions */
private final Map<ChunkCoordinates, ISound> mapSoundPositions = new HashMap<ChunkCoordinates, ISound>();

@Override
public void playRecord(String sound, int x, int y, int z) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(x, y, z);
ISound isound = mapSoundPositions.get(chunkcoordinates);
if (isound != null) {
	LogHelper.info("Sound already playing at " + x + "/" + y + "/" + z + "; stopping sound");
	Minecraft.getMinecraft().getSoundHandler().stopSounds();//.stopSound(isound);
	mapSoundPositions.remove(chunkcoordinates);
}
if (sound != null) {
	LogHelper.info("Playing sound at " + x + "/" + y + "/" + z + ": " + sound);
	ResourceLocation resource = new ResourceLocation(sound);
	PositionedSoundRecord psr = PositionedSoundRecord.func_147675_a(resource, x, y, z);
	mapSoundPositions.put(chunkcoordinates, psr);
	Minecraft.getMinecraft().getSoundHandler().playSound(psr);
}
}

 

 

Console Output is as expected:

[11:15:33] [ZeldaSwordSkills] [iNFO] Playing record on client
[11:15:33] [ZeldaSwordSkills] [iNFO] Playing sound at -417/74/838: records.cat
[11:15:35] [ZeldaSwordSkills] [iNFO] Song finished - closing screen
[11:15:35] [ZeldaSwordSkills] [iNFO] Gui closed, stopping song
[11:15:35] [ZeldaSwordSkills] [iNFO] Sound already playing at -417/74/838; stopping sound

 

I'm very confused why the vanilla code works, but me using what seems to be the same code fails. As far as I can tell, it should be doing exactly the same thing.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted October 11, 2014

Yeah, that seems weird. The Code in SoundManager looks correct.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 11, 2014

It sure does - I even checked if Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(isound) is returning true in my client proxy method just now, and it does; judging from the SoundManager isSoundPlaying and stopSound methods, this should be enough to guarantee that the sound system is able to stop it.

 

EDIT: Okay, after listening carefully, the record IS stopping, but immediately starts playing again, whether using my custom method or the vanilla one... curiouser and curiouser :\  I'm 100% sure that I'm not playing the record anywhere else, but I'm going to look again anyway. So bizarre.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 11, 2014

I tried replacing the playRecord calls in my gui like so:

private ISound songTrack;

// trigger song:
songTrack = PositionedSoundRecord.func_147675_a(new ResourceLocation("records.mall"), x, y, z);
mc.getSoundHandler().playSound(songTrack);

// turn it off:
mc.getSoundHandler().stopSound(songTrack);

This has the exact same behavior as everything else - the music stops but immediately restarts from the beginning, even though I'm not playing the sound from anywhere else and the gui has closed. Any ideas why it might be doing this?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45730 posts
Posted October 11, 2014

I would not think it would play twice, but just add a breakpoint to be sure.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 12, 2014

Turns out that it IS playing twice, but not in the way one might think.

 

What's happening is that the sound system sends the stop notification, but the sound entry is still in the playingSounds Map - after the Gui closes in Minecraft#displayGuiScreen, it calls SoundHandler#resumeSounds -> SoundMananger#resumeAllSounds and finds the entry still there, for which it then calls SoundSystem#play.

 

I'm not exactly sure how "CommandQueue( new CommandObject( CommandObject.STOP, sourcename) );" works, but for whatever reason it is either not executing properly or something else is going awry.

 

The only thing in my code different from vanilla that I can see is I'm trying to stop the sound from a Gui and the game resumes sounds after it closes, so I'm going to try sending a packet back and forth to stop the sound instead of doing it from inside the Gui. StopAllSounds clears all of the sound maps, which is why it works no matter what.

 

I shall post back with results of my experiment shortly. Thanks again for helping out ;)

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted October 12, 2014

Worked like a charm! Sent a packet when the Gui closes, then replied back to the client and shut the sound down from there. Thanks for getting me to use my IDE :D

  • Quote

Share this post


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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Oliviafrostpaw
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By Oliviafrostpaw · Posted 11 minutes ago

      After some poking, the function is not firing whatsoever
    • RaphGamingz
      [1.14.4] Dimensions

      By RaphGamingz · Posted 1 hour ago

      Anyone?
    • RaphGamingz
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By RaphGamingz · Posted 1 hour ago

      Are you sure this is correct, shouldn’t it be  new ResourceLocation(“minecraft”,”grass”) And is the function firing?
    • mervinrasquinha
      Introducing Stonecage

      By mervinrasquinha · Posted 3 hours ago

      If you’re interested in a modpack with a little bit of tech, a little bit of magic, and a lot of adventure, I would love for you to try out my modpack Stonecage. Stonecage takes mods you might have seen before (and many you might not have), and adds a twist to them to make them fresh again. The main gimmick of the pack is that it makes stone unmineable, meaning you’ll have to explore caves and dungeons the way they were intended, and find solutions to problems you never knew existed. It aims to be a hardcore pack that’s more fair than most, and leaves you to seek combat and adventure on your own terms. While you may start out weak, you’ll find magical artifacts known as curios in your adventures that can be crafted into powerful baubles that will help you in combat and elsewhere. You’ll also find pieces of ancient machines that with research can be deciphered and put back together, bringing industry back to a world that has long been without it. The pack is heavily centered around researching these lost machines, and the research table will guide you through the modpack while giving you more freedom than a quest book would. With a small, curated list of mods, most computers will likely be able to run it, and the many, many lines of scripting keep these mods integrated into what feels like a cohesive whole. If this sounds like fun to you, I encourage you to check it out. If you do, I hope you have as much fun playing it as I did creating it.
    • Darth_Cobalt
      Forge 1.14.4 crashes.

      By Darth_Cobalt · Posted 4 hours ago

      Hi I just downloaded forge and every time i try to load it, it crashes. I have tried 1.14.4 - 28.1.0 and 1.14.4 - 28.1.106. It crashes with both versions. I couldn't figure out how to upload the crash files, could somebody explain how I can do that?
  • Topics

    • Oliviafrostpaw
      7
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By Oliviafrostpaw
      Started December 8

    • RaphGamingz
      1
      [1.14.4] Dimensions

      By RaphGamingz
      Started Yesterday at 07:45 AM

    • mervinrasquinha
      0
      Introducing Stonecage

      By mervinrasquinha
      Started 3 hours ago

    • Darth_Cobalt
      0
      Forge 1.14.4 crashes.

      By Darth_Cobalt
      Started 4 hours ago

    • leonardsores
      0
      Fun mod interactions

      By leonardsores
      Started 4 hours ago

  • Who's Online (See full list)

    • Oliviafrostpaw
    • xerca
    • Redstoneguy129
    • Raelsyl
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10][SOLVED] Stopping records once started
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community