예제 #1
0
  /** Uses the currently equipped item on the specified entity. Args: entity */
  public void useCurrentItemOnEntity(Entity par1Entity) {
    if (!ForgeHooks.onEntityInteract(this, par1Entity, false)) {
      return;
    }
    if (!par1Entity.interact(this)) {
      ItemStack var2 = this.getCurrentEquippedItem();

      if (var2 != null && par1Entity instanceof EntityLiving) {
        var2.useItemOnEntity((EntityLiving) par1Entity);

        if (var2.stackSize <= 0) {
          var2.onItemDestroyedByUse(this);
          this.destroyCurrentEquippedItem();
        }
      }
    }
  }
예제 #2
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);
      }
    }
  }