Jump to content

Music in My Dimension


Thor597

Recommended Posts

Subscribe to the PlayBackgroundMusicEvent and then check if the player is in your dimension. If so, return a different SoundPoolEntry. That's how I'd do it.

To have the music in your Mod-Zip file, you can use a custom URLStreamHandler which makes the SoundPoolEntry accept the InputStreams from your zip. Ask if you wan't help with that.

 

Yes I would want some more help with that stuff. Someone should make a page on the tutorials page on how to add background music to dimensions and just music in general and also in the same tutorial how to add sounds(I used the system with ISoundHandler before but now that its gone I need to do the events things)

 

so yeah, a tutorial called: How to add new Audio(Sounds and Music) should be in the tutorials section! :D

Link to comment
Share on other sites

You are aware of the fact that Class.getResource() (Not as stream) returns an URL you could pass to new SoundPoolEntry?

Like:

public class SoundHandler {
    @ForgeSubscribe
    public void onSound(SoundLoadEvent event) {
        try {
            event.manager.soundPoolSounds.addSound("your/sound.ogg", CameraCraft.class.getResource("/path/to/your/sound.ogg"));
        } catch (Exception e) {
            System.err.println("Failed to register one or more sounds.");
        }
    }
}

This avoids writing a hacked urlstreamhandler and will work no matter where in your classpath the sound file is.

Link to comment
Share on other sites

I have a problem.

 

I want my mob to do this sound but im not getting anything, heres my code

 

package net.minecraft.src;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class ThorMod_SoundHandler
{
@ForgeSubscribe
 @SideOnly(Side.CLIENT)
public void onSound(SoundLoadEvent event)
{
	try
	{
		event.manager.soundPoolSounds.addSound("monkey1", mod_TheThorMod.class.getResource("/Sounds/monkey1"));
		event.manager.soundPoolSounds.addSound("monkey2", mod_TheThorMod.class.getResource("/Sounds/monkey2"));
		event.manager.soundPoolSounds.addSound("monkey3", mod_TheThorMod.class.getResource("/Sounds/monkey3"));
	} 

	catch (Exception e)
	{
		System.err.println("Failed to register one or more sounds.");
	}
}
}

 

And in my entity class I have this

protected String getLivingSound()
    {
        return "monkey";
    }

Link to comment
Share on other sites

Okay, I tried that now for myself and my sound won't register anywhere. In fact, the onSound method doesn't get even called (I've put a println in the method to test if it gets called). Did I do something wrong?

 

My SoundHandler:

 

public class PD_SoundHandler {	
@ForgeSubscribe
public void onSound(SoundLoadEvent event) {
	System.out.println("sound!");
        try {
            event.manager.soundPoolSounds.addSound("particledeco/static.ogg", PD_ModRegistry.class.getResource("/sound/static.wav"));
        } catch (Exception e) {
            System.err.println("Failed to register one or more sounds.");
        }
    }

 

 

The event bus will be registered in my ClientProxy like this:

MinecraftForge.EVENT_BUS.register(new PD_SoundHandler());

 

how I want to call my sound (in my entity):

PD_ModRegistry.proxy.getClientWorld().playSoundAtEntity(this, "particledeco.static", 1f, 1f);

 

 

PS: It seems that Thor597 above me has the same problem :P

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Okay, tyvm, but I have still the problem that the sound isn't played.

 

The sound is registered and the file will be found, but the entity won't play it :/

 

EDIT: Nvm, I'm using the worldObj field from my entity instead the ClientWorld from my proxy and it works now ^.^

EDIT2: It seems you have to use the server world for the entity, because it doesn't work with the client one...

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

So if i want music in my dimension i put this in my soundhandler

 

@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void onSound(SoundLoadEvent event)
{
	try
	{
		if(this.world.provider.worldType == 23)
		{
			event.manager.soundPoolMusic.addSound("thormod/netromWood2.wav", mod_TheThorMod.class.getResource("/Sounds/netromWood2.wav"));
		}
	} 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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