Jump to content

Custom sound for custom mob.


Hugofounda

Recommended Posts

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 !

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.



×
×
  • Create New...

Important Information

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