Page 1 of 1

Adding a Hidden-Electric-Energy-Interface to en entity

Posted: Tue Mar 05, 2019 10:35 pm
by archdruidardanos
Hi there,

i try to make an entity to consume energy from the electric network which by default doesn't. In theory it should be achievable by using a hidden-electric-energy-interface which is spawn in addition to the main object.

And using that snippet of code spawns an the entiy i wish for in addition a electric interface which is shown properly in the electric network overview.

Code: Select all

local function on_built( entity )
	local gen = entity.surface.create_entity{name="heei_object", position=entity.position, direction=entity.direction,force=entity.force}
	gen.destructible = true
	gen.minable = false
	return true
	end
But now i got stuck how to get that interface use the energy mentioned in the entity definition:

Code: Select all

  {
    type = "electric-energy-interface",
    name = "heei_object",
    icon = "__ArchdruidsChests__/graphics/object.png",
    icon_size = 32,
    flags = {},
    max_health = 350,
    collision_box = {{0, 0}, {0, 0}},
    selection_box = {{-0, -0}, {0, 0}},
    selectable_in_game = false,
	localised_name = {"item-name.object"},
    energy_source =
    {
      type = "electric",
	  buffer_capacity = "5MJ",
      usage_priority = "primary-input",
	  input_flow_limit = "5MW",
      output_flow_limit = "0KW",
	  drain = "0KW"

    },
    energy_production = "0KW",
    energy_usage = "5MW",
    picture =
    {
      filename = "__core__/graphics/empty.png",
      priority = "extra-high",
      width = 1,
      height = 1
    },
    order = "h-e-e-i"
  }

Any hint how to achieve it ? Additional calculations every x seconds/ticks …. or is that thing just deprecated portion of code and no longer valid to use ?! couldn't find any clue in documentation or web...

so i am looking forward to your ideas.

thanks and regards

Re: Adding a Hidden-Electric-Energy-Interface to en entity

Posted: Wed Mar 06, 2019 8:21 am
by darkfrei
Try to enable GUI of eei for testing, you can set all parameters correctly without restart of the game.
Note that the power in kW is kJ/s, but in-game power is always J/Tick.

Re: Adding a Hidden-Electric-Energy-Interface to en entity

Posted: Wed Mar 06, 2019 10:00 am
by archdruidardanos
darkfrei wrote: Wed Mar 06, 2019 8:21 am Try to enable GUI of eei for testing, you can set all parameters correctly without restart of the game.
Note that the power in kW is kJ/s, but in-game power is always J/Tick.
Where can i achieve that ? Never had been aware that there is a GUI for that stuff. In addition how does that reflect into the entity i created and spawn via control.lua ? Questions above Questions :)

Re: Adding a Hidden-Electric-Energy-Interface to en entity

Posted: Wed Mar 06, 2019 10:17 am
by darkfrei
archdruidardanos wrote: Wed Mar 06, 2019 10:00 am
darkfrei wrote: Wed Mar 06, 2019 8:21 am Try to enable GUI of eei for testing, you can set all parameters correctly without restart of the game.
Note that the power in kW is kJ/s, but in-game power is always J/Tick.
Where can i achieve that ? Never had been aware that there is a GUI for that stuff. In addition how does that reflect into the entity i created and spawn via control.lua ? Questions above Questions :)
https://wiki.factorio.com/Prototype/Ele ... yInterface

Re: Adding a Hidden-Electric-Energy-Interface to en entity

Posted: Wed Mar 06, 2019 10:21 am
by archdruidardanos
thanks will check this out later. I let you know if that helped.


EDIT:

i just checked it and to what ever reason that parameter helped that it was proper displayed in the electric network overview - and it worked. So thanks for that hint.

Re: Adding a Hidden-Electric-Energy-Interface to en entity

Posted: Wed Mar 06, 2019 11:05 pm
by Rseding91
If all you want to do is make an entity that normally consumes power not require power just set the energy_source{type = "void"} and it won't take power anymore.

Re: Adding a Hidden-Electric-Energy-Interface to en entity

Posted: Thu Mar 07, 2019 9:22 am
by archdruidardanos
Rseding91 wrote: Wed Mar 06, 2019 11:05 pm If all you want to do is make an entity that normally consumes power not require power just set the energy_source{type = "void"} and it won't take power anymore.
Nice to know that too, but it still doesn't answer why enable_gui fixed my issue.

Due to from my expectations a property called enable_gui - would enable a gui to do "things" and not make things working out nothingness. In addition i if i have a property energy_consumtion it should be sufficient to use that to enable consumption of energy - but it seems the backend requires the buffer_capacity as well before starts consuming energy.

Maybe in a point in future there will be a proper documentation how those things work so modding is more logical in specific parts. Even with some knowledge and skill in programming it is hard to grasp all the things going on in factorio regarding the modding of some feature. Maybe it just while i expect the backend to read the properties, checking that these are not nonsense and processing them - but it seems the backend uses some kind of Generics to use the modded input - which might explain the confusing stuff i see a lot of people encounter while modding. Anyway - it works so far. thanks for the nice input which lead into the right direction.