Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey, guys.

I'm trying to play a sound in a mod, which is client-only.

It works fine with single-player saves, but when trying to use in on a real multiplayer server (without installing the mod on server of course), I'm getting a crash:

Quote

java.lang.NullPointerException: Registry Object not present: trovogration:cooldown_end
    at java.util.Objects.requireNonNull(Objects.java:334) ~[?:?] {re:mixin}
    at net.minecraftforge.registries.RegistryObject.get(RegistryObject.java:320) ~[forge-1.18.2-40.1.92-universal.jar%23301!/:?] {re:mixin,xf:fml:forge:registry_object_binary_compat,re:classloading,xf:fml:forge:registry_object_binary_compat}

Here's the code:

Registration:

public class Sounds {
    public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, TrovoGration.MOD_ID);
    public static final RegistryObject<SoundEvent> SOUND_ACTION_NEGATIVE = SOUNDS.register("negative_action", () -> new SoundEvent(new ResourceLocation(TrovoGration.MOD_ID,"negative_action")));
    public static final RegistryObject<SoundEvent> SOUND_ACTION_POSITIVE = SOUNDS.register("positive_action", () -> new SoundEvent(new ResourceLocation(TrovoGration.MOD_ID,"positive_action")));
    public static final RegistryObject<SoundEvent> SOUND_COOLDOWN_START = SOUNDS.register("cooldown_start", () -> new SoundEvent(new ResourceLocation(TrovoGration.MOD_ID,"cooldown_start")));
    public static final RegistryObject<SoundEvent> SOUND_COOLDOWN_END = SOUNDS.register("cooldown_end", () -> new SoundEvent(new ResourceLocation(TrovoGration.MOD_ID,"cooldown_end")));
}

Main class constructor:

    public TrovoGration(){
        Sounds.SOUNDS.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

Play code:

LocalPlayer player ... ;
player.playSound(Sounds.SOUND_ACTION_NEGATIVE.get(), 0.7f, 1.0f);

sounds.json:

{
  "positive_action": {
	"category": "record",
    "subtitle": "trovogration.subtitle.positive_action",
    "sounds": [ "trovogration:positive_action" ]
  },
  "negative_action": {
	"category": "record",
    "subtitle": "trovogration.subtitle.negative_action",
    "sounds": [ "trovogration:negative_action" ]
  },
  "cooldown_start": {
	"category": "record",
    "subtitle": "trovogration.subtitle.cooldown_start",
    "sounds": [ "trovogration:cooldown_start" ]
  },
  "cooldown_end": {
	"category": "record",
    "subtitle": "trovogration.subtitle.cooldown_end",
    "sounds": [ "trovogration:cooldown_end" ]
  }  
}

Help!!

Edited by ZigTheHedge
Solved

From what I understand (which might be incorrect, I am not an expert on this),

it doesn't use the local client registry for those registries that have data sent from a multiplayer server.

SoundEvents is one of those registries.

So in multiplayer your SoundEvent effectively won't exist unless it is also registered on the server?

 

The logic can be found here (and its related methods):

https://github.com/MinecraftForge/MinecraftForge/blob/bb49b9e6dc7525ae0fa935abf6eec18b36091bd6/src/main/java/net/minecraftforge/registries/GameData.java#L656

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

You might be able to make it work by using the sound directly?

i.e. something like:

        SoundInstance sound = new SimpleSoundInstance(...);
        Minecraft.getInstance().getSoundManager().play(sound);

But I guess you would need to use an AccessTransformer to make the SimpleSoundInstance constructor that takes a ResourceLocation instead of a SoundEvent publicly accessible.

https://forge.gemwire.uk/wiki/Access_Transformers

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

There's a public constructor in SimpleSoundInstance )

Well, I've changed a code to use direct SoundInstance, big-fat Thank You for the suggestion ) Now it's time to test it in a multiplayer. I'll reply back.

  • ZigTheHedge changed the title to [SOLVED][1.18.2] Playing sound with client-only mod

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.