How to restore information for undo?

Place to get help with not working mods / modding interface.
Post Reply
Jaren Taq
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sat Nov 28, 2020 8:26 am
Contact:

How to restore information for undo?

Post by Jaren Taq »

Hello,

I have a custom entity, for which I store additional information in a global table referenced by unit_number. For copy/paste/blueprint I am able to save and restore these information using tags.

Now I also want to restore this information after I mined this entity and restore its ghost with undo. Is this possible?
What I basically need is something like this:

Code: Select all

function on_player_entity_mined(event)
  if event.entity.name == "my-entity" then
    -- these tags are stored in the ghost, which is created with undo
    event.tags = create_tags(event.entity)
  end
end
This information is only relevant for the undo process, I don't want to save the information in the item.

Can someone help me with this?

Thanks, Jaren

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

Re: How to restore information for undo?

Post by eradicator »

TL;DR: No.

I think undo just creates a new ghost at the old position (in a quick test they all have different unit_numbers). Thus there is no inherit relation between the original entity and the new ghost. And as the ghost doesn't even exist if the player doesn't press undo i think your only choice is to remember the entity position and then try to figure out if any particular ghost in on_built_entity was built using undo or not...
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.

Post Reply

Return to “Modding help”