pyanodon / pybugreports

Central bug-report repository for pymods
The Unlicense
6 stars 1 forks source link

if(entity_prototype.mineable_properties) expects a .products field #118

Closed crackalackintv closed 1 year ago

crackalackintv commented 2 years ago

Mod source

PyAE Beta

Which mod are you having an issue with?

Operating system

=Windows 10

What kind of issue is this?

What is the problem?

I was debugging why Fill4Me-fixed isn't working and I dug out why it is failing.

In core/lualib/production-score.lua#22, Factorio expects a .products to be present in the mineable_properties table, if it exists. For e.g. bitumen-seep, it does not have a .products even though it has a minable_properties. This makes the get_raw_resources function throw._

Steps to reproduce

I had Fill4Me installed, but you can most likely just call the core/lualib/production-score:get_raw_resources from anywhere and observe it throwing on bitumen-seep.

Additional context

Relevant code from core/lualib/production-score.lua

local function get_raw_resources()
  local raw_resources = {}
  local entities = game.entity_prototypes
  for name, entity_prototype in pairs (entities) do
    if entity_prototype.resource_category then
      if entity_prototype.mineable_properties then

-- THIS THROWS as it expects .products unconditionally
        for k, product in pairs (entity_prototype.mineable_properties.products) do

__
          raw_resources[product.name] = true
        end
      end
    end
    if entity_prototype.fluid then
      raw_resources[entity_prototype.fluid.name] = true
    end
  end
  return raw_resources
end

Log file

-

crackalackintv commented 2 years ago

Update: Discussed with kingarthur in Discord; it might be a Factorio bug assuming the products field is present. kingarthur suggested waiting for an official update on whether this is intended or not before addressing the issue from py's side.

Which I posted in the factorio discord and were pretty sure is a vanilla bug. I'm going to report it and wait for that before I make any changes

I still got to file an actual bug report for the devs but the consensus is that the behavior is a bug so needs fixed 1 way or the other and not just assuming it exists when it doesn't

ShadowGlass0 commented 2 years ago

It is a vanilla bug. According to the API docs, the products field is optional. https://lua-api.factorio.com/latest/LuaEntityPrototype.html#LuaEntityPrototype.mineable_properties

oorzkws commented 2 years ago

I threw this at Therenas (wube), I'll see if it's officially a documentation issue or a bug.

notnotmelon commented 1 year ago

Closing this as vanilla no longer requires this field. It's been replaced with the results table, which is defined for bitumen seeps.