// get the color value at the given point
  public Vec3 getColor(Vec3 p, Vec3 n, Vec3 d, Vec3 difCol, Vec3 spCol, int exp) {
    Vec3 color = new Vec3(0, 0, 0);
    Vec3 l = getDir().negate();
    Ray newRay = new Ray(p, l);
    HitRecord srec = new HitRecord();

    if (Data.getSettings().isA()) {
      if (Data.hasIntersection(newRay, 0.001, Double.POSITIVE_INFINITY, srec)) {
        // System.out.println("In shadow");
        return color;
      } else {
        l = l.normalize();

        if (Data.getSettings().isD()) {
          double nDotl = n.dotProduct(l);
          color = color.addVec(difCol.multScalar(i * Math.max(0, nDotl)));
        }

        if (Data.getSettings().isS()) {
          Vec3 h = l.subVec(d).normalize();
          double nDotH = n.dotProduct(h);
          color = color.addVec(spCol.multScalar(i * Math.pow(Math.max(0, nDotH), exp)));
        }
      }
    } else {
      l = l.normalize();

      if (Data.getSettings().isD()) {
        double nDotl = n.dotProduct(l);
        color = color.addVec(difCol.multScalar(i * Math.max(0, nDotl)));
      }

      if (Data.getSettings().isS()) {
        Vec3 h = l.subVec(d).normalize();
        double nDotH = n.dotProduct(h);
        color = color.addVec(spCol.multScalar(i * Math.pow(Math.max(0, nDotH), exp)));
      }
    }

    return color;
  }
  /** Applies a velocity to each of the entities pushing them away from each other. Args: entity */
  public void applyEntityCollision(Entity par1Entity) {
    if (!this.worldObj.isRemote) {
      if (par1Entity != this.riddenByEntity) {
        if (par1Entity instanceof EntityLiving
            && !(par1Entity instanceof EntityPlayer)
            && !(par1Entity instanceof EntityIronGolem)
            && this.minecartType == 0
            && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.01D
            && this.riddenByEntity == null
            && par1Entity.ridingEntity == null) {
          par1Entity.mountEntity(this);
        }

        double var2 = par1Entity.posX - this.posX;
        double var4 = par1Entity.posZ - this.posZ;
        double var6 = var2 * var2 + var4 * var4;

        if (var6 >= 9.999999747378752E-5D) {
          var6 = (double) MathHelper.sqrt_double(var6);
          var2 /= var6;
          var4 /= var6;
          double var8 = 1.0D / var6;

          if (var8 > 1.0D) {
            var8 = 1.0D;
          }

          var2 *= var8;
          var4 *= var8;
          var2 *= 0.10000000149011612D;
          var4 *= 0.10000000149011612D;
          var2 *= (double) (1.0F - this.entityCollisionReduction);
          var4 *= (double) (1.0F - this.entityCollisionReduction);
          var2 *= 0.5D;
          var4 *= 0.5D;

          if (par1Entity instanceof EntityMinecart) {
            double var10 = par1Entity.posX - this.posX;
            double var12 = par1Entity.posZ - this.posZ;
            Vec3 var14 =
                this.worldObj.getWorldVec3Pool().getVecFromPool(var10, 0.0D, var12).normalize();
            Vec3 var15 =
                this.worldObj
                    .getWorldVec3Pool()
                    .getVecFromPool(
                        (double) MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F),
                        0.0D,
                        (double) MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F))
                    .normalize();
            double var16 = Math.abs(var14.dotProduct(var15));

            if (var16 < 0.800000011920929D) {
              return;
            }

            double var18 = par1Entity.motionX + this.motionX;
            double var20 = par1Entity.motionZ + this.motionZ;

            if (((EntityMinecart) par1Entity).minecartType == 2 && this.minecartType != 2) {
              this.motionX *= 0.20000000298023224D;
              this.motionZ *= 0.20000000298023224D;
              this.addVelocity(par1Entity.motionX - var2, 0.0D, par1Entity.motionZ - var4);
              par1Entity.motionX *= 0.949999988079071D;
              par1Entity.motionZ *= 0.949999988079071D;
            } else if (((EntityMinecart) par1Entity).minecartType != 2 && this.minecartType == 2) {
              par1Entity.motionX *= 0.20000000298023224D;
              par1Entity.motionZ *= 0.20000000298023224D;
              par1Entity.addVelocity(this.motionX + var2, 0.0D, this.motionZ + var4);
              this.motionX *= 0.949999988079071D;
              this.motionZ *= 0.949999988079071D;
            } else {
              var18 /= 2.0D;
              var20 /= 2.0D;
              this.motionX *= 0.20000000298023224D;
              this.motionZ *= 0.20000000298023224D;
              this.addVelocity(var18 - var2, 0.0D, var20 - var4);
              par1Entity.motionX *= 0.20000000298023224D;
              par1Entity.motionZ *= 0.20000000298023224D;
              par1Entity.addVelocity(var18 + var2, 0.0D, var20 + var4);
            }
          } else {
            this.addVelocity(-var2, 0.0D, -var4);
            par1Entity.addVelocity(var2 / 4.0D, 0.0D, var4 / 4.0D);
          }
        }
      }
    }
  }
Beispiel #3
0
  /**
   * 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() {
    float var1;
    float var2;

    if (this.worldObj.isRemote) {
      var1 = MathHelper.cos(this.animTime * (float) Math.PI * 2.0F);
      var2 = MathHelper.cos(this.prevAnimTime * (float) Math.PI * 2.0F);

      if (var2 <= -0.3F && var1 >= -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 var3;

    if (this.func_110143_aJ() <= 0.0F) {
      var1 = (this.rand.nextFloat() - 0.5F) * 8.0F;
      var2 = (this.rand.nextFloat() - 0.5F) * 4.0F;
      var3 = (this.rand.nextFloat() - 0.5F) * 8.0F;
      this.worldObj.spawnParticle(
          "largeexplode",
          this.posX + (double) var1,
          this.posY + 2.0D + (double) var2,
          this.posZ + (double) var3,
          0.0D,
          0.0D,
          0.0D);
    } else {
      this.updateDragonEnderCrystal();
      var1 =
          0.2F
              / (MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ)
                      * 10.0F
                  + 1.0F);
      var1 *= (float) Math.pow(2.0D, this.motionY);

      if (this.slowed) {
        this.animTime += var1 * 0.5F;
      } else {
        this.animTime += var1;
      }

      this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);

      if (this.ringBufferIndex < 0) {
        for (int var25 = 0; var25 < this.ringBuffer.length; ++var25) {
          this.ringBuffer[var25][0] = (double) this.rotationYaw;
          this.ringBuffer[var25][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 var4;
      double var6;
      double var8;
      double var26;
      float var33;

      if (this.worldObj.isRemote) {
        if (this.newPosRotationIncrements > 0) {
          var26 = this.posX + (this.newPosX - this.posX) / (double) this.newPosRotationIncrements;
          var4 = this.posY + (this.newPosY - this.posY) / (double) this.newPosRotationIncrements;
          var6 =
              this.posZ
                  + (this.field_110152_bk - this.posZ) / (double) this.newPosRotationIncrements;
          var8 = MathHelper.wrapAngleTo180_double(this.newRotationYaw - (double) this.rotationYaw);
          this.rotationYaw =
              (float) ((double) this.rotationYaw + var8 / (double) this.newPosRotationIncrements);
          this.rotationPitch =
              (float)
                  ((double) this.rotationPitch
                      + (this.newRotationPitch - (double) this.rotationPitch)
                          / (double) this.newPosRotationIncrements);
          --this.newPosRotationIncrements;
          this.setPosition(var26, var4, var6);
          this.setRotation(this.rotationYaw, this.rotationPitch);
        }
      } else {
        var26 = this.targetX - this.posX;
        var4 = this.targetY - this.posY;
        var6 = this.targetZ - this.posZ;
        var8 = var26 * var26 + var4 * var4 + var6 * var6;

        if (this.target != null) {
          this.targetX = this.target.posX;
          this.targetZ = this.target.posZ;
          double var10 = this.targetX - this.posX;
          double var12 = this.targetZ - this.posZ;
          double var14 = Math.sqrt(var10 * var10 + var12 * var12);
          double var16 = 0.4000000059604645D + var14 / 80.0D - 1.0D;

          if (var16 > 10.0D) {
            var16 = 10.0D;
          }

          this.targetY = this.target.boundingBox.minY + var16;
        } else {
          this.targetX += this.rand.nextGaussian() * 2.0D;
          this.targetZ += this.rand.nextGaussian() * 2.0D;
        }

        if (this.forceNewTarget
            || var8 < 100.0D
            || var8 > 22500.0D
            || this.isCollidedHorizontally
            || this.isCollidedVertically) {
          this.setNewTarget();
        }

        var4 /= (double) MathHelper.sqrt_double(var26 * var26 + var6 * var6);
        var33 = 0.6F;

        if (var4 < (double) (-var33)) {
          var4 = (double) (-var33);
        }

        if (var4 > (double) var33) {
          var4 = (double) var33;
        }

        this.motionY += var4 * 0.10000000149011612D;
        this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);
        double var11 = 180.0D - Math.atan2(var26, var6) * 180.0D / Math.PI;
        double var13 = MathHelper.wrapAngleTo180_double(var11 - (double) this.rotationYaw);

        if (var13 > 50.0D) {
          var13 = 50.0D;
        }

        if (var13 < -50.0D) {
          var13 = -50.0D;
        }

        Vec3 var15 =
            this.worldObj
                .getWorldVec3Pool()
                .getVecFromPool(
                    this.targetX - this.posX, this.targetY - this.posY, this.targetZ - this.posZ)
                .normalize();
        Vec3 var40 =
            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 var17 = (float) (var40.dotProduct(var15) + 0.5D) / 1.5F;

        if (var17 < 0.0F) {
          var17 = 0.0F;
        }

        this.randomYawVelocity *= 0.8F;
        float var18 =
            MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0F
                + 1.0F;
        double var19 =
            Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0D + 1.0D;

        if (var19 > 40.0D) {
          var19 = 40.0D;
        }

        this.randomYawVelocity =
            (float)
                ((double) this.randomYawVelocity
                    + var13 * (0.699999988079071D / var19 / (double) var18));
        this.rotationYaw += this.randomYawVelocity * 0.1F;
        float var21 = (float) (2.0D / (var19 + 1.0D));
        float var22 = 0.06F;
        this.moveFlying(0.0F, -1.0F, var22 * (var17 * var21 + (1.0F - var21)));

        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 var23 =
            this.worldObj
                .getWorldVec3Pool()
                .getVecFromPool(this.motionX, this.motionY, this.motionZ)
                .normalize();
        float var24 = (float) (var23.dotProduct(var40) + 1.0D) / 2.0F;
        var24 = 0.8F + 0.15F * var24;
        this.motionX *= (double) var24;
        this.motionZ *= (double) var24;
        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;
      var2 =
          (float) (this.getMovementOffsets(5, 1.0F)[1] - this.getMovementOffsets(10, 1.0F)[1])
              * 10.0F
              / 180.0F
              * (float) Math.PI;
      var3 = MathHelper.cos(var2);
      float var28 = -MathHelper.sin(var2);
      float var5 = this.rotationYaw * (float) Math.PI / 180.0F;
      float var27 = MathHelper.sin(var5);
      float var7 = MathHelper.cos(var5);
      this.dragonPartBody.onUpdate();
      this.dragonPartBody.setLocationAndAngles(
          this.posX + (double) (var27 * 0.5F),
          this.posY,
          this.posZ - (double) (var7 * 0.5F),
          0.0F,
          0.0F);
      this.dragonPartWing1.onUpdate();
      this.dragonPartWing1.setLocationAndAngles(
          this.posX + (double) (var7 * 4.5F),
          this.posY + 2.0D,
          this.posZ + (double) (var27 * 4.5F),
          0.0F,
          0.0F);
      this.dragonPartWing2.onUpdate();
      this.dragonPartWing2.setLocationAndAngles(
          this.posX - (double) (var7 * 4.5F),
          this.posY + 2.0D,
          this.posZ - (double) (var27 * 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[] var29 = this.getMovementOffsets(5, 1.0F);
      double[] var9 = this.getMovementOffsets(0, 1.0F);
      var33 =
          MathHelper.sin(
              this.rotationYaw * (float) Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
      float var32 =
          MathHelper.cos(
              this.rotationYaw * (float) Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
      this.dragonPartHead.onUpdate();
      this.dragonPartHead.setLocationAndAngles(
          this.posX + (double) (var33 * 5.5F * var3),
          this.posY + (var9[1] - var29[1]) * 1.0D + (double) (var28 * 5.5F),
          this.posZ - (double) (var32 * 5.5F * var3),
          0.0F,
          0.0F);

      for (int var30 = 0; var30 < 3; ++var30) {
        EntityDragonPart var31 = null;

        if (var30 == 0) {
          var31 = this.dragonPartTail1;
        }

        if (var30 == 1) {
          var31 = this.dragonPartTail2;
        }

        if (var30 == 2) {
          var31 = this.dragonPartTail3;
        }

        double[] var35 = this.getMovementOffsets(12 + var30 * 2, 1.0F);
        float var34 =
            this.rotationYaw * (float) Math.PI / 180.0F
                + this.simplifyAngle(var35[0] - var29[0]) * (float) Math.PI / 180.0F * 1.0F;
        float var38 = MathHelper.sin(var34);
        float var37 = MathHelper.cos(var34);
        float var36 = 1.5F;
        float var39 = (float) (var30 + 1) * 2.0F;
        var31.onUpdate();
        var31.setLocationAndAngles(
            this.posX - (double) ((var27 * var36 + var38 * var39) * var3),
            this.posY + (var35[1] - var29[1]) * 1.0D - (double) ((var39 + var36) * var28) + 1.5D,
            this.posZ + (double) ((var7 * var36 + var37 * var39) * var3),
            0.0F,
            0.0F);
      }

      if (!this.worldObj.isRemote) {
        this.slowed =
            this.destroyBlocksInAABB(this.dragonPartHead.boundingBox)
                | this.destroyBlocksInAABB(this.dragonPartBody.boundingBox);
      }
    }
  }