/** Attack the specified entity using a ranged attack. */
  public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_) {
    EntityArrow entityarrow =
        new EntityArrow(
            this.worldObj,
            this,
            p_82196_1_,
            1.6F,
            (float) (14 - this.worldObj.difficultySetting.getDifficultyId() * 4));
    int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
    int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
    entityarrow.setDamage(
        (double) (p_82196_2_ * 2.0F)
            + this.rand.nextGaussian() * 0.25D
            + (double) ((float) this.worldObj.difficultySetting.getDifficultyId() * 0.11F));

    if (i > 0) {
      entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
    }

    if (j > 0) {
      entityarrow.setKnockbackStrength(j);
    }

    if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0
        || this.getSkeletonType() == 1) {
      entityarrow.setFire(100);
    }

    this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.worldObj.spawnEntityInWorld(entityarrow);
  }
Exemple #2
0
  /**
   * called when the player releases the use item button. Args: itemstack, world, entityplayer,
   * itemInUseCount
   */
  public void onPlayerStoppedUsing(
      ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_) {
    boolean var5 =
        p_77615_3_.capabilities.isCreativeMode
            || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0;

    if (var5 || p_77615_3_.inventory.hasItem(Items.arrow)) {
      int var6 = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_;
      float var7 = (float) var6 / 20.0F;
      var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;

      if ((double) var7 < 0.1D) {
        return;
      }

      if (var7 > 1.0F) {
        var7 = 1.0F;
      }

      EntityArrow var8 = new EntityArrow(p_77615_2_, p_77615_3_, var7 * 2.0F);

      if (var7 == 1.0F) {
        var8.setIsCritical(true);
      }

      int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_);

      if (var9 > 0) {
        var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D);
      }

      int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_);

      if (var10 > 0) {
        var8.setKnockbackStrength(var10);
      }

      if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0) {
        var8.setFire(100);
      }

      p_77615_1_.damageItem(1, p_77615_3_);
      p_77615_2_.playSoundAtEntity(
          p_77615_3_,
          "random.bow",
          1.0F,
          1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);

      if (var5) {
        var8.canBePickedUp = 2;
      } else {
        p_77615_3_.inventory.consumeInventoryItem(Items.arrow);
      }

      if (!p_77615_2_.isClient) {
        p_77615_2_.spawnEntityInWorld(var8);
      }
    }
  }
  @Override
  public void onPlayerStoppedUsing(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) {
    int j = this.getMaxItemUseDuration(par1ItemStack) - par4;

    ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled()) return;
    j = event.charge;

    boolean flag =
        par3EntityPlayer.capabilities.isCreativeMode
            || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack)
                > 0;

    if (flag || par3EntityPlayer.inventory.hasItem(Items.arrow)) {
      float f = j / 40.0F;
      f = (f * f + f * 2.0F) / 3.0F;
      f *= 0.75F;

      if (f < 0.2D) return;
      if (f > 1.0F) f = 1.0F;

      EntityArrow arrow = new EntityArrow(par2World, par3EntityPlayer, f);
      arrow.setDamage(arrow.getDamage() + 2.0);
      arrow.motionX *= 1.6;
      arrow.motionZ *= 1.6;
      arrow.motionY *= 1.15;
      if (f >= 1.0F) arrow.setIsCritical(true);

      int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
      if (k > 0) arrow.setDamage(arrow.getDamage() + k * 0.5D + 0.5D);

      k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
      if (k > 0) arrow.setKnockbackStrength(k);

      if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
        arrow.setFire(100);

      par1ItemStack.damageItem(1, par3EntityPlayer);
      par2World.playSoundAtEntity(
          par3EntityPlayer,
          "random.bow",
          1.0F,
          1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

      if (flag) arrow.canBePickedUp = 2;
      else par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow);

      if (!par2World.isRemote) par2World.spawnEntityInWorld(arrow);
    }
  }
  public void onPlayerStoppedUsing(
      ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft) {
    boolean var5 =
        playerIn.capabilities.isCreativeMode
            || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
    if (var5 || playerIn.inventory.hasItem(Items.arrow)) {
      int var6 = this.getMaxItemUseDuration(stack) - timeLeft;
      float var7 = (float) var6 / 20.0F;
      var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;
      if ((double) var7 < 0.1D) {
        return;
      }

      if (var7 > 1.0F) {
        var7 = 1.0F;
      }

      EntityArrow var8 = new EntityArrow(worldIn, playerIn, var7 * 2.0F);
      if (var7 == 1.0F) {
        var8.setIsCritical(true);
      }

      int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
      if (var9 > 0) {
        var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D);
      }

      int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
      if (var10 > 0) {
        var8.setKnockbackStrength(var10);
      }

      if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) {
        var8.setFire(100);
      }

      stack.damageItem(1, playerIn);
      worldIn.playSoundAtEntity(
          playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);
      if (var5) {
        var8.canBePickedUp = 2;
      } else {
        playerIn.inventory.consumeInventoryItem(Items.arrow);
      }

      playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
      if (!worldIn.isRemote) {
        worldIn.spawnEntityInWorld(var8);
      }
    }
  }
  /**
   * Helper function for onPlayerStoppedUsing() that allows subclasses to easily overwrite how to
   * apply bow enchantments to the spawned arrow entity
   *
   * @param entityarrow
   * @param stack
   */
  protected void applyEnchantments(EntityArrow entityarrow, ItemStack stack) {
    int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);

    if (j > 0) {
      entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
    }

    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);

    if (k > 0) {
      entityarrow.setKnockbackStrength(k);
    }

    if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
      entityarrow.setFire(100);
    }
  }
  /**
   * called when the player releases the use item button. Args: itemstack, world, entityplayer,
   * itemInUseCount
   */
  @Override
  public void onPlayerStoppedUsing(ItemStack var1, World var2, EntityPlayer var3, int var4) {
    int var6 = this.getMaxItemUseDuration(var1) - var4;
    float var7 = var6 / 20.0F;
    var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;

    if (var7 < 0.1D) return;

    boolean var8 = false;

    if (var7 > 1.0F) {
      if (var7 > 9.0F) {
        var8 = true;
      }

      var7 = 1.0F;
    }

    EntityArrow var9 = new EntityArrow(var2, var3, var7 * 2.0F);

    int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, var1);

    if (var10 > 0) {
      var9.setDamage(var9.getDamage() + var10 * 0.5D + 0.5D);
    }

    int var11 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, var1);

    if (var11 > 0) {
      var9.setKnockbackStrength(var11);
    }

    if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, var1) > 0) {
      var9.setFire(100);
    }

    var1.damageItem(1, var3);
    var2.playSoundAtEntity(
        var3, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);

    if (!var2.isRemote) {
      var2.spawnEntityInWorld(var9);
    }
  }
  @Override
  public void attackEntityWithRangedAttack(EntityLivingBase var1, float var2) {
    EntityArrow entityarrow =
        new EntityArrow(
            this.worldObj, this, var1, Math.max(1F, getDistanceToEntity(var1) / 10F), 1);
    entityarrow.posX = this.posX;
    entityarrow.posY = this.posY + this.getEyeHeight();
    entityarrow.posZ = this.posZ;

    int power =
        EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
    int punch =
        EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
    double damage = (double) (var2 * 3.0F) + this.rand.nextGaussian() * 0.25D;
    entityarrow.setDamage(damage);

    if (power > 0) entityarrow.setDamage(entityarrow.getDamage() + (double) power * 0.5D + 0.5D);
    if (punch > 0) entityarrow.setKnockbackStrength(punch);
    if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0)
      entityarrow.setFire(100);

    this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.worldObj.spawnEntityInWorld(entityarrow);
  }
  @Override
  public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemUse) {

    int draw = this.getMaxItemUseDuration(stack) - itemUse;

    ArrowLooseEvent event = new ArrowLooseEvent(player, stack, draw);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled()) {
      return;
    }
    draw = event.charge;

    boolean flag =
        player.capabilities.isCreativeMode
            || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;

    if (flag || player.inventory.hasItem(Items.arrow)) {
      boolean empowered = isEmpowered(stack);
      float f = draw / 20.0F;
      f = (f * f + f * 2.0F) / 3.0F;

      if (f > 1.0F) {
        f = 1.0F;
      } else if (f < 0.1F) {
        return;
      }
      EntityArrow arrow =
          new EntityArrow(world, player, f * arrowSpeedMultiplier * (empowered ? 1.0F : 1.25F));
      double damage = arrow.getDamage() * arrowDamageMultiplier * (empowered ? 1.0F : 1.25F);
      arrow.setDamage(damage);

      if (f == 1.0F) {
        arrow.setIsCritical(true);
      }
      int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);

      if (k > 0) {
        if (empowered) {
          k++;
        }
        arrow.setDamage(arrow.getDamage() + k * 0.5D + 0.5D);
      }
      int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);

      if (l > 0) {
        if (empowered) {
          l++;
        }
        arrow.setKnockbackStrength(l);
      }
      if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) {
        arrow.setFire(100);
      }
      world.playSoundAtEntity(
          player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

      if (flag) {
        arrow.canBePickedUp = 2;
      } else {
        player.inventory.consumeInventoryItem(Items.arrow);
      }
      if (ServerHelper.isServerWorld(world)) {
        world.spawnEntityInWorld(arrow);
      }
      if (!player.capabilities.isCreativeMode) {
        useEnergy(stack);
      }
    }
  }
  /* Bow usage */
  public void onPlayerStoppedUsing(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) {
    int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4;

    ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, var6);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled()) {
      return;
    }
    var6 = event.charge;

    boolean var5 =
        par3EntityPlayer.capabilities.isCreativeMode
            || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack)
                > 0;

    if (var5 || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID)) {
      float var7 = (float) var6 / 20.0F;
      var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;

      if ((double) var7 < 0.1D) {
        return;
      }

      if (var7 > 1.0F) {
        var7 = 1.0F;
      }

      EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F);

      if (var7 == 1.0F) {
        var8.setIsCritical(true);
      }

      int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);

      if (var9 > 0) {
        var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D);
      }

      int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);

      if (var10 > 0) {
        var8.setKnockbackStrength(var10);
      }

      if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) {
        var8.setFire(100);
      }

      par1ItemStack.damageItem(1, par3EntityPlayer);
      par2World.playSoundAtEntity(
          par3EntityPlayer,
          "random.bow",
          1.0F,
          1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);

      if (var5) {
        var8.canBePickedUp = 2;
      } else {
        par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.itemID);
      }

      if (!par2World.isRemote) {
        par2World.spawnEntityInWorld(var8);
      }
    }
  }