How can I go about manipulating the craft queue?

Place to get help with not working mods / modding interface.
PEBKAC
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Oct 06, 2017 2:04 pm
Contact:

How can I go about manipulating the craft queue?

Post by PEBKAC »

I want to change things in the crafting queue. When the player crafts, say, 5 inserters, first all gears for the 5 inserters are made, then all 5 circuits, then the 5 inserters. I want to break this up from batched production to piecemeal production, but since this is my first modding attempt, I'm a little stumped on how to do certain things. Other mods (and at least the tutorials I've worked through) don't seem to do what I want to do.

So I've managed to tap into the on_pre_player_crafted_item event. Now, I want to
  • see how many of a thing were ordered (doesn't seem to be on the event natively, but I think I can work this out).
  • Nullify this event (no idea how to do this), and
  • Send out X individual crafting requests (again, no idea).
Any ideas on how to accomplish this? Any references I might check out to help me further here?

Hermitude
Burner Inserter
Burner Inserter
Posts: 11
Joined: Wed Jul 05, 2017 8:13 am
Contact:

Re: How can I go about manipulating the craft queue?

Post by Hermitude »

Hello and congrats on your first mod project.

The API has methods for accessing the crafting queue. (TBH I have not used these myself though.)

Take a look at:
LuaControl

Code: Select all

LuaControl.get_craftable_count
LuaControl.begin_crafting
LuaControl.cancel_crafting
LuaControl.crafting_queue_size
LuaControl.crafting_queue
LuaControl.character_crafting_speed_modifier
LuaControl.crafting_speed
LuaControl.crafting_progress
Since LuaPlayer (the player character) inherits from LuaControl, you can use these fields like:

Code: Select all

if (game.player.crafting_queue_size > x) then
   -- your code here
end
To solve your problem more generally, you will probably also want to have a look at the recipes:
LuaRecipePrototype

You can get the game's recipe prototypes from:

Code: Select all

game.recipe_prototypes
If you are new to the whole API itself, you should probably bookmark the following:
Factorio API
LuaGameScript

The latter is the class that provides the `game` object that started off my examples above. For much of the "callable" game logic, `game' is the starting point to the entire API.

Enjoy!

User avatar
dog80
Filter Inserter
Filter Inserter
Posts: 287
Joined: Thu Dec 08, 2016 11:57 pm
Contact:

Re: How can I go about manipulating the craft queue?

Post by dog80 »

just a sidenote: then we also need a way to cancel all recipes with 1 action, instead of this mindless hundret times clicking to cancel all these single orders

Hermitude
Burner Inserter
Burner Inserter
Posts: 11
Joined: Wed Jul 05, 2017 8:13 am
Contact:

Re: How can I go about manipulating the craft queue?

Post by Hermitude »

dog80 wrote:
Thu Nov 07, 2019 6:33 am
just a sidenote: then we also need a way to cancel all recipes with 1 action, instead of this mindless hundret times clicking to cancel all these single orders
This would also be a very easy mod to make. Please feel free to try it out! If you need any assistance, just ask in this thread.

Post Reply

Return to “Modding help”