Create light source entity

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
lovely_santa
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

Create light source entity

Post by lovely_santa » Thu Apr 05, 2018 8:45 pm

Hi,

Afther some mods, I keep trying to create light entities, but it never works out right. If I want to create a light source, it always needs a default entity, for example a lamp, a vehicle, etc...

A simple entity with light source would be handy. The ability to force it on and off through the api (example not needing energy at all, but still lighting up) would be a nice addition, or ability to give it an infinite fuel source so it never runs out. With infinity i mean for example support for burner fuel source (rest can be done through scripting already). (Why doesn't this gets supported for all prototypes?)

A nice addition to this enitty could be also able to select the type of light source (the circle uniform one or the cone shaped one + orientation?)

If this forcing on/off get implemented, maybe some extra events could be handy about the darkness of the map (not with the time, in case this gets changed in the base game sometime)

Examples: (mainly the upper two would be extremely usefull)
  • on_dawn : when it gets light (aka vanilla lamps turn off)
  • on_nightfall : when lights turn on
  • on_midnight : middle of the night
  • on_noon: middle of the day
Greetings
lovely_santa
Last edited by lovely_santa on Sun Apr 08, 2018 4:20 pm, edited 2 times in total.
You can find all my mods on the mod portal.
Image

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Create light source entity

Post by betrok » Fri Apr 06, 2018 3:56 am

Yep, such kind of entity will be useful.

For now you can create lamps with oriented light and minimum darkness setting:

Code: Select all

local cone_lamp = table.deepcopy(data.raw.lamp["small-lamp"])
cone_lamp.name = "cone-lamp"
cone_lamp.light = {
	type = "oriented",
	picture =
	{
		filename = "__core__/graphics/light-cone.png",
		priority = "extra-high",
		flags = { "light" },
		scale = 2,
		width = 200,
		height = 200
	},
	minimum_darkness = 0.8,
	shift = {0, -18},
	size = 4,
	intensity = 0.9,
	color = {r=1.0, g=1.0, b=1.0}
}
But there is still all that extra logic with energy sources, circuit and health.

Btw i'm working on light-related mod now as well, pm me if you want to cooperate.

User avatar
lovely_santa
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

Re: Create light source entity

Post by lovely_santa » Fri Apr 06, 2018 8:36 am

The circuit logic is easy: make selection_box = {} so you can't select it in the first place

The energy is another issue that i can't solve yet.. It has no buffer so i can't give it some energy..
Making a new force for it, place invisible pole, invisible simple accumulator and a lamp is like overkill... using burner energy doesn't work either..

Health isn't an issue either.. Make it indestructible (entity.destructible = false)

PS: I've send you a pm
You can find all my mods on the mod portal.
Image

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2160
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Create light source entity

Post by darkfrei » Fri Apr 06, 2018 10:19 am

lovely_santa wrote: The energy is another issue that i can't solve yet.. It has no buffer so i can't give it some energy..
Making a new force for it, place invisible pole, invisible simple accumulator and a lamp is like overkill... using burner energy doesn't work either.
We are need universal power description for all powered entities: electrical, burner, fluid (with temperature), fluid (with burner), and nothing, if this entity doesn't need any energy source.

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

Re: Create light source entity

Post by eradicator » Fri Apr 06, 2018 11:07 am

Feel free to bump my interface request for a free energy source: viewtopic.php?f=28&t=57793 and don't forget to link back to this thread. More examples help suggestions.

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Create light source entity

Post by betrok » Fri Apr 06, 2018 1:45 pm

After some investigations i ended up with such variants of bases for abstract light sources:
  • player(type for characters) — easy way to get 8-way rotatable light. Have tons of extra properties and logic around it. Does not have smooth orientation.
  • explosion — non-rotatable at all. Lifetime is based on animation. Rather small footprint, but there are still sound, smoke and effects.
  • projectile — actuality still is not rotatable: only sprite rotates following target, light does not. Need target to follow it and will dissapear after reaches it(unless speed and acceleration both zero).
  • car with player-type entity mounted as driver — finaly smooth rotation. Tons of extra logic around again though.
Btw rotation(even smooth one) could be emulated with set of various entity protopytes with single difference in orientation of light. But creation and destruction of entity is probably much heavier operation than move and rotation.

User avatar
lovely_santa
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

Re: Create light source entity

Post by lovely_santa » Sat Apr 07, 2018 9:03 pm

betrok wrote:After some investigations i ended up with such variants of bases for abstract light sources:
  • player(type for characters) — easy way to get 8-way rotatable light. Have tons of extra properties and logic around it. Does not have smooth orientation.
  • explosion — non-rotatable at all. Lifetime is based on animation. Rather small footprint, but there are still sound, smoke and effects.
  • projectile — actuality still is not rotatable: only sprite rotates following target, light does not. Need target to follow it and will dissapear after reaches it(unless speed and acceleration both zero).
  • car with player-type entity mounted as driver — finaly smooth rotation. Tons of extra logic around again though.
Btw rotation(even smooth one) could be emulated with set of various entity protopytes with single difference in orientation of light. But creation and destruction of entity is probably much heavier operation than move and rotation.
The car is the only 'hacky' sollution i can find usefull.. or the explosion for the round light.. but what if i want to re-use those to use power.. well then I cant...
Why not allow small-lamps to have the burner fuel enabled just like other prototypes can have a fuel inventory... I guess there is a reason otherwise it would work.. So thats why I requested the simple entity version of a light source.. and the extra events to extend the controlability it...
You can find all my mods on the mod portal.
Image

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 1292
Joined: Fri Nov 06, 2015 7:41 pm
Contact:

Re: Create light source entity

Post by Deadlock989 » Sat Apr 07, 2018 10:20 pm

+1 for a burner lamp.

Xalos
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Mar 08, 2017 6:03 am
Contact:

Re: Create light source entity

Post by Xalos » Sun Apr 08, 2018 4:23 pm

+1 for burner energy_source support for all entities.

Bilka
Factorio Staff
Factorio Staff
Posts: 2134
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Create light source entity

Post by Bilka » Fri Jan 04, 2019 6:14 pm

Hey, I implemented the ability to draw arbitrary lights in 0.17: https://lua-api.factorio.com/0.17.0-pre ... draw_light I hope this helps you, though please let me know if you are still looking for a burner lamp.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2160
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Create light source entity

Post by darkfrei » Fri Jan 04, 2019 7:04 pm

Bilka wrote:
Fri Jan 04, 2019 6:14 pm
Hey, I implemented the ability to draw arbitrary lights in 0.17: https://lua-api.factorio.com/0.17.0-pre ... draw_light I hope this helps you, though please let me know if you are still looking for a burner lamp.

Code: Select all

draw_light{sprite=…,
So this sprite can be used as glowing mask?
Attachments
2018-11-05 20_43_09-Window.png
2018-11-05 20_43_09-Window.png (189.69 KiB) Viewed 641 times

Bilka
Factorio Staff
Factorio Staff
Posts: 2134
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Create light source entity

Post by Bilka » Fri Jan 04, 2019 7:08 pm

darkfrei wrote:
Fri Jan 04, 2019 7:04 pm

Code: Select all

draw_light{sprite=…,
So this sprite can be used as glowing mask?
Yes :)
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2160
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Create light source entity

Post by darkfrei » Sun Mar 03, 2019 2:53 pm

Bilka wrote:
Fri Jan 04, 2019 7:08 pm
darkfrei wrote:
Fri Jan 04, 2019 7:04 pm

Code: Select all

draw_light{sprite=…,
So this sprite can be used as glowing mask?
Yes :)
How it works? https://lua-api.factorio.com/latest/Lua ... draw_light

For example I want to set image as light Factorio_0.17/data/core/graphics/light-medium.png to selected entity:

Code: Select all

/c
local entity = game.player.selected
local filename = "__core__/graphics/light-medium.png"
rendering.draw_light = 
  {
    sprite = filename,
    surface = entity.surface,
    target = entity
  }
Why it doesn't working?

UPD: this works

Code: Select all

/c 
local entity = game.player.selected 
local filename = "utility/light_medium" 
rendering.draw_light {sprite = filename, surface = entity.surface, target = entity}

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2160
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Create light source entity

Post by darkfrei » Sun Mar 03, 2019 4:44 pm

It works great for vanilla sprite.

But not for modded utility (data.raw["utility-sprites"].default):

Code: Select all

data.raw["utility-sprites"].default.riteg_glow =
    {
      filename = "__RITEG__/graphics/riteg-glow.png",
      priority = "extra-high",
      flags = {"light"},
      width = 102, height = 133
    }
and then this command

Code: Select all

/c 
local entity = game.player.selected 
local filename = "utility/riteg_glow" 
rendering.draw_light {sprite = filename, surface = entity.surface, target = entity}
makes error:
2019-03-03 17_43_35-Factorio 0.17.4.png
2019-03-03 17_43_35-Factorio 0.17.4.png (103.71 KiB) Viewed 377 times
But I am sure that it was added to the data.raw:
2019-03-03 17_46_08-Calculator.png
2019-03-03 17_46_08-Calculator.png (21.19 KiB) Viewed 374 times
Last edited by darkfrei on Sun Mar 03, 2019 4:46 pm, edited 1 time in total.

Bilka
Factorio Staff
Factorio Staff
Posts: 2134
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Create light source entity

Post by Bilka » Sun Mar 03, 2019 4:45 pm

You cannot add additional utility sprites. Make a sprite prototype (type = "sprite").
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2160
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Create light source entity

Post by darkfrei » Sun Mar 03, 2019 5:00 pm

Bilka wrote:
Sun Mar 03, 2019 4:45 pm
You cannot add additional utility sprites. Make a sprite prototype (type = "sprite").
Thanks, it works!

Code: Select all

data:extend ({
  {
    type = "sprite",
    name = 'riteg_glow',
    filename = "__RITEG__/graphics/riteg-glow.png",
    priority = "extra-high",
    flags = {"no-crop" },
    width = 102, height = 174
  }
})
2019-03-03 17_59_56-Factorio 0.17.4.png
2019-03-03 17_59_56-Factorio 0.17.4.png (80.74 KiB) Viewed 372 times
Works as well:

Code: Select all

  rendering.draw_light 
    {
      -- sprite = "riteg_glow", -- not nice :(
      sprite = "utility/light_small",
      surface = entity.surface,
      target = entity
    }

Post Reply

Return to “Modding interface requests”

Who is online

Users browsing this forum: No registered users