Jump to content

Recommended Posts

Posted

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?

Posted

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?

Posted

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.

Posted

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.

Posted

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.

Posted

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?

Posted

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 ;)

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

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • Fastfund recovery helps an individual to get back their scammed funds irrespective of nationality, Romance scam funds and Broker's scam, all kinds of scam funds are 100% accurately recovered without disappointment, their goal is to give all those who seek help to recover lost satisfaction of funds recovery within 72 hours After countless hours of research and desperate attempts to find a solution, I stumbled upon FASTFUND RECOVERY. It was like finding an oasis in the middle of a desert. Their website promised to help victims of scams reclaim what was rightfully theirs, and I instantly knew I had to give them a shot. Before diving headfirst into the recovery process, I wanted to make sure that FASTFUND RECOVERY was the real deal. So, I did my due diligence and looked into their expertise and reputation. To my relief, I found that they had an impeccable track record, successfully assisting countless individuals in recovering their lost funds. Their team consisted of experts in cybersecurity and financial fraud, armed with the knowledge and tools needed to tackle even the most intricate scams. With their reputation preceding them, I felt a renewed sense of hope. FASTFUND RECOVERY successfully came to my aid and got back the amount I lost to these scammers and for this, I am sending this article for clarification. The info of FASTFUND RECOVERY is email: Fastfundrecovery8 (@)Gmail (.) com. Web fastfundrecovery(.)com. (W/A 1 807/500/7554)
  • Topics

×
×
  • Create New...

Important Information

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