Exemplo n.º 1
0
  public static boolean canHarvestBlock(Block block, EntityPlayer player, int metadata) {
    if (block.blockMaterial.isToolNotRequired()) {
      return true;
    }

    ItemStack stack = player.inventory.getCurrentItem();
    if (stack == null) {
      return player.canHarvestBlock(block);
    }

    List info = toolClasses.get(stack.getItem());
    if (info == null) {
      return player.canHarvestBlock(block);
    }

    Object[] tmp = info.toArray();
    String toolClass = (String) tmp[0];
    int harvestLevel = (Integer) tmp[1];

    Integer blockHarvestLevel = toolHarvestLevels.get(Arrays.asList(block, metadata, toolClass));
    if (blockHarvestLevel == null) {
      return player.canHarvestBlock(block);
    }

    if (blockHarvestLevel > harvestLevel) {
      return false;
    }
    return true;
  }
Exemplo n.º 2
0
  public static boolean canToolHarvestBlock(Block block, int metadata, ItemStack stack) {
    if (stack == null) return false;
    List info = toolClasses.get(stack.getItem());
    if (info == null) return false;

    Object[] tmp = info.toArray();
    String toolClass = (String) tmp[0];
    int harvestLevel = (Integer) tmp[1];

    Integer blockHarvestLevel = toolHarvestLevels.get(Arrays.asList(block, metadata, toolClass));
    return !(blockHarvestLevel == null || blockHarvestLevel > harvestLevel);
  }