Jouer une musique de combat



  • Bonjour,
    J'ai créé une entité, et je voulais faire jouer des musiques de combat pendant qu'elle était en vie.
    Problème : Après avoir créé le code correctement, les musiques ne se jouaient pas (ou aléatoirement) !

    Pouvez-vous m'aider ?
    EntityFireDragon :

    
    package fr.MrBlockTNT.Dragons.entity.firedragon;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Random;
    
    import javax.swing.Timer;
    
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockEndPortal;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.renderer.entity.RenderDragon;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityCreature;
    import net.minecraft.entity.EntityLiving;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.SharedMonsterAttributes;
    import net.minecraft.entity.boss.EntityDragon;
    import net.minecraft.entity.boss.EntityDragonPart;
    import net.minecraft.entity.boss.IBossDisplayData;
    import net.minecraft.entity.item.EntityEnderCrystal;
    import net.minecraft.entity.item.EntityXPOrb;
    import net.minecraft.entity.monster.EntityZombie;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.projectile.EntityLargeFireball;
    import net.minecraft.entity.projectile.EntitySmallFireball;
    import net.minecraft.pathfinding.PathEntity;
    import net.minecraft.util.AxisAlignedBB;
    import net.minecraft.util.DamageSource;
    import net.minecraft.util.MathHelper;
    import net.minecraft.util.Vec3;
    import net.minecraft.world.Explosion;
    import net.minecraft.world.World;
    
    public class EntityFireDragon extends EntityLiving implements IBossDisplayData
    {
    public String mobName;
    
    public double targetX;
    public double targetY;
    public double targetZ;
    
    /**
    * Ring buffer array for the last 64 Y-positions and yaw rotations. Used to calculate offsets for the animations.
    */
    public double[][] ringBuffer = new double[64][3];
    
    /**
    * Index into the ring buffer. Incremented once per tick and restarts at 0 once it reaches the end of the buffer.
    */
    public int ringBufferIndex = -1;
    
    /** An array containing all body parts of this dragon */
    public EntityFireDragonPart[] dragonPartArray;
    
    /** The head bounding box of a dragon */
    public EntityFireDragonPart dragonPartHead;
    
    /** The body bounding box of a dragon */
    public EntityFireDragonPart dragonPartBody;
    public EntityFireDragonPart dragonPartTail1;
    public EntityFireDragonPart dragonPartTail2;
    public EntityFireDragonPart dragonPartTail3;
    public EntityFireDragonPart dragonPartWing1;
    public EntityFireDragonPart dragonPartWing2;
    
    /** Animation time at previous tick. */
    public float prevAnimTime;
    
    /**
    * Animation time, used to control the speed of the animation cycles (wings flapping, jaw opening, etc.)
    */
    public float animTime;
    
    /** Force selecting a new flight target at next tick if set to true. */
    public boolean forceNewTarget;
    
    /**
    * Activated if the dragon is flying though obsidian, white stone or bedrock. Slows movement and animation speed.
    */
    public boolean slowed;
    private Entity target;
    public int deathTicks;
    
    /** The current endercrystal that is healing this dragon */
    public EntityFireCrystal healingEnderCrystal;
    
    public EntityFireDragon(World world)
    {
    super(world);
    mobName = "Fire Dragon";
    this.dragonPartArray = new EntityFireDragonPart[] {this.dragonPartHead = new EntityFireDragonPart(this, "head", 6.0F, 6.0F), this.dragonPartBody = new EntityFireDragonPart(this, "body", 8.0F, 8.0F), this.dragonPartTail1 = new EntityFireDragonPart(this, "tail", 4.0F, 4.0F), this.dragonPartTail2 = new EntityFireDragonPart(this, "tail", 4.0F, 4.0F), this.dragonPartTail3 = new EntityFireDragonPart(this, "tail", 4.0F, 4.0F), this.dragonPartWing1 = new EntityFireDragonPart(this, "wing", 4.0F, 4.0F), this.dragonPartWing2 = new EntityFireDragonPart(this, "wing", 4.0F, 4.0F)};
    this.setHealth(this.getMaxHealth());
    this.setSize(16.0F, 8.0F);
    this.noClip = true;
    this.isImmuneToFire = true;
    this.targetY = 100.0D;
    this.ignoreFrustumCheck = true;
    }
    
    protected void applyEntityAttributes()
    {
    super.applyEntityAttributes();
    this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(1.0D);
    }
    
    protected void entityInit()
    {
    super.entityInit();
    }
    
    /**
    * Returns a double[3] array with movement offsets, used to calculate trailing tail/neck positions. [0] = yaw
    * offset, [1] = y offset, [2] = unused, always 0\. Parameters: buffer index offset, partial ticks.
    */
    public double[] getMovementOffsets(int par1, float par2)
    {
    if (this.getHealth() <= 0.0F)
    {
    par2 = 0.0F;
    }
    
    par2 = 1.0F - par2;
    int j = this.ringBufferIndex - par1 * 1 & 63;
    int k = this.ringBufferIndex - par1 * 1 - 1 & 63;
    double[] adouble = new double[3];
    double d0 = this.ringBuffer[j][0];
    double d1 = MathHelper.wrapAngleTo180_double(this.ringBuffer[k][0] - d0);
    adouble[0] = d0 + d1 * (double)par2;
    d0 = this.ringBuffer[j][1];
    d1 = this.ringBuffer[k][1] - d0;
    adouble[1] = d0 + d1 * (double)par2;
    adouble[2] = this.ringBuffer[j][2] + (this.ringBuffer[k][2] - this.ringBuffer[j][2]) * (double)par2;
    return adouble;
    }
    
    boolean isDead = false;
    
    protected void attackEntitySimpleFireball(Entity par1Entity, float par2, int par3)
    {
    if(isDead == false)
    {
    if (this.attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY)
    {
    this.attackTime = 20;
    this.attackEntityAsMob(par1Entity);
    }
    else if (par2 < 30.0F)
    {
    double d0 = par1Entity.posX - this.posX;
    double d1 = par1Entity.boundingBox.minY + (double)(par1Entity.height / 2.0F) - (this.posY + (double)(this.height / 2.0F));
    double d2 = par1Entity.posZ - this.posZ;
    
    float f1 = MathHelper.sqrt_float(par2) * 0.5F;
    if(rand.nextInt(50) == 1)
    {
    for (int i = 0; i < rand.nextInt(par3); i++)
    {
    this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
    EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.worldObj, this, d0 + this.rand.nextGaussian() * (double)f1, d1, d2 + this.rand.nextGaussian() * (double)f1);
    entitysmallfireball.posY = this.posY + (double)(this.height / 2.0F) + 0.5D;
    this.worldObj.spawnEntityInWorld(entitysmallfireball);
    }
    }
    }
    }
    }
    
    protected void attackEntityLargeFireball(Entity par1Entity, float par2, int par3)
    {
    if(isDead == false)
    {
    if (this.attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY)
    {
    this.attackTime = 20;
    this.attackEntityAsMob(par1Entity);
    }
    else if (par2 < 30.0F)
    {
    double d0 = par1Entity.posX - this.posX;
    double d1 = par1Entity.boundingBox.minY + (double)(par1Entity.height / 2.0F) - (this.posY + (double)(this.height / 2.0F));
    double d2 = par1Entity.posZ - this.posZ;
    
    float f1 = MathHelper.sqrt_float(par2) * 0.5F;
    if(rand.nextInt(50) == 1)
    {
    for (int i = 0; i < rand.nextInt(par3); i++)
    {
    this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
    EntityLargeFireball entitysmallfireball = new EntityLargeFireball(this.worldObj, this, d0 + this.rand.nextGaussian() * (double)f1, d1, d2 + this.rand.nextGaussian() * (double)f1);
    entitysmallfireball.posY = this.posY + (double)(this.height / 2.0F) + 0.5D;
    this.worldObj.spawnEntityInWorld(entitysmallfireball);
    }
    }
    }
    }
    }
    
    public void playEndSound(EntityPlayer player, World world)
    {
    world.playRecord("dragons:boss/boss_end", player.serverPosX, player.serverPosY, player.serverPosZ);
    }
    
    public void playFightSound1(EntityPlayer player, World world)
    {
    world.playRecord("dragons:boss/fire_dragon", player.serverPosX, player.serverPosY, player.serverPosZ);
    }
    
    public void playFightSound2(EntityPlayer player, World world)
    {
    world.playRecord("dragons:boss/fire_dragon_second_half", player.serverPosX, player.serverPosY, player.serverPosZ);
    }
    
    /**
    * 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.
    */
    
    boolean startFight = false;
    boolean isAngry = false;
    boolean isVeryAngry = false;
    boolean angryIA = false;
    boolean wantToKillYou = false;
    int angryScream = 0;
    
    public void onLivingUpdate()
    {
    float f;
    float f1;
    
    float f20 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    float f21 = (this.rand.nextFloat() - 0.5F) * 4.0F;
    float f22 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    
    Minecraft mc = Minecraft.getMinecraft();
    EntityPlayer player = mc.thePlayer;
    if(player != null)
    {
    if(angryIA = true && isVeryAngry == false && wantToKillYou == false)
    {
    attackEntitySimpleFireball(player, 1.0F, 15);
    }
    else if (angryIA == false && isVeryAngry == false && wantToKillYou == false && startFight == true)
    {
    attackEntitySimpleFireball(player, 1.0F, 5);
    }
    else if(isVeryAngry == true && angryIA == false && wantToKillYou == false)
    {
    attackEntityLargeFireball(player, 1.0F, 5);
    }
    else if (wantToKillYou == true && angryIA == false && isVeryAngry == false)
    {
    attackEntityLargeFireball(player, 1.0F, 12);
    }
    }
    
    if(this.getHealth() <= 1000.0F && this.getHealth() >= 500.0F)
    {
    playFightSound1(player, worldObj);
    }
    else if(this.getHealth() <= 499.0F && this.getHealth() >= 0.0F)
    {
    playFightSound2(player, worldObj);
    }
    
    if(this.getHealth() <= 999.0F)
    {
    startFight = true;
    }
    
    if (this.getHealth() <= 700.0F)
    {
    isAngry = true;
    startFight = false;
    }
    
    if (this.getHealth() <= 375.0F)
    {
    isVeryAngry = true;
    isAngry = false;
    }
    
    if(this.getHealth() <= 200.0F)
    {
    wantToKillYou = true;
    isVeryAngry = false;
    }
    
    if(isAngry == false && isVeryAngry == false && wantToKillYou == false)
    {
    for (int i = 0; i < 6; ++i)
    {
    this.worldObj.spawnParticle("flame", this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
    }
    }
    else if(isAngry == true || isVeryAngry == true || wantToKillYou == true)
    {
    for (int i = 0; i < 15; ++i)
    {
    this.worldObj.spawnParticle("flame", this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
    }
    
    if(angryScream == 0)
    {
    angryScream = 1;
    this.worldObj.playSound(this.posX, this.posY, this.posZ, "random.explode1", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false);
    this.worldObj.playSound(this.posX, this.posY, this.posZ, "random.explode2", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false);
    this.worldObj.playSound(this.posX, this.posY, this.posZ, "random.explode3", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false);
    this.worldObj.playSound(this.posX, this.posY, this.posZ, "random.explode4", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false);
    }
    }
    
    if (this.worldObj.isRemote)
    {
    f = MathHelper.cos(this.animTime * (float)Math.PI * 2.0F);
    f1 = MathHelper.cos(this.prevAnimTime * (float)Math.PI * 2.0F);
    
    if (f1 <= -0.3F && f >= -0.3F)
    {
    this.worldObj.playSound(this.posX, this.posY, this.posZ, "mob.enderdragon.wings", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false);
    }
    }
    
    this.prevAnimTime = this.animTime;
    float f2;
    
    if (this.getHealth() <= 0.0F)
    {
    f = (this.rand.nextFloat() - 0.5F) * 8.0F;
    f1 = (this.rand.nextFloat() - 0.5F) * 4.0F;
    f2 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    this.worldObj.spawnParticle("largeexplode", this.posX + (double)f, this.posY + 2.0D + (double)f1, this.posZ + (double)f2, 0.0D, 0.0D, 0.0D);
    }
    else
    {
    this.updateDragonEnderCrystal();
    f = 0.2F / (MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 10.0F + 1.0F);
    f *= (float)Math.pow(2.0D, this.motionY);
    
    if (this.slowed)
    {
    this.animTime += f * 0.5F;
    }
    else
    {
    this.animTime += f;
    }
    
    this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);
    
    if (this.ringBufferIndex < 0)
    {
    for (int i = 0; i < this.ringBuffer.length; ++i)
    {
    this.ringBuffer*[0] = (double)this.rotationYaw;
    this.ringBuffer*[1] = this.posY;
    }
    }
    
    if (++this.ringBufferIndex == this.ringBuffer.length)
    {
    this.ringBufferIndex = 0;
    }
    
    this.ringBuffer[this.ringBufferIndex][0] = (double)this.rotationYaw;
    this.ringBuffer[this.ringBufferIndex][1] = this.posY;
    double d0;
    double d1;
    double d2;
    double d3;
    float f3;
    
    if (this.worldObj.isRemote)
    {
    if (this.newPosRotationIncrements > 0)
    {
    d3 = this.posX + (this.newPosX - this.posX) / (double)this.newPosRotationIncrements;
    d0 = this.posY + (this.newPosY - this.posY) / (double)this.newPosRotationIncrements;
    d1 = this.posZ + (this.newPosZ - this.posZ) / (double)this.newPosRotationIncrements;
    d2 = MathHelper.wrapAngleTo180_double(this.newRotationYaw - (double)this.rotationYaw);
    this.rotationYaw = (float)((double)this.rotationYaw + d2 / (double)this.newPosRotationIncrements);
    this.rotationPitch = (float)((double)this.rotationPitch + (this.newRotationPitch - (double)this.rotationPitch) / (double)this.newPosRotationIncrements);
    –this.newPosRotationIncrements;
    this.setPosition(d3, d0, d1);
    this.setRotation(this.rotationYaw, this.rotationPitch);
    }
    }
    else
    {
    d3 = this.targetX - this.posX;
    d0 = this.targetY - this.posY;
    d1 = this.targetZ - this.posZ;
    d2 = d3 * d3 + d0 * d0 + d1 * d1;
    
    if (this.target != null)
    {
    this.targetX = this.target.posX;
    this.targetZ = this.target.posZ;
    double d4 = this.targetX - this.posX;
    double d5 = this.targetZ - this.posZ;
    double d6 = Math.sqrt(d4 * d4 + d5 * d5);
    double d7 = 0.4000000059604645D + d6 / 80.0D - 1.0D;
    
    if (d7 > 10.0D)
    {
    d7 = 10.0D;
    }
    
    this.targetY = this.target.boundingBox.minY + d7;
    }
    else
    {
    this.targetX += this.rand.nextGaussian() * 2.0D;
    this.targetZ += this.rand.nextGaussian() * 2.0D;
    }
    
    if (this.forceNewTarget || d2 < 100.0D || d2 > 22500.0D || this.isCollidedHorizontally || this.isCollidedVertically)
    {
    this.setNewTarget();
    }
    
    d0 /= (double)MathHelper.sqrt_double(d3 * d3 + d1 * d1);
    f3 = 0.6F;
    
    if (d0 < (double)(-f3))
    {
    d0 = (double)(-f3);
    }
    
    if (d0 > (double)f3)
    {
    d0 = (double)f3;
    }
    
    this.motionY += d0 * 0.10000000149011612D;
    this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);
    double d8 = 180.0D - Math.atan2(d3, d1) * 180.0D / Math.PI;
    double d9 = MathHelper.wrapAngleTo180_double(d8 - (double)this.rotationYaw);
    
    if (d9 > 50.0D)
    {
    d9 = 50.0D;
    }
    
    if (d9 < -50.0D)
    {
    d9 = -50.0D;
    }
    
    Vec3 vec3 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.targetX - this.posX, this.targetY - this.posY, this.targetZ - this.posZ).normalize();
    Vec3 vec31 = this.worldObj.getWorldVec3Pool().getVecFromPool((double)MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F), this.motionY, (double)(-MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F))).normalize();
    float f4 = (float)(vec31.dotProduct(vec3) + 0.5D) / 1.5F;
    
    if (f4 < 0.0F)
    {
    f4 = 0.0F;
    }
    
    this.randomYawVelocity *= 0.8F;
    float f5 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0F + 1.0F;
    double d10 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0D + 1.0D;
    
    if (d10 > 40.0D)
    {
    d10 = 40.0D;
    }
    
    this.randomYawVelocity = (float)((double)this.randomYawVelocity + d9 * (0.699999988079071D / d10 / (double)f5));
    this.rotationYaw += this.randomYawVelocity * 0.1F;
    float f6 = (float)(2.0D / (d10 + 1.0D));
    float f7 = 0.06F;
    this.moveFlying(0.0F, -1.0F, f7 * (f4 * f6 + (1.0F - f6)));
    
    if (this.slowed)
    {
    this.moveEntity(this.motionX * 0.800000011920929D, this.motionY * 0.800000011920929D, this.motionZ * 0.800000011920929D);
    }
    else
    {
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    }
    
    Vec3 vec32 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.motionX, this.motionY, this.motionZ).normalize();
    float f8 = (float)(vec32.dotProduct(vec31) + 1.0D) / 2.0F;
    f8 = 0.8F + 0.15F * f8;
    this.motionX *= (double)f8;
    this.motionZ *= (double)f8;
    this.motionY *= 0.9100000262260437D;
    }
    
    this.renderYawOffset = this.rotationYaw;
    this.dragonPartHead.width = this.dragonPartHead.height = 3.0F;
    this.dragonPartTail1.width = this.dragonPartTail1.height = 2.0F;
    this.dragonPartTail2.width = this.dragonPartTail2.height = 2.0F;
    this.dragonPartTail3.width = this.dragonPartTail3.height = 2.0F;
    this.dragonPartBody.height = 3.0F;
    this.dragonPartBody.width = 5.0F;
    this.dragonPartWing1.height = 2.0F;
    this.dragonPartWing1.width = 4.0F;
    this.dragonPartWing2.height = 3.0F;
    this.dragonPartWing2.width = 4.0F;
    f1 = (float)(this.getMovementOffsets(5, 1.0F)[1] - this.getMovementOffsets(10, 1.0F)[1]) * 10.0F / 180.0F * (float)Math.PI;
    f2 = MathHelper.cos(f1);
    float f9 = -MathHelper.sin(f1);
    float f10 = this.rotationYaw * (float)Math.PI / 180.0F;
    float f11 = MathHelper.sin(f10);
    float f12 = MathHelper.cos(f10);
    this.dragonPartBody.onUpdate();
    this.dragonPartBody.setLocationAndAngles(this.posX + (double)(f11 * 0.5F), this.posY, this.posZ - (double)(f12 * 0.5F), 0.0F, 0.0F);
    this.dragonPartWing1.onUpdate();
    this.dragonPartWing1.setLocationAndAngles(this.posX + (double)(f12 * 4.5F), this.posY + 2.0D, this.posZ + (double)(f11 * 4.5F), 0.0F, 0.0F);
    this.dragonPartWing2.onUpdate();
    this.dragonPartWing2.setLocationAndAngles(this.posX - (double)(f12 * 4.5F), this.posY + 2.0D, this.posZ - (double)(f11 * 4.5F), 0.0F, 0.0F);
    
    if (!this.worldObj.isRemote && this.hurtTime == 0)
    {
    this.collideWithEntities(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartWing1.boundingBox.expand(4.0D, 2.0D, 4.0D).offset(0.0D, -2.0D, 0.0D)));
    this.collideWithEntities(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartWing2.boundingBox.expand(4.0D, 2.0D, 4.0D).offset(0.0D, -2.0D, 0.0D)));
    this.attackEntitiesInList(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartHead.boundingBox.expand(1.0D, 1.0D, 1.0D)));
    }
    
    double[] adouble = this.getMovementOffsets(5, 1.0F);
    double[] adouble1 = this.getMovementOffsets(0, 1.0F);
    f3 = MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
    float f13 = MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
    this.dragonPartHead.onUpdate();
    this.dragonPartHead.setLocationAndAngles(this.posX + (double)(f3 * 5.5F * f2), this.posY + (adouble1[1] - adouble[1]) * 1.0D + (double)(f9 * 5.5F), this.posZ - (double)(f13 * 5.5F * f2), 0.0F, 0.0F);
    
    for (int j = 0; j < 3; ++j)
    {
    EntityFireDragonPart entitydragonpart = null;
    
    if (j == 0)
    {
    entitydragonpart = this.dragonPartTail1;
    }
    
    if (j == 1)
    {
    entitydragonpart = this.dragonPartTail2;
    }
    
    if (j == 2)
    {
    entitydragonpart = this.dragonPartTail3;
    }
    
    double[] adouble2 = this.getMovementOffsets(12 + j * 2, 1.0F);
    float f14 = this.rotationYaw * (float)Math.PI / 180.0F + this.simplifyAngle(adouble2[0] - adouble[0]) * (float)Math.PI / 180.0F * 1.0F;
    float f15 = MathHelper.sin(f14);
    float f16 = MathHelper.cos(f14);
    float f17 = 1.5F;
    float f18 = (float)(j + 1) * 2.0F;
    entitydragonpart.onUpdate();
    entitydragonpart.setLocationAndAngles(this.posX - (double)((f11 * f17 + f15 * f18) * f2), this.posY + (adouble2[1] - adouble[1]) * 1.0D - (double)((f18 + f17) * f9) + 1.5D, this.posZ + (double)((f12 * f17 + f16 * f18) * f2), 0.0F, 0.0F);
    }
    }
    }
    
    /**
    * Updates the state of the enderdragon's current endercrystal.
    */
    private void updateDragonEnderCrystal()
    {
    if (this.healingEnderCrystal != null)
    {
    if (this.healingEnderCrystal.isDead)
    {
    if (!this.worldObj.isRemote)
    {
    this.attackEntityFromPart(this.dragonPartHead, DamageSource.setExplosionSource((Explosion)null), 10.0F);
    }
    
    this.healingEnderCrystal = null;
    }
    else if (this.ticksExisted % 10 == 0 && this.getHealth() < this.getMaxHealth())
    {
    this.setHealth(this.getHealth() + 1.0F);
    }
    }
    
    if (this.rand.nextInt(10) == 0)
    {
    float f = 32.0F;
    List list = this.worldObj.getEntitiesWithinAABB(EntityFireCrystal.class, this.boundingBox.expand((double)f, (double)f, (double)f));
    EntityFireCrystal entityendercrystal = null;
    double d0 = Double.MAX_VALUE;
    Iterator iterator = list.iterator();
    
    while (iterator.hasNext())
    {
    EntityFireCrystal entityendercrystal1 = (EntityFireCrystal)iterator.next();
    double d1 = entityendercrystal1.getDistanceSqToEntity(this);
    
    if (d1 < d0)
    {
    d0 = d1;
    entityendercrystal = entityendercrystal1;
    }
    }
    
    this.healingEnderCrystal = entityendercrystal;
    }
    }
    
    /**
    * Pushes all entities inside the list away from the enderdragon.
    */
    private void collideWithEntities(List par1List)
    {
    double d0 = (this.dragonPartBody.boundingBox.minX + this.dragonPartBody.boundingBox.maxX) / 2.0D;
    double d1 = (this.dragonPartBody.boundingBox.minZ + this.dragonPartBody.boundingBox.maxZ) / 2.0D;
    Iterator iterator = par1List.iterator();
    
    while (iterator.hasNext())
    {
    Entity entity = (Entity)iterator.next();
    
    if (entity instanceof EntityLivingBase)
    {
    double d2 = entity.posX - d0;
    double d3 = entity.posZ - d1;
    double d4 = d2 * d2 + d3 * d3;
    entity.addVelocity(d2 / d4 * 4.0D, 0.20000000298023224D, d3 / d4 * 4.0D);
    }
    }
    }
    
    /**
    * Attacks all entities inside this list, dealing 5 hearts of damage.
    */
    private void attackEntitiesInList(List par1List)
    {
    for (int i = 0; i < par1List.size(); ++i)
    {
    Entity entity = (Entity)par1List.get(i);
    
    if (entity instanceof EntityLivingBase)
    {
    entity.attackEntityFrom(DamageSource.causeMobDamage(this), 10.0F);
    }
    }
    }
    
    /**
    * Sets a new target for the flight AI. It can be a random coordinate or a nearby player.
    */
    private void setNewTarget()
    {
    this.forceNewTarget = false;
    
    if (this.rand.nextInt(2) == 0 && !this.worldObj.playerEntities.isEmpty())
    {
    this.target = (Entity)this.worldObj.playerEntities.get(this.rand.nextInt(this.worldObj.playerEntities.size()));
    }
    else
    {
    boolean flag = false;
    
    do
    {
    this.targetX = 0.0D;
    this.targetY = (double)(70.0F + this.rand.nextFloat() * 50.0F);
    this.targetZ = 0.0D;
    this.targetX += (double)(this.rand.nextFloat() * 120.0F - 60.0F);
    this.targetZ += (double)(this.rand.nextFloat() * 120.0F - 60.0F);
    double d0 = this.posX - this.targetX;
    double d1 = this.posY - this.targetY;
    double d2 = this.posZ - this.targetZ;
    flag = d0 * d0 + d1 * d1 + d2 * d2 > 100.0D;
    }
    while (!flag);
    
    this.target = null;
    }
    }
    
    /**
    * Simplifies the value of a number by adding/subtracting 180 to the point that the number is between -180 and 180.
    */
    private float simplifyAngle(double par1)
    {
    return (float)MathHelper.wrapAngleTo180_double(par1);
    }
    
    /**
    * Destroys all blocks that aren't associated with 'The End' inside the given bounding box.
    */
    
    public boolean attackEntityFromPart(EntityFireDragonPart par1EntityDragonPart, DamageSource par2DamageSource, float par3)
    {
    if (par1EntityDragonPart != this.dragonPartHead)
    {
    par3 = par3 / 4.0F + 1.0F;
    }
    
    float f1 = this.rotationYaw * (float)Math.PI / 180.0F;
    float f2 = MathHelper.sin(f1);
    float f3 = MathHelper.cos(f1);
    this.targetX = this.posX + (double)(f2 * 5.0F) + (double)((this.rand.nextFloat() - 0.5F) * 2.0F);
    this.targetY = this.posY + (double)(this.rand.nextFloat() * 3.0F) + 1.0D;
    this.targetZ = this.posZ - (double)(f3 * 5.0F) + (double)((this.rand.nextFloat() - 0.5F) * 2.0F);
    this.target = null;
    
    if (par2DamageSource.getEntity() instanceof EntityPlayer || par2DamageSource.isExplosion())
    {
    this.func_82195_e(par2DamageSource, par3);
    }
    
    return true;
    }
    
    /**
    * Called when the entity is attacked.
    */
    public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
    {
    return false;
    }
    
    protected boolean func_82195_e(DamageSource par1DamageSource, float par2)
    {
    return super.attackEntityFrom(par1DamageSource, par2);
    }
    
    /**
    * handles entity death timer, experience orb and particle creation
    */
    protected void onDeathUpdate()
    {
    Minecraft mc = Minecraft.getMinecraft();
    EntityPlayer player = mc.thePlayer;
    ++this.deathTicks;
    isDead = true;
    wantToKillYou = false;
    if (this.deathTicks >= 180 && this.deathTicks <= 200)
    {
    float f = (this.rand.nextFloat() - 0.5F) * 8.0F;
    float f1 = (this.rand.nextFloat() - 0.5F) * 4.0F;
    float f2 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    this.worldObj.spawnParticle("hugeexplosion", this.posX + (double)f, this.posY + 2.0D + (double)f1, this.posZ + (double)f2, 0.0D, 0.0D, 0.0D);
    }
    
    int i;
    int j;
    
    if (!this.worldObj.isRemote)
    {
    if (this.deathTicks > 150 && this.deathTicks % 5 == 0)
    {
    this.playEndSound(player, worldObj);
    i = 2500;
    
    while (i > 0)
    {
    j = EntityXPOrb.getXPSplit(i);
    i -= j;
    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
    }
    }
    
    if (this.deathTicks == 1)
    {
    this.playEndSound(player, worldObj);
    this.worldObj.func_82739_e(1018, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
    }
    }
    
    this.moveEntity(0.0D, 0.10000000149011612D, 0.0D);
    this.renderYawOffset = this.rotationYaw += 20.0F;
    
    if (this.deathTicks == 200 && !this.worldObj.isRemote)
    {
    this.playEndSound(player, worldObj);
    
    i = 5000;
    
    while (i > 0)
    {
    j = EntityXPOrb.getXPSplit(i);
    i -= j;
    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
    }
    this.setDead();
    }
    }
    
    /**
    * Makes the entity despawn if requirements are reached
    */
    protected void despawnEntity() {}
    
    /**
    * Return the Entity parts making up this Entity (currently only for dragons)
    */
    public Entity[] getParts()
    {
    return this.dragonPartArray;
    }
    
    /**
    * Returns true if other Entities should be prevented from moving through this Entity.
    */
    public boolean canBeCollidedWith()
    {
    return false;
    }
    
    public World func_82194_d()
    {
    return this.worldObj;
    }
    
    /**
    * Returns the sound this mob makes while it's alive.
    */
    protected String getLivingSound()
    {
    return "mob.enderdragon.growl";
    }
    
    /**
    * Returns the sound this mob makes when it is hurt.
    */
    protected String getHurtSound()
    {
    return "mob.enderdragon.hit";
    }
    
    /**
    * Returns the volume for the sounds this mob makes.
    */
    protected float getSoundVolume()
    {
    return 5.0F;
    }
    }
    
    

  • Administrateurs

    Tu dois mettre ta musique dans cette méthode : protected String getLivingSound()



  • Merci, je teste :)___
    EDIT : ça ne marche pas.
    Le nouveau code :

    
    protected String getLivingSound()
    {
    String music = "";
    if(this.getHealth() <= 1000.0F && this.getHealth() >= 500.0F)
    {
    music = "dragons:music/boss/fire_dragon";
    }
    else if(this.getHealth() <= 499.0F && this.getHealth() >= 1.0F)
    {
    music = "dragons:music/boss/fire_dragon_second_half";
    }
    return music;
    }
    
    

  • Administrateurs

    Pour jouer un son, toujours des . et non des /



  • Ah merci :D___
    EDIT : ça ne marche pas, je vais vérifier si mes sons commencent par un blanc .


  • Administrateurs

    Le problème c'est que cette fonction fait un playSound et non un playMusic, il faudrait plutôt mettre un playMusic dans la fonction onEntityUpdate (ou quelque chose comme ça).



  • D'accord je teste
    EDIT : J'ai déjà testé dans onLivingUpdate et ça ne marche pas


  • Administrateurs

    Tu as mit quel code ?



  • Je précise que playMusic n'existe pas, j'ai donc testé avec un playRecord


  • Administrateurs

    Heu oui, playRecord.
    this.worldObj.playRecord("nom du son", (int)this.posX, (int)this.posY, (int)this.posZ);
    ça marche pas ?



  • Désolé ça n'a pas l'air de marcher 😞

    Code :
    Dans onLivingUpdate()

    
    if(this.getHealth() <= 999.0F && this.getHealth() >= 500.0F)
    {
    this.worldObj.playRecord("dragons:music.boss.fire_dragon", (int)this.posX, (int)this.posY, (int)this.posZ);
    }
    else if(this.getHealth() <= 499.0F && this.getHealth() >= 1.0F)
    {
    this.worldObj.playRecord("dragons:music.boss.fire_dragon_second_half", (int)this.posX, (int)this.posY, (int)this.posZ);
    }
    
    

    PS : Excuse moi de ne pas t'avoir répondu directement car ces derniers temps je n'ai pas pu venir sur le forum.



  • Essaie de jouer un son de base du jeu, et donne le résultat 🙂



  • on peut faire ne sorte que quand le joueur aggro une entité sa joue la musique?



  • @Gugu42
    Non j'ai testé, ça ne marche pas (en plus comme les sons ne sont pas par défaut et qu'il faut les ajouter ça revient au même).

    @isador34
    Je ne sais pas.

    PS: Encore désolé pour cette longue période sans réponse.


  • Administrateurs

    Mets un System.out.println("quelque chose pour vérifier que le code est exécuté");



  • Att sinon demain je te passe des code qui marche



  • @robin4002
    Ok je teste

    EDIT: le code fonctionne, j'ai un retour à chaque fois (la musique ne marche quand même pas)

    @isador34
    Merci 🙂


    Ah je crois que je viens de comprendre mon erreur (et oui, prendre du recul, ça marche ! :))
    Le code de lancement est dans la méthode getLivingSound(). Or, celle(ci exécute le code à CHAQUE SECONDE (ou tick je sais pas).
    Il faudrait donc que j'utilise une autre méthode ou un condition dans le genre :

    
    if(musiqueFinie == true)
    { lancerMusique(); }
    else
    {}
    
    


  • moi ca mon mod qui jouer de la musique je fessai ca:
    ma classe qui enregistre les sons:

    
    @ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
    try
    {
    event.manager.soundPoolSounds.addSound("modid:tonSon.ogg");
    }
    catch(Exception e)
    {
    System.out.println("Failed to registry sound");
    }
    
    

    et dans ma condition:

    
    FMLClientHandler.instance().getClient().sndManager.playSoundFX("modid:tonSon", 1.0F, 1.0F);