示例#1
0
  /**
   * >>>>>>> dev Damage an item based on the amount of Blocks it can mine
   *
   * @param item Item to damage
   * @param blocks amount of blocks the item can break
   * @return the damaged Item, can be completely broken
   */
  public static ItemStack damage(ItemStack item, short blocks) {
    short maxDurability = item.getType().getMaxDurability();
    Validate.isTrue(maxDurability > 1, "This item is not damageable");
    if (blocks <= 0) return item;

    short damagePerBlock = (short) (maxDurability / blocks);
    // Because tooldmg is an int we have to sometimes break the tool twice, I couldn't find the flaw
    // in the first formula so oh well....
    double percent =
        damagePerBlock > 1
            ? (maxDurability % blocks) / (double) maxDurability
            : ((double) maxDurability / blocks) - damagePerBlock;

    if (damagePerBlock > 0 || percent > 0.0D) {
      int durability = item.getDurability();
      durability += damagePerBlock;

      if (OurRandom.nextDouble() < percent) durability += (damagePerBlock > 0 ? damagePerBlock : 1);

      item.setDurability((short) durability);
    }
    return item;
  }
示例#2
0
 public static Vector randomDir() {
   double x = OurRandom.nextDouble() - 1.0;
   double y = 0.0;
   double z = OurRandom.nextDouble() - 1.0;
   return new Vector(x, y, z);
 }