Jump to content

Recommended Posts

Posted

I have looked at several other threads and tutorials on this but it just doesnt seem to want to work. I am trying to add a custom sound to a mob, though this sound isnt nessecary i would still like to add it to my mob. here is what i have.

 

classes:

 

 

Main class:

package mods.mochickens;

import java.util.List;

import mods.mochickens.client.ClientProxyMoChickens;
import mods.mochickens.misc.SoundEvents;
import mods.mochickens.mobs.EntityDiamondChicken;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "mochickens", name = "Mo' Chickens", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class MoChickens {

@Instance("mochickens")
    public static MoChickens instance;

@SidedProxy(clientSide = "mods.mochickens.client.ClientProxyMoChickens",
			serverSide = "mods.mochickens.common.CommonProxyMoChickens")
public static ClientProxyMoChickens proxy;

int diamondChickenEggID;

static int startEntityId = 300;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {

	Configuration config = new Configuration(event.getSuggestedConfigurationFile());

	diamondChickenEggID = config.get("Item IDs", "Diamond Chicken Egg ID", 514).getInt();

	config.save();

}

@EventHandler
public void load(FMLInitializationEvent event){

	languageRegisters();
	entityRegisters();
	EggRegisters();

	proxy.registerRenders();

}

// Add Spawn Egg
public static int getUniqueEntityID() {
	do {
		startEntityId++;
	} while(EntityList.getStringFromID(startEntityId) != null);
	return startEntityId;
}

public static void registerEntityEgg(Class <? extends Entity> entity, int primaryColor, int secondaryColor) {
	int id = getUniqueEntityID();
	EntityList.IDtoClassMapping.put(id, entity);
	EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor));
}

public void EggRegisters() {
	registerEntityEgg(EntityDiamondChicken.class, 0x0000FF, 0x000000);
}

//Add Mobs
public void entityRegisters() {
	EntityRegistry.registerModEntity(EntityDiamondChicken.class,"DiamondChicken", 2, this , 40, 3, true);
	EntityRegistry.addSpawn(EntityDiamondChicken.class, 5, 1, 2, EnumCreatureType.creature, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.mushroomIsland, BiomeGenBase.mushroomIslandShore, BiomeGenBase.ocean, BiomeGenBase.plains, BiomeGenBase.river, BiomeGenBase.swampland);
}

private static void languageRegisters() {
	LanguageRegistry.instance().addStringLocalization("entity.mochickens.DiamondChicken.name", "Diamond Chicken");
}


}

 

Client Proxy:

package mods.mochickens.client;

import mods.mochickens.misc.SoundEvents;
import mods.mochickens.mobs.EntityDiamondChicken;
import mods.mochickens.mobs.models.ModelDiamondChicken;
import mods.mochickens.mobs.renders.RenderDiamondChicken;
import mods.mochickens.proxies.CommonProxyMoChickens;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.network.IGuiHandler;

public class ClientProxyMoChickens extends CommonProxyMoChickens {

public void registerRenders(){
	RenderingRegistry.registerEntityRenderingHandler(EntityDiamondChicken.class, new RenderDiamondChicken(new ModelDiamondChicken(), 0.3F));
	MinecraftForge.EVENT_BUS.register(new SoundEvents());
}

}

 

Sound Register:

package mods.mochickens.misc;

import net.minecraft.server.MinecraftServer;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class SoundEvents {
@ForgeSubscribe
public void onSound(SoundLoadEvent event) {
	// You add them the same way as you add blocks.
	event.manager.addSound("mochickens:sounds/layDiamond.ogg");
	}
}

 

Mob Class:

package mods.mochickens.mobs;

import java.util.logging.Logger;

import mods.mochickens.misc.ChickAITempt;
import mods.mochickens.misc.ChickTameable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.EnchantmentThorns;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;

public class EntityDiamondChicken extends EntityTameable {
public boolean field_70885_d = false;
public float field_70886_e = 0.0F;
public float destPos = 0.0F;
public float field_70884_g;
public float field_70888_h;
public float field_70889_i = 1.0F;

/** The time until the next egg is spawned. */
public int timeUntilNextEgg;

public EntityDiamondChicken(World par1World) {
	super(par1World);
	this.setSize(0.3F, 0.7F);
	float f = 0.25F;
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
	this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
	this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(6, new EntityAIWatchClosest(this,
			EntityPlayer.class, 6.0F));
	this.tasks.addTask(7, new EntityAILookIdle(this));
	this.tasks.addTask(2, new EntityAIAttackOnCollide(this,
			EntityPlayer.class, 1.0D, false));
	this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this,
			EntityPlayer.class, 0, true));
	this.timeUntilNextEgg = -1;
	this.setTamed(false);
}

/**
 * Returns true if the newer Entity AI code should be run
 */
public boolean isAIEnabled() {
	return true;
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth)
			.setAttribute(4.0D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
			.setAttribute(0.25D);
}

@Override
public final void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {
	super.readEntityFromNBT(par1NBTTagCompound);
	String s = par1NBTTagCompound.getString("Owner");

	if (s.length() > 0) {
		this.setTamed(true);
		this.setOwner(s);
	}
}

    @Override
public void setTamed(boolean par1)
    {
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);

        if (par1)
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 4)));
            this.worldObj.setEntityState(this, (byte) 7);
			this.tasks.removeTask(new EntityAIAttackOnCollide(this,
					EntityPlayer.class, 1.0D, false));
			this.targetTasks.taskEntries.clear();
			this.tasks.addTask(3, new ChickAITempt(this, 1.0D,
					Block.blockDiamond.blockID, false));
			this.timeUntilNextEgg = this.rand.nextInt(1) + 60;
        }
        else
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -5)));
        }
    }

public boolean attackEntityAsMob(Entity par1Entity) {
	if (!this.isTamed()) {
		EntityPlayer entityplayer = this.worldObj
				.getClosestVulnerablePlayerToEntity(this, 16.0D);
		// f = damage delt 2.0D = 1 heart
		float f = (float) 5.0D;
		int i = 0;

		if (entityplayer instanceof EntityLivingBase) {
			f += EnchantmentHelper.getEnchantmentModifierLiving(this,
					(EntityLivingBase) entityplayer);
			i += EnchantmentHelper.getKnockbackModifier(this,
					(EntityLivingBase) entityplayer);
			entityplayer.addPotionEffect(new PotionEffect(
					Potion.blindness.id, 200, 1));
			entityplayer.addPotionEffect(new PotionEffect(
					Potion.moveSlowdown.id, 200, 2));
		}

		boolean flag = par1Entity.attackEntityFrom(
				DamageSource.causeMobDamage(this), f);

		if (flag) {
			if (i > 0) {
				entityplayer.addVelocity(
						(double) (-MathHelper.sin(this.rotationYaw
								* (float) Math.PI / 180.0F)
								* (float) i * 0.5F),
						0.1D,
						(double) (MathHelper.cos(this.rotationYaw
								* (float) Math.PI / 180.0F)
								* (float) i * 0.5F));
				this.motionX *= 0.6D;
				this.motionZ *= 0.6D;
			}

			int j = EnchantmentHelper.getFireAspectModifier(this);

			if (j > 0) {
				entityplayer.setFire(j * 4);
			}

			if (entityplayer instanceof EntityLivingBase) {
				EnchantmentThorns.func_92096_a(this,
						(EntityLivingBase) entityplayer, this.rand);
			}
		}

		return flag;
	} else {
		return false;
	}
}

/**
 * Called frequently so the entity can update its state every tick as
 * required. For example, zombies and skeletons use this to react to
 * sunlight and start to burn.
 */
public void onLivingUpdate() {
	super.onLivingUpdate();
	this.field_70888_h = this.field_70886_e;
	this.field_70884_g = this.destPos;
	this.destPos = (float) ((double) this.destPos + (double) (this.onGround ? -1
			: 4) * 0.3D);

	if (this.destPos < 0.0F) {
		this.destPos = 0.0F;
	}

	if (this.destPos > 1.0F) {
		this.destPos = 1.0F;
	}

	if (!this.onGround && this.field_70889_i < 1.0F) {
		this.field_70889_i = 1.0F;
	}

	this.field_70889_i = (float) ((double) this.field_70889_i * 0.9D);

	if (!this.onGround && this.motionY < 0.0D) {
		this.motionY *= 0.6D;
	}

	this.field_70886_e += this.field_70889_i * 2.0F;

	if (!this.isChild() && !this.worldObj.isRemote
			&& --this.timeUntilNextEgg == 0) {
		this.worldObj.playSoundAtEntity(this,
				"mochickens:sounds/layDiamond",
				1.0F,
				1.0F);
		this.dropItem(Item.diamond.itemID, 1);
		this.timeUntilNextEgg = this.rand.nextInt(1) + 60;
	}
}

/**
 * Called when the mob is falling. Calculates and applies fall damage.
 */
protected void fall(float par1) {
}

/**
 * Returns the sound this mob makes while it's alive.
 */
protected String getLivingSound() {
	return "mob.chicken.say";
}

/**
 * Returns the sound this mob makes when it is hurt.
 */
protected String getHurtSound() {
	return "mob.chicken.hurt";
}

/**
 * Returns the sound this mob makes on death.
 */
protected String getDeathSound() {
	return "mob.chicken.hurt";
}

/**
 * Plays step sound at given x, y, z for the entity
 */
protected void playStepSound(int par1, int par2, int par3, int par4) {
	this.playSound("mob.chicken.step", 0.15F, 1.0F);
}

/**
 * Returns the item ID for the item the mob drops on death.
 */
protected int getDropItemId() {
	return Item.feather.itemID;
}

/**
 * Drop 0-2 items of this living's type. @param par1 - Whether this entity
 * has recently been hit by a player. @param par2 - Level of Looting used to
 * kill this mob.
 */
protected void dropFewItems(boolean par1, int par2) {
	int j = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);

	for (int k = 0; k < j; ++k) {
		if (this.isTamed()) {
		this.dropItem(Item.diamond.itemID, 1);
		} else {
			this.dropItem(Item.egg.itemID, 1);
		}
	}

	if (this.isBurning()) {
		this.dropItem(Item.chickenCooked.itemID, 1);
	} else {
		this.dropItem(Item.chickenRaw.itemID, 1);
	}
}

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow,
 * gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer par1EntityPlayer) {
	ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
	if (!this.isTamed()) {
		if (itemstack != null && itemstack.itemID == Item.diamond.itemID) {
			if (!par1EntityPlayer.capabilities.isCreativeMode) {
				--itemstack.stackSize;
			}

			if (itemstack.stackSize <= 0) {
				par1EntityPlayer.inventory.setInventorySlotContents(
						par1EntityPlayer.inventory.currentItem,
						(ItemStack) null);
			}

			if (!this.worldObj.isRemote) {
				if (this.rand.nextInt(3) == 0) {
					this.setTamed(true);
					this.setPathToEntity((PathEntity) null);
					this.setAttackTarget((EntityLivingBase) null);
					this.setTarget(null);
					this.setOwner(par1EntityPlayer.getCommandSenderName());
					this.playTameEffect(true);
				} else {
					this.playTameEffect(false);
					this.worldObj.setEntityState(this, (byte) 6);
				}
			}

			return true;
		}
	}

	return super.interact(par1EntityPlayer);
}

/**
 * This function is used when two same-species animals in 'love mode' breed
 * to generate the new baby animal.
 */
public EntityDiamondChicken spawnBabyAnimal(EntityAgeable par1EntityAgeable) {
	EntityDiamondChicken entitybluechicken = new EntityDiamondChicken(
			this.worldObj);
	String s = this.getOwnerName();

	if (s != null && s.trim().length() > 0) {
		entitybluechicken.setOwner(s);
		entitybluechicken.setTamed(true);
	}

	return entitybluechicken;
}

/**
 * Checks if the parameter is an item which this animal can be fed to breed
 * it (wheat, carrots or seeds depending on the animal type)
 */
public boolean isBreedingItem(ItemStack par1ItemStack) {
	if (this.isTamed()) {
		return par1ItemStack != null
				&& par1ItemStack.itemID == Item.diamond.itemID;
	} else {
		return false;
	}
}

public EntityAgeable createChild(EntityAgeable par1EntityAgeable) {
	return this.spawnBabyAnimal(par1EntityAgeable);
}
}

 

 

 

As i said, i have tried everything i have seen to fix this. the sound file is in src/assets/mochickens/sounds/layDiamond.ogg

Posted

for most of them, just one i want custom which is in the onLivingUpdae() method. and before you point me toward your tutorial, i have looked at it and thats how i got to this point, i just cant get it to play in game.

 

public void onLivingUpdate() {
	super.onLivingUpdate();
	this.field_70888_h = this.field_70886_e;
	this.field_70884_g = this.destPos;
	this.destPos = (float) ((double) this.destPos + (double) (this.onGround ? -1
			: 4) * 0.3D);

	if (this.destPos < 0.0F) {
		this.destPos = 0.0F;
	}

	if (this.destPos > 1.0F) {
		this.destPos = 1.0F;
	}

	if (!this.onGround && this.field_70889_i < 1.0F) {
		this.field_70889_i = 1.0F;
	}

	this.field_70889_i = (float) ((double) this.field_70889_i * 0.9D);

	if (!this.onGround && this.motionY < 0.0D) {
		this.motionY *= 0.6D;
	}

	this.field_70886_e += this.field_70889_i * 2.0F;

	if (!this.isChild() && !this.worldObj.isRemote
			&& --this.timeUntilNextEgg == 0) {
		this.worldObj.playSoundAtEntity(this,
				"mochickens:sounds/layDiamond",
				1.0F,
				1.0F);
		this.dropItem(Item.diamond.itemID, 1);
		this.timeUntilNextEgg = this.rand.nextInt(1) + 60;
	}
}

 

specifically this block of it

if (!this.isChild() && !this.worldObj.isRemote
			&& --this.timeUntilNextEgg == 0) {
		this.worldObj.playSoundAtEntity(this,
				"mochickens:sounds/layDiamond",
				1.0F,
				1.0F);
		this.dropItem(Item.diamond.itemID, 1);
		this.timeUntilNextEgg = this.rand.nextInt(1) + 60;
	}

 

line is

this.worldObj.playSoundAtEntity(this, "mochickens:sounds/layDiamond", 1.0F, 1.0F);

Posted

If your sound file is

sounds/layDiamond.ogg

you have to call it with

sounds.layDiamond

when you want to play it.

 

here is the error i get by using that:

 

 

2013-11-16 02:29:31 [iNFO] [sTDERR] Exception in thread "Thread-13" java.lang.NullPointerException

2013-11-16 02:29:31 [iNFO] [sTDERR] at paulscode.sound.codecs.CodecJOrbis.readHeader(CodecJOrbis.java:448)

2013-11-16 02:29:31 [iNFO] [sTDERR] at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:301)

2013-11-16 02:29:31 [iNFO] [sTDERR] at paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)

2013-11-16 02:29:31 [iNFO] [sTDERR] at paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)

2013-11-16 02:29:31 [iNFO] [sTDERR] at paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)

2013-11-16 02:29:31 [iNFO] [sTDERR] at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)

2013-11-16 02:29:31 [iNFO] [sTDERR] at paulscode.sound.CommandThread.run(CommandThread.java:121)

 

 

 

the only change is on this on line:

this.worldObj.playSoundAtEntity(this, "mochickens:sounds.layDiamond", 1.0F, 1.0F);

Posted

this.worldObj.playSoundAtEntity(this, "mochickens:sounds.layDiamond", 1.0F, 1.0F);

This would mean you put your sound at

assets/mochickens/sound/sounds/layDiamond ?

Posted

@diesieben07: i use audacity

 

@GotoLink: Thank you, that was the problem. i wasnt fully understanding the file path, though i thought i was. i changed the file path to that, and now it works.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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