Beispiel #1
0
  /**
   * called when the player releases the use item button. Args: itemstack, world, entityplayer,
   * itemInUseCount
   */
  public void a(ItemStack var1, World var2, EntityHuman var3, int var4) {
    // Forge start
    int var5 = this.a(var1) - var4;
    ArrowLooseEvent var6 = new ArrowLooseEvent(var3, var1, var5);
    MinecraftForge.EVENT_BUS.post(var6);

    if (var6.isCanceled()) {
      return;
    }
    var5 = var6.charge;
    // Forge end
    boolean var7 =
        var3.abilities.canInstantlyBuild
            || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, var1) > 0;

    if (var7 || var3.inventory.e(Item.ARROW.id)) {
      float var8 = (float) var5 / 20.0F;
      var8 = (var8 * var8 + var8 * 2.0F) / 3.0F;

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

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

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

      if (var8 == 1.0F) {
        var9.e(true);
      }

      int var10 = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, var1);

      if (var10 > 0) {
        var9.b(var9.c() + (double) var10 * 0.5D + 0.5D);
      }

      int var11 = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, var1);

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

      if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, var1) > 0) {
        var9.setOnFire(100);
      }

      // CraftBukkit start
      org.bukkit.event.entity.EntityShootBowEvent event =
          org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(
              var3, var1, var9, var8);
      if (event.isCancelled()) {
        event.getProjectile().remove();
        return;
      }

      if (event.getProjectile() == var9.getBukkitEntity()) {
        var2.addEntity(var9);
      }
      // CraftBukkit end

      var1.damage(1, var3);
      var2.makeSound(var3, "random.bow", 1.0F, 1.0F / (d.nextFloat() * 0.4F + 1.2F) + var8 * 0.5F);

      if (var7) {
        var9.fromPlayer = 2;
      } else {
        var3.inventory.d(Item.ARROW.id);
      }
    }
  }
Beispiel #2
0
  public void a(ItemStack itemstack, World world, EntityHuman entityhuman, int i) {
    boolean flag =
        entityhuman.abilities.canInstantlyBuild
            || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, itemstack) > 0;

    if (flag || entityhuman.inventory.b(Items.ARROW)) {
      int j = this.d(itemstack) - i;
      float f = (float) j / 20.0F;

      f = (f * f + f * 2.0F) / 3.0F;
      if ((double) f < 0.1D) {
        return;
      }

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

      EntityArrow entityarrow = new EntityArrow(world, entityhuman, f * 2.0F);
      entityarrow.damage = 2.3D;

      if (f == 1.0F) {
        entityarrow.setCritical(true);
      }

      int k = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, itemstack);

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

      int l = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, itemstack);

      if (l > 0) {
        entityarrow.a(l);
      }

      if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, itemstack) > 0) {
        EntityCombustEvent event = new EntityCombustEvent(entityarrow.getBukkitEntity(), 100);
        entityarrow.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
          entityarrow.setOnFire(event.getDuration());
        }
      }

      // CraftBukkit start
      EntityShootBowEvent event =
          CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, entityarrow, f);
      if (event.isCancelled()) {
        event.getProjectile().remove();
        return;
      }

      if (event.getProjectile() == entityarrow.getBukkitEntity()) {
        world.addEntity(entityarrow);
      }
      // CraftBukkit end

      itemstack.damage(1, entityhuman);

      world.makeSound(
          entityhuman, "random.bow", 1.0F, 1.0F / (g.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
      if (flag) {
        entityarrow.fromPlayer = 2;
      } else {
        entityhuman.inventory.a(Items.ARROW);
      }

      entityhuman.b(StatisticList.USE_ITEM_COUNT[Item.getId(this)]);
    }
  }