npo6ka / FNEI

Factorio NEI
https://mods.factorio.com/mods/npo6ka/FNEI
36 stars 21 forks source link

FNEI incorrectly display mining entities that cannot mine a selected resource #62

Closed clampi closed 7 months ago

clampi commented 4 years ago

Encountered in FNEI 0.3.4 The code that displays entities that could craft a recipe, which also handles phony mining recipes, does not filter out mining entities that could mine a resource-category but have no input fluidbox when one would be required to mine a certain resource. Such a resource would be uranium in vanilla, modded resources like that are many. Notable entities that cannot mine resources that require fluids are 'character' and 'burner-mining-drill'.

Here are the changes to FNEI code that will handle said filtering FNEI/utils/crafting_category_list.lua ~ line 85, in function CraftCategoty:create_crafting_category_list()

      -- A building may be used to mine a certain item
      for category, _ in pairs(entity.resource_categories or {}) do
        add_category_entry("mine" .. category, { type = "resource-miner", val = item, mining_speed = entity.mining_speed, ifbox = in_fluidbox})
      end

In the same function, you should also take a look at character entities, those can also mine resources -- Add character 'by hand' recipes You might want to consider the resources that could be mined by said entity, for brevity sake. I reckon that it might not be that useful to a vanilla play, but it is in heavy modded overhauls, at start, to figure out what research is mandatory to get a certain resource.

FNEI/scripts/recipe/gui.lua ~line 293, in function RecipeGui.set_made_in_list(recipe)

      elseif cat.type == 'resource-miner' and cat.mining_speed and Settings.get_val("show-recipes", "buildings", cat.val.name) then
        -- matching resource-category with mining-category is not enough, entity must have an input fluidbox if resource requires a fluid to be mined
        local in_fluidbox_cnt = 0

        for _,prot in pairs(recipe.ingredients) do
          if prot.type == "fluid" then
            in_fluidbox_cnt = in_fluidbox_cnt + 1
          end
        end

        if in_fluidbox_cnt <= (cat.ifbox or 0) then
            element = {
              type = "choose-elem-button",
              name = "item_" .. cat.val.name,
              style = "fnei_default_button",
              elem_type = "item",
              elem_value = cat.val.name,
              locked = true
            }
            -- https://wiki.factorio.com/Mining
            caption = round(recipe.mining_time / (cat.mining_speed), 3)
        end
      end

Here are some screenshots before and after above code changes for a resource that requires a fluid to be mined

Before FNEI_resource_required_fluid_to_mine_before

After FNEI_resource_required_fluid_to_mine_after

npo6ka commented 7 months ago

Thanks, fixed ac792806df2a673e2c4dc3487ddb964f90467b6c