Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

SoundHandler.playSound(ISound) not doing anything


PlanetTeamSpeak
 Share

Recommended Posts

I have made a class implementing ISound, but when I try to play it with Minecraft.getMinecraft().getSoundHandler().playSound(new EasterEgg()), nothing happens not even an error in the console saying the sound doesn't exist.

EasterEgg.java:

package com.ptsmods.morecommands.miscellaneous;

import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.Sound;
import net.minecraft.client.audio.SoundEventAccessor;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;

public class EasterEgg implements ISound {

	private ResourceLocation location;
	private SoundEventAccessor soundEvent;
	private Sound sound;

	public EasterEgg() {
		location = new ResourceLocation("morecommands:easteregg");
		try {
			createAccessor(Minecraft.getMinecraft().getSoundHandler());
		} catch (Throwable e) {}
	}

	@Override
	public ResourceLocation getSoundLocation() {
		return location;
	}

	@Override
	public SoundEventAccessor createAccessor(SoundHandler handler) {
		soundEvent = handler.getAccessor(location);

		if (soundEvent == null)
			sound = SoundHandler.MISSING_SOUND;
		else
			sound = soundEvent.cloneEntry();

		return soundEvent;
	}

	@Override
	public Sound getSound() {
		return sound;
	}

	@Override
	public SoundCategory getCategory() {
		return SoundCategory.PLAYERS;
	}

	@Override
	public boolean canRepeat() {
		return true;
	}

	@Override
	public int getRepeatDelay() {
		return 10;
	}

	@Override
	public float getVolume() {
		return 100;
	}

	@Override
	public float getPitch() {
		return 0;
	}

	@Override
	public float getXPosF() {
		return 0;
	}

	@Override
	public float getYPosF() {
		return 0;
	}

	@Override
	public float getZPosF() {
		return 0;
	}

	@Override
	public AttenuationType getAttenuationType() {
		return AttenuationType.LINEAR;
	}

}

Sounds.json:

{
  "easteregg": {
    "category": "players",
    "sounds": [
      {
        "name": "morecommands:easteregg",
        "stream": true
      }
    ]
  }
}

 

Edited by PlanetTeamSpeak
Link to comment
Share on other sites

I was able to play the sound without registering it, but somehow it broke, do you have any clues on how to register sounds though? I couldn't find how to do it in 1.12

Edit:

The mod is actually meant for 1.11 up until 1.12.1, it's just commands so it works on all version mentioned.

Edited by PlanetTeamSpeak
Link to comment
Share on other sites

I've never worked with 1.12 before.

 

But are you calling playSound on client side?

 

you can also try just calling the sound like so.

ResourceLocation local = new ResourceLocation("morecommands:easteregg");
SoundEvent event = new SoundEvent(local);

Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(event, SoundCategory.BLOCKS, 1.0f, 1.0f, new BlockPos(0, 0, 0)));
Edited by SuperHB
Link to comment
Share on other sites

Doing some research, this is how you would register sounds in 1.12: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/2cb7b67adf7ab41e066c3308ac898224b2891752/src/main/java/choonster/testmod3/init/ModSoundEvents.java

 

I'm pretty sure you have to call the registry from preInit (maybe) but it doesn't seem to be from the example.

 

Based on the example linked, I'm guessing you will have to call the registered soundevent like so

Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(ModSoundEvents.RECORD_SOLARIS, SoundCategory.BLOCKS, 1.0f, 1.0f, playerPos));

Hope this helps. If it doesn't, then my help ends here as I haven't worked with 1.12 yet.

Edited by SuperHB
Link to comment
Share on other sites

13 hours ago, SuperHB said:

I'm pretty sure you have to call the registry from preInit (maybe) but it doesn't seem to be from the example.

 

You don't. That code uses registry events, which Forge fires when each registry is ready to receive registrations.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • So I've gotten this error and I tried fixing it the way another form did, but it came with no success and I am truly lost as this isn't well documented. Doing `gradlew build` shows: My gradlew path is the following: C:/     Gradle         bin         docs         init.d         lib         src         LICENSE         NOTICE         README The bin is added to the system environment variables "Path" list.   Any help? Thanks!
    • I downloaded the Forge Server Installer and installed the server to my root directory, then I tried to launch the server and got nothing but a log file, it did not even generate the files. This is all that is in the log files, I am running the latest Java 8 version and JDK 17 version (Adoptium Temurin 17 LTS). // Debug.txt [28Jan2022 17:09:25.344] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [28Jan2022 17:09:25.346] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.2 by Eclipse Adoptium [28Jan2022 17:09:25.354] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [minecraft,testharness,fmlclient,fmlserver] // Latest.txt [28Jan2022 17:09:25.344] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [28Jan2022 17:09:25.346] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.2 by Eclipse Adoptium  
    • Here is the log file https://drive.google.com/file/d/1Y456kYGNFfgbNDpoE3cW735JKRV-WRt1/view?usp=sharing
    • Here's the new log https://gist.github.com/RichyZ2002/fdaaacb1fd39095d5e15e5d5101542a4
    • I have read the documentation and run the example once, but attach is not executed. When the subscribed Entity is called, attach is called, and then MyCapabilityImplementation is called. fill in the code in the place corresponding to MyCapabilityImplementation. This is how I understand it, am I wrong And I'm not sure what the need for the ResourceLocation string is. It says there are no restrictions, so does that mean it is an ID for identification purposes? Main public void registerCapabilities(RegisterCapabilitiesEvent event) { MyCapability.register(event); }     The problem with not running has been resolved. I had misinterpreted it. MinecraftForge.EVENT_BUS.register(MyCapabilityAttacher.class); So the only thing I'm concerned about is the correctness of future development procedures.  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.