How to draw a light only when target entity is powered

Place to get help with not working mods / modding interface.
ThePlash
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 01, 2019 3:49 am
Contact:

How to draw a light only when target entity is powered

Post by ThePlash »

Hello!

In my mod I'm adding a technology that makes roboports emit light during the night. To achieve this, I'm using rendering.draw_light() with minimum_darkness = 0.5

Now I need them to stop emitting light if they get disconnected from power. I'm already tracking the ID of the light associated with the roboport, but I have no clue about how to react to a change in their power status (powered to unpowered and vice versa).

Is there a way to do this?

Another idea i have is to use a dummy invisible lamp entity placed over the roboport so I can leverage the lamp logic, but I'm wondering if there's another way that doesn't require spawning an additional entity for each roboport on the map...

Any suggestion?

Thanks!
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to draw a light only when target entity is powered

Post by eradicator »

Spawning extra lamps is way cheaper than on_tick scanning every roboport all the time just to see if it has power. Because that's the only thing you could do.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
ThePlash
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Jun 01, 2019 3:49 am
Contact:

Re: How to draw a light only when target entity is powered

Post by ThePlash »

eradicator wrote: Thu Jun 06, 2019 4:42 pm Spawning extra lamps is way cheaper than on_tick scanning every roboport all the time just to see if it has power. Because that's the only thing you could do.
Just as i thought... i'll probably go the lamp entity way

Thanks
Post Reply

Return to “Modding help”