Cloning a ghost onto same position no longer possible?

Place to get help with not working mods / modding interface.
Post Reply
ChrislyBear
Burner Inserter
Burner Inserter
Posts: 14
Joined: Thu Jul 05, 2018 7:46 am
Contact:

Cloning a ghost onto same position no longer possible?

Post 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

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

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

Post 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)

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

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

Post by eradicator »

Assuming you're using LuaEntity.clone(), have you tried using LuaSurface.clone_area/clone_entities/clone_brush instead?
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.

ChrislyBear
Burner Inserter
Burner Inserter
Posts: 14
Joined: Thu Jul 05, 2018 7:46 am
Contact:

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

Post 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.

Post Reply

Return to “Modding help”