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

Hey guys

 

I created a mob, it works but I want to add customs sounds (Ambient/ death) but my code doesn't works :/

 

Here is my class for the Entity

package fr.hardmod.Entity;

import fr.hardmod.HardMod;
import fr.hardmod.Reference;
import fr.hardmod.SoundHandler;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.EntityAIZombieAttack;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.World;

public class EntityGalopin extends EntityMob {

	public EntityGalopin(World worldIn) 
	{
		super(worldIn);
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false));
        this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
        this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(8, new EntityAILookIdle(this));
        this.applyEntityAI();
	}

	protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(35.0D);
        this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.52456856D);
        this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(5.0D);
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(17.5D);
    }
	
	 protected void applyEntityAI()
	    {
	        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
	        this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityVillager.class, false));
	        this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true));
	    }
	 
	 protected SoundEvent getAmbientSound()
	    {
	        return SoundHandler.GALOPIN_AMBIENT;
	    }

	    protected SoundEvent getDeathSound()
	    {
	        return SoundHandler.GALOPIN_DEATH;
	    }
	 
}

 

 

Here is my sound Handler

 

package fr.hardmod;

import net.minecraft.init.Bootstrap;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;

public class SoundHandler
{
	public static SoundEvent GALOPIN_AMBIENT;
	public static SoundEvent GALOPIN_DEATH;

    private static SoundEvent getRegisteredSoundEvent(String id)
    
    {
        SoundEvent soundevent = (SoundEvent)SoundEvent.REGISTRY.getObject(new ResourceLocation(id));

        if (soundevent == null)
        {
            throw new IllegalStateException("Invalid Sound requested: " + id);
        }
        else
        {
            return soundevent;
        }
    }

    static
    {
        if (!Bootstrap.isRegistered())
        {
            throw new RuntimeException("Accessed Sounds before Bootstrap!");
        }
        else
        {
        	GALOPIN_AMBIENT = getRegisteredSoundEvent("entity.galopin.galopin_ambient");
        	GALOPIN_DEATH = getRegisteredSoundEvent("entity.galopin.galopin_death");
        }
    }
}

 

And, this is my sounds.json

 

{
    "entity.galopin.galopin_ambient": {
        "category": "hostile",
        "subtitle": "entity.galopin.galopin_ambient",
        "sounds": [ { "name": "hardmod:galopin_ambient", "stream": true } ]
    },
    "entity.galopin.galopin_death": {
        "category": "hostile",
        "subtitle": "entity.galopin.galopin_death",
        "sounds": [ { "name": "hardmod:galopin_death", "stream": true } ]
    }
}

 

 

The file location is: C:\Users\Hugo\Desktop\forge-1.10.2-12.18.3.2422-mdk\src\main\resources\assets\hardmod\sounds

 

Thanks for your help !

Have you registered the sounds in the FMLPreInitializationEvent handler of your mod class?

 

If not, "ForgeRegistries.SOUND_EVENTS.register(GALOPIN_AMBIENT);" should do it. I've never needed to use SoundEvent.REGISTRY.getObject.

Edited by FredTargaryen

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.