Page 1 of 1

Cloning a ghost onto same position no longer possible?

Posted: Tue Dec 08, 2020 5:00 pm
by ChrislyBear
Hello,

I just noticed, that a change in 1.1 broke my mod "BotPrioritizer."
In a nutshell:
  1. I'm cloning a entity ghost directly over a existing one
  2. and then I'm destroying the original one.
This makes it, that the personal robots can take over if you're near the ghosts, because these build orders are "new".

Now I noticed that it isn't possible anymore to leverage this "bug" (I'd call it feature) for my mod. If a ghost is cloned onto another entity, the function will fail and return nil.
Is there any other way to 100% clone an entity, maybe without placing it first?

Can I "save away" the original entity in a variable, destroy it and then place it again? I tried table.deep_copy from the "flib" library and table.deepcopy from the regular "util" library, but as soon as I destroy the original entity, my copy also becomes invalid.

I'm rather new to modding, so I don't really have an overview over all the possibilites to copy entites. Hopefully someone can help!

Thanks in advance,
Chris

Re: Cloning a ghost onto same position no longer possible?

Posted: Tue Dec 08, 2020 5:10 pm
by PFQNiet
Perhaps you can teleport the ghost out of the way first, then clone it back into its original spot and delete the original after? As far as I can tell, LuaEntity#teleport doesn't check for collisions (you're expected to use LuaSurface#find_non_colliding_position first)

Re: Cloning a ghost onto same position no longer possible?

Posted: Tue Dec 08, 2020 5:16 pm
by eradicator
Assuming you're using LuaEntity.clone(), have you tried using LuaSurface.clone_area/clone_entities/clone_brush instead?

Re: Cloning a ghost onto same position no longer possible?

Posted: Tue Dec 08, 2020 5:35 pm
by ChrislyBear
Great suggestions! Thank you guys! I'll have a look into those; they sound promising.

I also just toyed around with a secondary surface, where I clone my entities to, then remove the original and clone them back. But I don't know the implications of creating a new surface. This could be a bad idea, I don't know.

P.S.: Yes, I'm using Entity.clone(). Sorry for not clearing this up or providing code snippets.

Edit: The teleport suggestion probably won't work, because you cannot teleport transport belts... damn.