Exemple #1
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);
      }
    }
  }
  @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);
      }
    }
  }