Esempio n. 1
0
 /** @return Euclidean distance between current position and home chest */
 public double distanceToHome() {
   return Math.sqrt(
       Math.pow(this.posX - homePos.x, 2)
           + Math.pow(this.posY - homePos.y, 2)
           + Math.pow(this.posZ - homePos.z, 2));
 }
Esempio n. 2
0
  @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()) {
      j = event.charge;
      boolean flag =
          par3EntityPlayer.capabilities.isCreativeMode
              || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack)
                  > 0;
      if (flag || par3EntityPlayer.inventory.hasItemStack(new ItemStack(Items.arrow, 2))) {
        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;
        }

        EntityArrowDoubleShot entityarrow =
            new EntityArrowDoubleShot(par2World, par3EntityPlayer, f * 2.0F);
        EntityArrowDoubleShot entityarrow1 =
            new EntityArrowDoubleShot(par2World, par3EntityPlayer, f * 2.0F);
        entityarrow.motionX += Math.random() * 0.4D - 0.2D;
        entityarrow.motionY += Math.random() * 0.4D - 0.2D;
        entityarrow.motionZ += Math.random() * 0.4D - 0.2D;
        entityarrow1.motionX += Math.random() * 0.4D - 0.2D;
        entityarrow1.motionY += Math.random() * 0.4D - 0.2D;
        entityarrow1.motionZ += Math.random() * 0.4D - 0.2D;
        entityarrow.setDamage(entityarrow.getDamage() + 0.5D);
        entityarrow1.setDamage(entityarrow.getDamage() + 0.5D);
        if (f == 1.0F) {
          entityarrow.setIsCritical(true);
          entityarrow1.setIsCritical(true);
        }

        int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
        if (k > 0) {
          entityarrow.setDamage(entityarrow.getDamage() + (double) k * 0.5D + 0.5D);
          entityarrow1.setDamage(entityarrow.getDamage() + (double) k * 0.5D + 0.5D);
        }

        int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
        if (l > 0) {
          entityarrow.setKnockbackStrength(l);
          entityarrow1.setKnockbackStrength(l);
        }

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

        par1ItemStack.damageItem(1, par3EntityPlayer);
        par2World.playSoundAtEntity(
            par3EntityPlayer,
            "random.bow",
            1.0F,
            1.0F / (Item.itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
        if (flag) {
          entityarrow.canBePickedUp = 2;
          entityarrow1.canBePickedUp = 2;
        } else {
          par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow);
          par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow);
        }

        if (!par2World.isRemote) {
          par2World.spawnEntityInWorld(entityarrow);
          par2World.spawnEntityInWorld(entityarrow1);
        }
      }
    }
  }