Allow "ammo" as ItemPrototypeFilter

Things that already exist in the current mod API
Pi-C
Smart Inserter
Smart Inserter
Posts: 1726
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Allow "ammo" as ItemPrototypeFilter

Post by Pi-C »

We already can use

Code: Select all

fuel_items = game.get_filtered_item_prototypes({ {filter = "fuel"} })
to get a list of all items with a fuel_value. Could we get a similar filter "ammo", please? This would make it possible to simply use

Code: Select all

ammo_items = game.get_filtered_item_prototypes({ {filter = "ammo"} })
instead of

Code: Select all

local ammo_items = {}
for i_name, i_proto in pairs(game.item_prototypes) do
  ammo_type = i_proto.get_ammo_type()
  ammo_items[i_name] = ammo_type and ammo_type.category and i_proto
end
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Bilka
Factorio Staff
Factorio Staff
Posts: 3309
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Allow "ammo" as ItemPrototypeFilter

Post by Bilka »

Use this:

Code: Select all

game.get_filtered_item_prototypes({{filter = "type", type = "ammo"}})
Something like filter = "tool" returns everything that is a tool prototype, including its children like repair-tool. Using the "type" filter and an item prototype type (like "ammo") returns only prototypes with that exact type.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1726
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Allow "ammo" as ItemPrototypeFilter

Post by Pi-C »

Bilka wrote: Thu Jun 27, 2024 1:39 pm Use this:

Code: Select all

game.get_filtered_item_prototypes({{filter = "type", type = "ammo"}})
Thanks! That should have been a nobrainer as I've used the 'type' filter before. But I've somehow forgotten that 'ammo' is regarded as an item with just another type … Sorry for the noise! :oops:
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Already exists”