Powered machine


A library to make machines that normally can't consume power consume power.

Internal
7 days ago
2.0
1.11K
Owner:
Frontrider
Source:
N/A
Homepage:
https://discord.gg/53jAMP5gZV
License:
MIT
Created:
15 days ago
Latest Version:
0.3.3 (7 days ago)
Factorio version:
2.0
Downloaded by:
1.11K users

SECTION FOR PLAYERS:
The mod is optimized for the case when the machine is always running. If you keep it powered, then no scripts will ever run on my side. If it loses power then it will start to check for the power's return about every 3 seconds. If you are afraid of script lag, avoid losing power. this does mean that sometimes it won't turn on right after getting power back, but fewer checks are better.
I don't recommend trying to cheese the 3 second timer with a power switch. The delay is not consistent enough for you to not get random outages.


This mod provides an interface to make any entity consume some kind of power. You can add it to any entity prototypes. The code works on a large number of entity prototypes, but not all of them. Check the final fixes for the up to date full list.
When I say any entity, I mean any. The orbital cannon is an entirely scripted composite entity that uses this to consume electricity.

You have to add this field, to your entity prototype to make it powered.

 powered_machine                        = {
        -- the default is to not make the entity freeze, but you can!
        heating_energy = "0kW",
        energy_usage   = settings.startup["orbital-cannon-energy-consumption"].value,
        -- the custom recipe lets you make this machine consume any arbitrary combinations of items.
        -- you can use any recipe categories, but the default is "powered-machine-powering"
        recipe="powered-machine-power-consumption",
        fluidbox= <an optional fluidbox definition>,
        --tells my system that it should toggle the entity's active state for you.
        auto_toggle=false,
        -- if set to false, no events will be raised or registered.
        raise_event=true,
        -- any energy source.
        energy_source  =
        {
            type = "electric",
            usage_priority = "secondary-input",
            emissions_per_minute = { pollution = 2 },
        },
}

The consumer entity will also disable item insertion if there are no inputs. I don't recommend using item inputs on things that also want to consume items themselves, like roboports or assembling machines.

You will receive events with the name defines.events["powered_machine_enabled_<exact name of your prototype>"], this will have the following structure:

{
entity =  <your current entity>,
-- the current state of the system, if not running then it ran out of power.
running = true/false,
-- these two are internal entities, one is consuming your fuel, the other is doing some checks to see if said fuel is being consumed or not.
-- you don't care if you just want to toggle your own behaviors.
consumer = data.consumer,
checker = data.checker
}

This allows you to toggle whatever behavior you need to toggle depending on power availability.

The orbital cannon receives events with the name powered_machine_enabled_orbital-cannon.

it also comes with default picker dollies support, all involved entities are blacklisted by default.