Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)

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
Posted (edited)

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
Posted (edited)

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

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

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

×
×
  • Create New...

Important Information

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