public void damage(int amount, CraftEntity source) {
    net.minecraft.src.DamageSource reason = net.minecraft.src.DamageSource.generic;

    if (source instanceof CraftHumanEntity) {
      reason =
          net.minecraft.src.DamageSource.causePlayerDamage(
              ((CraftHumanEntity) source).getMCPlayer());
    } else if (source instanceof CraftLivingEntity) {
      reason =
          net.minecraft.src.DamageSource.causeMobDamage(
              ((CraftLivingEntity) source).getEntityLiving());
    }

    getEntityLiving().damageEntity(reason, amount);
  }
예제 #2
0
  @Override
  public boolean onEntityInteract(EntityPlayer player, Entity entity, boolean isAttack) {

    if (entity instanceof EntityLiving) {
      ItemStack stack = player.getCurrentEquippedItem();
      if (stack != null
          && !player.worldObj.isRemote
          && InfiToolPowers.freezingEnchant(stack, (EntityLiving) entity)) {
        // entity.worldObj.playSoundAtEntity(entity, "random.glass", 1.0F, this.rand.nextFloat() -
        // this.rand.nextFloat() * 0.2F + 1.0F);
        entity.attackEntityFrom(
            DamageSource.causePlayerDamage(player), stack.getDamageVsEntity(entity));
        ((EntityLiving) entity).freeze(500);
        return false;
      } else {
        return true;
      }
    } else {
      return true;
    }
  }
예제 #3
0
 public void attackTargetEntityWithCurrentItem(Entity entity) {
   int i = inventory.getDamageVsEntity(entity);
   if (isPotionActive(Potion.damageBoost)) {
     i += 3 << getActivePotionEffect(Potion.damageBoost).getAmplifier();
   }
   if (isPotionActive(Potion.weakness)) {
     i -= 2 << getActivePotionEffect(Potion.weakness).getAmplifier();
   }
   int j = 0;
   int k = 0;
   if (entity instanceof EntityLiving) {
     k = EnchantmentHelper.getEnchantmentModifierLiving(inventory, (EntityLiving) entity);
     j += EnchantmentHelper.getKnockbackModifier(inventory, (EntityLiving) entity);
   }
   if (isSprinting()) {
     j++;
   }
   if (i > 0 || k > 0) {
     boolean flag =
         fallDistance > 0.0F
             && !onGround
             && !isOnLadder()
             && !isInWater()
             && !isPotionActive(Potion.blindness)
             && ridingEntity == null
             && (entity instanceof EntityLiving);
     if (flag) {
       i += rand.nextInt(i / 2 + 2);
     }
     i += k;
     boolean flag1 = entity.attackEntityFrom(DamageSource.causePlayerDamage(this), i);
     if (flag1) {
       if (j > 0) {
         entity.addVelocity(
             -MathHelper.sin((rotationYaw * 3.141593F) / 180F) * (float) j * 0.5F,
             0.10000000000000001D,
             MathHelper.cos((rotationYaw * 3.141593F) / 180F) * (float) j * 0.5F);
         motionX *= 0.59999999999999998D;
         motionZ *= 0.59999999999999998D;
         setSprinting(false);
       }
       if (flag) {
         onCriticalHit(entity);
       }
       if (k > 0) {
         func_40183_c(entity);
       }
       if (i >= 18) {
         triggerAchievement(AchievementList.overkill);
       }
     }
     ItemStack itemstack = getCurrentEquippedItem();
     if (itemstack != null && (entity instanceof EntityLiving)) {
       itemstack.hitEntity((EntityLiving) entity, this);
       if (itemstack.stackSize <= 0) {
         itemstack.onItemDestroyedByUse(this);
         destroyCurrentEquippedItem();
       }
     }
     if (entity instanceof EntityLiving) {
       if (entity.isEntityAlive()) {
         alertWolves((EntityLiving) entity, true);
       }
       addStat(StatList.damageDealtStat, i);
       int l = EnchantmentHelper.getFireAspectModifier(inventory, (EntityLiving) entity);
       if (l > 0) {
         entity.setFire(l * 4);
       }
     }
     addExhaustion(0.3F);
   }
 }
예제 #4
0
  @Override
  public void onUpdate() {
    super.onUpdate();
    if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
      prevRotationYaw =
          rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
      prevRotationPitch =
          rotationPitch = (float) ((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D);
    }
    if (arrowShake > 0) {
      arrowShake--;
    }
    if (inGround) {
      int i = worldObj.getBlockId(xTile, yTile, zTile);
      int j = worldObj.getBlockMetadata(xTile, yTile, zTile);
      if (i != inTile || j != inData) {
        inGround = false;
        motionX *= rand.nextFloat() * 0.2F;
        motionY *= rand.nextFloat() * 0.2F;
        motionZ *= rand.nextFloat() * 0.2F;
        ticksInGround = 0;
        ticksFlying = 0;
      } else {
        ticksInGround++;
        tickInGround();
        if (ticksInGround == ttlInGround) {
          setDead();
        }
        return;
      }
    } else {
      ticksFlying++;
    }
    tickFlying();
    Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
    vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    if (movingobjectposition != null) {
      vec3d1 =
          Vec3.createVectorHelper(
              movingobjectposition.hitVec.xCoord,
              movingobjectposition.hitVec.yCoord,
              movingobjectposition.hitVec.zCoord);
    }
    Entity entity = null;
    List list =
        worldObj.getEntitiesWithinAABBExcludingEntity(
            this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
    double d = 0.0D;
    for (int k = 0; k < list.size(); k++) {
      Entity entity2 = (Entity) list.get(k);
      if (!canBeShot(entity2)) {
        continue;
      }
      float f3 = hitBox;
      AxisAlignedBB axisalignedbb = entity2.boundingBox.expand(f3, f3, f3);
      MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
      if (movingobjectposition1 == null) {
        continue;
      }
      double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
      if (d1 < d || d == 0.0D) {
        entity = entity2;
        d = d1;
      }
    }

    if (entity != null) {
      movingobjectposition = new MovingObjectPosition(entity);
    }
    if (movingobjectposition != null && (entity != shooter || ticksFlying > 2) && (onHit())) {
      Entity entity1 = movingobjectposition.entityHit;
      if (entity1 != null) {
        if (!worldObj.isRemote) {
          if (onHitTarget(entity1) && hasTorchAttachment == false) {
            if ((entity1 instanceof EntityLiving) && !(entity1 instanceof EntityPlayer)) {
              ++((EntityLiving) entity1).arrowHitTempCounter;
            }

            entity1.attackEntityFrom(
                DamageSource.causePlayerDamage((EntityPlayer) shooter),
                this.arrowCritical ? dmg * 2 : dmg);
            setDead();
          }
        }
      } else {
        xTile = movingobjectposition.blockX;
        yTile = movingobjectposition.blockY;
        zTile = movingobjectposition.blockZ;
        inTile = worldObj.getBlockId(xTile, yTile, zTile);
        inData = worldObj.getBlockMetadata(xTile, yTile, zTile);
        Block block = Block.blocksList[inTile];
        if (block != null && !(block instanceof BlockFlower)) {
          if (onHitBlock(movingobjectposition)) {
            motionX = (float) (movingobjectposition.hitVec.xCoord - posX);
            motionY = (float) (movingobjectposition.hitVec.yCoord - posY);
            motionZ = (float) (movingobjectposition.hitVec.zCoord - posZ);
            float f2 =
                MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
            posX -= (motionX / (double) f2) * 0.05000000074505806D;
            posY -= (motionY / (double) f2) * 0.05000000074505806D;
            posZ -= (motionZ / (double) f2) * 0.05000000074505806D;
            inGround = true;
            arrowShake = 7;
            this.arrowCritical = false;
          }
        }
      }
    }
    if (movingobjectposition != null && !worldObj.isRemote) {
      Entity entity1 = movingobjectposition.entityHit;
      if (entity1 != null && entity1 instanceof EntityLiving && entity1 != shooter) {
        if (hasExplosiveAttachment && ((EntityLiving) entity1).arrowHitTempCounter < 10) {
          this.worldObj.createExplosion(
              this,
              (int) Math.floor(((EntityLiving) entity1).posX),
              (int) ((EntityLiving) entity1).posY,
              (int) Math.floor(((EntityLiving) entity1).posZ),
              1);
        }

        if (hasIceAttachment) {
          ((EntityLiving) entity1)
              .addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 280, 3));
        }

        if (hasPoisonAttachment) {
          ((EntityLiving) entity1).addPotionEffect(new PotionEffect(Potion.poison.id, 280, 3));
        }

        if (hasLightningAttachment) {
          this.worldObj.addWeatherEffect(
              new EntityLightningBolt(this.worldObj, entity1.posX, entity1.posY, entity1.posZ));
          this.setDead();
        }
      }
    }

    FMLLog.info("" + this.inGround);

    posX += motionX;
    posZ += motionZ;
    posY += motionY;
    handleMotionUpdate();
    float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
    rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
    for (rotationPitch = (float) ((Math.atan2(motionY, f1) * 180D) / 3.1415927410125732D);
        rotationPitch - prevRotationPitch < -180F;
        prevRotationPitch -= 360F) {}
    for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) {}
    for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) {}
    for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) {}
    rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
    setPosition(posX, posY, posZ);
  }
예제 #5
0
  /**
   * Attacks for the player the targeted entity with the currently equipped item. The equipped item
   * has hitEntity called on it. Args: targetEntity
   */
  public void attackTargetEntityWithCurrentItem(Entity par1Entity) {
    if (!ForgeHooks.onEntityInteract(this, par1Entity, true)) {
      return;
    }
    ItemStack stack = getCurrentEquippedItem();
    if (stack != null && stack.getItem().onLeftClickEntity(stack, this, par1Entity)) {
      return;
    }

    if (par1Entity.canAttackWithItem()) {
      int var2 = this.inventory.getDamageVsEntity(par1Entity);

      if (this.isPotionActive(Potion.damageBoost)) {
        var2 += 3 << this.getActivePotionEffect(Potion.damageBoost).getAmplifier();
      }

      if (this.isPotionActive(Potion.weakness)) {
        var2 -= 2 << this.getActivePotionEffect(Potion.weakness).getAmplifier();
      }

      int var3 = 0;
      int var4 = 0;

      if (par1Entity instanceof EntityLiving) {
        var4 =
            EnchantmentHelper.getEnchantmentModifierLiving(
                this.inventory, (EntityLiving) par1Entity);
        var3 += EnchantmentHelper.getKnockbackModifier(this.inventory, (EntityLiving) par1Entity);
      }

      if (this.isSprinting()) {
        ++var3;
      }

      if (var2 > 0 || var4 > 0) {
        boolean var5 =
            this.fallDistance > 0.0F
                && !this.onGround
                && !this.isOnLadder()
                && !this.isInWater()
                && !this.isPotionActive(Potion.blindness)
                && this.ridingEntity == null
                && par1Entity instanceof EntityLiving;

        if (var5) {
          var2 += this.rand.nextInt(var2 / 2 + 2);
        }

        var2 += var4;
        boolean var6 = par1Entity.attackEntityFrom(DamageSource.causePlayerDamage(this), var2);

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

          if (var5) {
            this.onCriticalHit(par1Entity);
          }

          if (var4 > 0) {
            this.onEnchantmentCritical(par1Entity);
          }

          if (var2 >= 18) {
            this.triggerAchievement(AchievementList.overkill);
          }

          this.setLastAttackingEntity(par1Entity);
        }

        ItemStack var7 = this.getCurrentEquippedItem();

        if (var7 != null && par1Entity instanceof EntityLiving) {
          var7.hitEntity((EntityLiving) par1Entity, this);

          if (var7.stackSize <= 0) {
            var7.onItemDestroyedByUse(this);
            this.destroyCurrentEquippedItem();
          }
        }

        if (par1Entity instanceof EntityLiving) {
          if (par1Entity.isEntityAlive()) {
            this.alertWolves((EntityLiving) par1Entity, true);
          }

          this.addStat(StatList.damageDealtStat, var2);
          int var8 =
              EnchantmentHelper.getFireAspectModifier(this.inventory, (EntityLiving) par1Entity);

          if (var8 > 0) {
            par1Entity.setFire(var8 * 4);
          }
        }

        this.addExhaustion(0.3F);
      }
    }
  }