Hello,
I'm wanting my entity to require power that varies with certain conditions. From what I've read, I need to spawn an ElectricEnergyInterface with my entity. I have managed this, but this is showing an accumulator. Again, from what I've read I need to provide a prototype that acts as an invisible entity.
Is there any simple example/mod that uses ElectricEnergyInterface to make an entity require power?
Thank you.
Simple example of ElectricEnergyInterface
Re: Simple example of ElectricEnergyInterface
The default `electric-energy-interface` is a configurable "cheat" item for playing with energy in creative mode.
You can create your own entity of the `electric-energy-interface` type, and configure it with some sensible default values and invisible graphics. Then, in script, you can set its actual power consumption.
You can create your own entity of the `electric-energy-interface` type, and configure it with some sensible default values and invisible graphics. Then, in script, you can set its actual power consumption.
Re: Simple example of ElectricEnergyInterface
Thank you, I don't suppose you know of any example laying around or mod that demonstrates this at all do you to get things going?
Re: Simple example of ElectricEnergyInterface
I don't have any full examples to hand, but the basic idea is:
Then you can place this entity and adjust its consumption via script:
If you don't know the max consumption or it's potentially unbounded, you can set a "reasonable" limit in the `data:extend`, and then dynamically adjust it after setting `entity.power_usage`:
Code: Select all
data:extend{
{
type = "electric-energy-interface",
name = "my-entity",
energy_source = {
type = "electric",
buffer_capacity = "...", -- ideally set to 1/60 of the max consumption of the entity - any less and it won't work properly
usage_priority = "secondary-input",
drain = "0W"
},
pictures = { ... },
-- minable, collision box, selection box etc.
}
}
Code: Select all
local entity = surface.create_entity{
name = "my-entity",
position = ...,
force = "player"
}
entity.power_usage = 10*1000*1000/60 -- 10MW, the /60 is because power_usage is per-tick
Code: Select all
entity.electric_buffer_size = math.max(entity.electric_buffer_size, entity.power_usage)