Jump to content

[1.11] playSound crashes game. Null pointer exception in PositionedSoundRecord class


Recommended Posts

Posted

Hey everyone,

 

Having trouble loading my custom sound using the playSound method in code. My sound loads completely fine when I use /playsound in-game, but as soon as the playSound method gets called, the game crashes. Really not sure why. I should have everything registered correctly, as the sound does actually play when using commands.

 

Common Proxy:

public class CommonProxy {
    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event){
        RegistryEventHandler.registerSounds();
    }
}

 

Registry Event Handler: ( Courtesy of @Choonster TestMod3 code )

@Mod.EventBusSubscriber
public class RegistryEventHandler {
    public static SoundEvent infused_log_ambient;

    public static void registerSounds() {
        infused_log_ambient = registerSound("infused_log_ambient");
    }

    private static SoundEvent registerSound(String sound) {
        Utils.getLogger().info(sound + " loaded");
        final ResourceLocation soundID = new ResourceLocation(Reference.MODID, sound);
        return GameRegistry.register(new SoundEvent(soundID).setRegistryName(soundID));
    }
}

 

Play Sound called in this class:

public class ItemSpiritBase extends ItemBase {


    public ItemSpiritBase(String name) {
        super(name);
    }

    protected void conversionDisplay(World world, BlockPos pos) {
        if(world.isRemote) {
            world.playSound(pos.getX(), pos.getY(), pos.getZ(), RegistryEventHandler.infused_log_ambient, SoundCategory.BLOCKS, 1.0f, 1.0f, false);
        }
    }
}

 

conversionDisplay() is called from here:

@Override
    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        Utils.getLogger().info("Used item!");
        if(worldIn.getBlockState(pos) == Blocks.LOG.getDefaultState() || worldIn.getBlockState(pos) == Blocks.LOG2.getDefaultState()) {
            Utils.getLogger().info("Log test worked!");
            conversionDisplay(worldIn, pos);
            worldIn.setBlockState(pos, ModBlocks.zombie_infused_log.getDefaultState());
        }

        return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    }

 

Sooo yeah, game crashes as soon as I R-click on the MC logs. Definitely because of the playSound() method.

 

CRASH REPORT:

Spoiler

[02:03:50] [Client thread/FATAL]: Unreported exception thrown!
java.lang.NullPointerException
    at net.minecraft.client.audio.PositionedSoundRecord.<init>(PositionedSoundRecord.java:40) ~[PositionedSoundRecord.class:?]
    at net.minecraft.client.audio.PositionedSoundRecord.<init>(PositionedSoundRecord.java:35) ~[PositionedSoundRecord.class:?]
    at net.minecraft.client.multiplayer.WorldClient.playSound(WorldClient.java:504) ~[WorldClient.class:?]
    at io.github.mspacedev.items.spirits.ItemSpiritBase.conversionDisplay(ItemSpiritBase.java:24) ~[ItemSpiritBase.class:?]
    at io.github.mspacedev.items.spirits.ItemZombieSpirit.onItemUse(ItemZombieSpirit.java:32) ~[ItemZombieSpirit.class:?]
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:180) ~[ItemStack.class:?]
    at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:489) ~[PlayerControllerMP.class:?]
    at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1606) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2276) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2053) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1841) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:407) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_144]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144]
    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_144]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_144]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]
[02:03:50] [Client thread/INFO]: [net.minecraft.init.Bootstrap:printToSYSOUT:600]: ---- Minecraft Crash Report ----
// Don't do that.

Time: 12/20/17 2:03 AM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
    at net.minecraft.client.audio.PositionedSoundRecord.<init>(PositionedSoundRecord.java:40)
    at net.minecraft.client.audio.PositionedSoundRecord.<init>(PositionedSoundRecord.java:35)
    at net.minecraft.client.multiplayer.WorldClient.playSound(WorldClient.java:504)
    at io.github.mspacedev.items.spirits.ItemSpiritBase.conversionDisplay(ItemSpiritBase.java:24)
    at io.github.mspacedev.items.spirits.ItemZombieSpirit.onItemUse(ItemZombieSpirit.java:32)
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:180)
    at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:489)
    at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1606)
    at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2276)
    at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2053)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1841)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119)
    at net.minecraft.client.Minecraft.run(Minecraft.java:407)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:26)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
    at net.minecraft.client.audio.PositionedSoundRecord.<init>(PositionedSoundRecord.java:40)
    at net.minecraft.client.audio.PositionedSoundRecord.<init>(PositionedSoundRecord.java:35)
    at net.minecraft.client.multiplayer.WorldClient.playSound(WorldClient.java:504)
    at io.github.mspacedev.items.spirits.ItemSpiritBase.conversionDisplay(ItemSpiritBase.java:24)
    at io.github.mspacedev.items.spirits.ItemZombieSpirit.onItemUse(ItemZombieSpirit.java:32)
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:180)
    at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:489)
    at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1606)
    at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2276)
    at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2053)

-- Affected level --
Details:
    Level name: MpServer
    All players: 1 total; [EntityPlayerSP['MSpaceDev'/0, l='MpServer', x=-631.67, y=4.00, z=-448.33]]
    Chunk stats: MultiplayerChunkCache: 2401, 2401
    Level seed: 0
    Level generator: ID 01 - flat, ver 0. Features enabled: false
    Level generator options: 
    Level spawn location: World: (-718,4,-505), Chunk: (at 2,0,7 in -45,-32; contains blocks -720,0,-512 to -705,255,-497), Region: (-2,-1; contains chunks -64,-32 to -33,-1, blocks -1024,0,-512 to -513,255,-1)
    Level time: 632139 game time, 18000 day time
    Level dimension: 0
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
    Forced entities: 1 total; [EntityPlayerSP['MSpaceDev'/0, l='MpServer', x=-631.67, y=4.00, z=-448.33]]
    Retry entities: 0 total; []
    Server brand: fml,forge
    Server type: Integrated singleplayer server
Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:456)
    at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2774)
    at net.minecraft.client.Minecraft.run(Minecraft.java:436)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:26)

 

 

Posted (edited)

Awesome, got it working fine now. Thank you.

 

    public static SoundEvent infused_log_ambient;
    private static final ResourceLocation infusedLogAmbientRL = new ResourceLocation(Reference.MODID, "blocks.infused_log_ambient");

    @SubscribeEvent
    public static void registerSounds(RegistryEvent.Register<SoundEvent> event) {
        infused_log_ambient = new SoundEvent(infusedLogAmbientRL).setRegistryName(infusedLogAmbientRL);
        registerSound(infused_log_ambient, event);
    }

    private static void registerSound(SoundEvent soundID, RegistryEvent.Register<SoundEvent> event) {
        Utils.getLogger().info(soundID + " loaded");
        event.getRegistry().register(soundID);
    }

 

Edited by MSpace-Dev

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.