Page 1 of 1

Entity that is only placeable on another entity

Posted: Sun Sep 17, 2017 7:13 pm
by Alex99
Is there a way to make one entity be only placeable on a certain type of entity?
e.g. an entity that when placed on a tree produces leafs

Then if this is possible then could one have them interact?
e.g. an entity that when placed on an assembly machine adds 2 module slots

Thanks in advance

EDIT: words are hard

Re: Entity that is only placeable on another entity

Posted: Tue Sep 19, 2017 1:43 am
by robertpaulson
if it goes to trees I think you can use :

Code: Select all

{
							type = "create-entity",
							entity_name = "dead-tree",
							check_buildability = true
						},
IFAIK it checks if there is a tree then replaces it with a dead one, its a flag for a target_effects within a projectile. not sure why you wanna create leafs on a tree, but you can replace one with leafs (live tree) if it doesn't have them (dead tree). modification to tree entity might be necessary since they probably don't work both ways in vanilla

regarding the assemblers- to make more module slots you will have to modify the entity prototype, which cannot be done after the prototypes load. so 1stly you will have to make all entities you want this to affect have two versions (vanilla and +2module slots). then you will have to figure it out how to change the existing entity into the upgraded version.

I am still wondering if a "mousover" function exist in game or can be made. This will make it so you simply check what is under your cursor-destroy it and build over a new version. Some up-gradable entities use this mechanic so it is quite possible that it is that simple.

if not then I know there is a way to track all entities that were build by player and assigning them unique IDs, but I have no clue how to do it. AAI vehicles does this so you can look into that. Then you can select the entity, get the ID, get the entity details, replace it with a new upgraded version. It would be clunky but it will do the job.

Re: Entity that is only placeable on another entity

Posted: Wed Sep 20, 2017 12:12 am
by Alex99
Thanks for the reply but i meant to place an entity on another entity and still have both exist
i.e. to continue the tree and leaf example, have a tree, then without destroying or removing the tree, place an entity on the tree then (and this is irreverent) have the placed entity produce leafs.

The reason I abstracted it into the leaf/assembler example is because this is a part of a much larger project that would be impossible to explain a single post while still retaining the issue.

Re: Entity that is only placeable on another entity

Posted: Wed Sep 20, 2017 8:08 am
by Mr.YaR
Also very interested in this.

Re: Entity that is only placeable on another entity

Posted: Wed Sep 20, 2017 11:34 am
by Klonan
Only functionality like this in the game at the moment is with resouces and mining drills

Re: Entity that is only placeable on another entity

Posted: Sat Sep 23, 2017 1:57 pm
by robertpaulson
Klonan wrote:Only functionality like this in the game at the moment is with resouces and mining drills
what about upgrading entities like assembly machines? I can place mk2 on mk1, but obv I cannot place mk2 on a ...furnace lets say... how the game knows what i'm trying to build on? is there a method written for it?

Re: Entity that is only placeable on another entity

Posted: Sat Sep 23, 2017 2:34 pm
by daniel34
robertpaulson wrote:
Klonan wrote:Only functionality like this in the game at the moment is with resouces and mining drills
what about upgrading entities like assembly machines? I can place mk2 on mk1, but obv I cannot place mk2 on a ...furnace lets say... how the game knows what i'm trying to build on? is there a method written for it?
Because assembling machines have a property that says

Code: Select all

fast_replaceable_group = "assembling-machine",
All entities that can be fast replaced have that property (search for "fast_replaceable_group" in all of the Factorio/data *.lua files). Chests ("container") can be replaced by other chests, inserters can be replaced by other inserters and so on. Currently the replacing entity has to be of the same size as the entity that is replaced, but 0.16 allows you to replace belts with splitters (FFF #206).

In theory you could also make a mod that can fast-replace assemblers with furnaces, but I doubt it would be useful.

Re: Entity that is only placeable on another entity

Posted: Sat Sep 23, 2017 10:31 pm
by robertpaulson
daniel34 wrote: Because assembling machines have a property that says

Code: Select all

fast_replaceable_group = "assembling-machine",
All entities that can be fast replaced have that property (search for "fast_replaceable_group" in all of the Factorio/data *.lua files). Chests ("container") can be replaced by other chests, inserters can be replaced by other inserters and so on. Currently the replacing entity has to be of the same size as the entity that is replaced, but 0.16 allows you to replace belts with splitters (FFF #206).

In theory you could also make a mod that can fast-replace assemblers with furnaces, but I doubt it would be useful.
I see. Well, from this I am deducting that this function has to check where user is trying to build the entity and checks if the entity under it is eligible for an upgrade (similarly to the drills/resource interaction mentioned above). Could it be possible to access this check via lua? is it likely that this function would be implemented in the future, or is it too troublesome?