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

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*

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/

  • Author

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*

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.