Jump to content

Get pitch of sound causes NullPointerException


leduyquang753

Recommended Posts

So I am working on my project NBS Recorder for 1.12 and I need to get the pitch of sounds in order to record them. However, when I try getting the pitch of a sound on PlaySoundEvent:

event.getSound().getPitch()

it fires NullPointerException:

[14:10:57] [main/ERROR] [FML]: Exception caught during firing event net.minecraftforge.client.event.sound.PlaySoundEvent@7e4594ac:
java.lang.NullPointerException: null
	at net.minecraft.client.audio.PositionedSound.getPitch(PositionedSound.java:90) ~[PositionedSound.class:?]
	at cf.leduyquang753.nbsrecorder.Events.onSound(Events.java:47) ~[Events.class:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_13_Events_onSound_PlaySoundEvent.invoke(.dynamic) ~[?:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?]
	at net.minecraftforge.client.ForgeHooksClient.playSound(ForgeHooksClient.java:353) [ForgeHooksClient.class:?]
	at net.minecraft.client.audio.SoundManager.playSound(SoundManager.java:375) [SoundManager.class:?]
	at net.minecraft.client.audio.SoundHandler.playSound(SoundHandler.java:261) [SoundHandler.class:?]
	at net.minecraft.client.multiplayer.WorldClient.playSound(WorldClient.java:518) [WorldClient.class:?]
	at net.minecraft.client.multiplayer.WorldClient.playSound(WorldClient.java:497) [WorldClient.class:?]
	at net.minecraft.client.network.NetHandlerPlayClient.handleSoundEffect(NetHandlerPlayClient.java:1828) [NetHandlerPlayClient.class:?]
	at net.minecraft.network.play.server.SPacketSoundEffect.processPacket(SPacketSoundEffect.java:78) [SPacketSoundEffect.class:?]
	at net.minecraft.network.play.server.SPacketSoundEffect.processPacket(SPacketSoundEffect.java:13) [SPacketSoundEffect.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) [PacketThreadUtil$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_131]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_131]
	at net.minecraft.util.Util.runTask(Util.java:53) [Util.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1176) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]

 

I'm so confused now because this is the only way to record sounds for my mod (maybe not)...

Link to comment
Share on other sites

Uhhh, I'm confused because the ISoundEventListener class seems to be having only one method which maybe used to trigger the event:

void soundPlay(ISound soundIn, SoundEventAccessor accessor);

Did you tell me to hook up to something related to this?

I need these things when a sound is played: The name and the pitch of the sound.

Edited by leduyquang753
More info.
Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

Those can be obtained from the ISound instance given to the method.

But, there aren't anything to retrieve from the ISoundEventListener class or soundPlay method? The whole class is just...

package net.minecraft.client.audio;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public interface ISoundEventListener
{
    void soundPlay(ISound soundIn, SoundEventAccessor accessor);
}

and nothing else?

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.