Jump to content

[1.9] New Sound Not Registered


Lyras

Recommended Posts

Problem: New sounds don't get registered.

 

package registry;

import core.ModBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class SoundRegistry {

public static SoundEvent record_flute1;
public static SoundEvent record_flute2;

public static void registerSounds () {

	record_flute1 = registerSound( "record.flute1" );
	record_flute2 = registerSound( "record.flute2" );

}

private static SoundEvent registerSound ( String soundName ) {

	ResourceLocation res = new ResourceLocation ( ModBase.ID , soundName );
	return GameRegistry.register( new SoundEvent( res ).setRegistryName( res ) );

}

}

 

package item;

import handler.SoundHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import registry.SoundRegistry;

public class ItemPanFlute extends ItemBase {

public ItemPanFlute () {

	super( "pan_flute" , false );
	this.setCreativeTab( CreativeTabs.tabTools );
	this.setMaxStackSize( 1 );
	this.setMaxDamage( 500 );

}

@Override
public ActionResult < ItemStack > onItemRightClick ( ItemStack itemstack , World world , EntityPlayer player , EnumHand hand ) {

	try {

		if ( itemstack.getTagCompound().hasNoTags() || ( world.getTotalWorldTime() - itemstack.getTagCompound().getLong( "world_time" ) ) >= 5 ) {

			if ( !world.isRemote ) {

				float rotationPitch = ( ( - ( player.rotationPitch ) ) / 360 );
				float soundPitch = ( float ) ( rotationPitch + 1.375 );

				if ( !player.isSneaking() ) { SoundHandler.playSoundInRadius( player , 25 , SoundRegistry.record_flute1 , ( float ) 0.5 , soundPitch ); }
				else { SoundHandler.playSoundInRadius( player , 25 , SoundRegistry.record_flute2 , ( float ) 0.5 , soundPitch ); } 

				itemstack.getTagCompound().setLong( "world_time" , world.getTotalWorldTime() );
				itemstack.damageItem( 1 , player );

			}

		}

	} catch ( Exception ex ) {}

	return super.onItemRightClick( itemstack , world , player , hand );

}

@Override
public void onUpdate ( ItemStack itemstack , World world , Entity entity , int metadata , boolean bool ) {

	if ( itemstack.getTagCompound() == null ) { itemstack.setTagCompound( new NBTTagCompound() ); }

}

}

 

{

    "record.flute1": {
        "category": "record",
        "sounds": [
            {
                "name": "betterlife:flute1",
                "stream": true
            }
        ]
    } ,
    
    "record.flute2": {
        "category": "record",
        "sounds": [
            {
                "name": "betterlife:flute2",
                "stream": true
            }
        ]
    }

}

 

As you can see in the 2nd code snippet: When the player sneaks and right clicks the item, the 2nd sound should be played. But this doesn't work.

*Hug*

Link to comment
Share on other sites

Are you sure that registerSounds() is being called in the proxies? Forgetting to actually call registration methods has tripped me up before in the past.

Colore - The mod that adds monochrome blocks in every color of the rainbow!

http://www.minecraftforge.net/forum/index.php?topic=35149

 

If you're looking to learn how to make mods for 1.9.4, I wrote a helpful article with links to a lot of useful resources for learning Minecraft 1.9.4 modding!

 

http://supergeniuszeb.com/mods/a-helpful-list-of-minecraft-1-9-4-modding-resources/

Link to comment
Share on other sites

The method gets called.

 

Scenario:

I've got my flute. When I'm not sneaking and press the item it will play record_flute1 but when I'm sneaking and press the item, it should play record_flute2.

When I'm not sneaking it will play the sound and when I'm sneaking it will not. I already copied record_flute1 and named it record_flute2 so that I have both files BUT they are the same. Then I tested again and realized that I actually just plays record_flute1 but not record_flute2.

 

The base problem is commensurately that just the record_flute1 can be played.

 

*Hug*

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

    • 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;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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