Workaround for entity destruction on tile change

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
Earendel
Factorio Staff
Factorio Staff
Posts: 716
Joined: Sun Nov 23, 2014 11:57 am
Contact:

Workaround for entity destruction on tile change

Post by Earendel »

There may already be a workaround for this, but I can't find one.

The problem occurs when you have a tile, and an entity overlapping that tile. The tile get changed, either by mining the tile, or putting flooring down. The change causes the collision mask to change, the entity gets destroyed.

There are times you'd want this to happen, such as landfill removing fish.

But there are times when you don't: You have space platform with an expensive structure on it. You mine a tile accidentally, the structure disappears.

I can see thee solutions to the problem, but there may be a better one.

Option 1:

Two new events: on_pre_player_changed_tile and on_pre_robot_changed_tile

The event return values could be similar to on_player_built_tile, except that tiles would be an array of 'NewTileAndPosition' (instead of old).

A mod maker could then use these events to search for entities in the affected area, check if they would be destroyed.

Option 2:

The game prevents you from mining tiles that would destroy entities. Some entities could have flags to not block tile changes (fish).

The game prevents you from building tiles where they would destroy entities (unless they are flagged to not block tile changes).

Option 3:

Basically like option 2, but instead of preventing the action, it forces the player or bot to perform a mining action on the conflicting entity if possible.
I.e. you try to mine the tile, and entity is in the way, you automatically start mining the entity first.
User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 248
Joined: Fri Feb 16, 2018 5:21 am
Contact:

Re: Workaround for entity destruction on tile change

Post by mrudat »

The platforms mod makes platforms indestructible so long as there is an entity on top to prevent this very thing from happening.
User avatar
Earendel
Factorio Staff
Factorio Staff
Posts: 716
Joined: Sun Nov 23, 2014 11:57 am
Contact:

Re: Workaround for entity destruction on tile change

Post by Earendel »

mrudat wrote: Sun Apr 21, 2019 1:32 am The platforms mod makes platforms indestructible so long as there is an entity on top to prevent this very thing from happening.
Oh nice. I took a look at the code and the idea is pretty clever. Unfortunately doing it that way requires an additional 'immortal' tile for each tile that might be affected. I have at least 3 tiles that would need this treatment, and I can't justify adding 3 new tile types just for this. With Alien Biomes as a dependency the available tile slots are low and people are already going over the 256 tile limit.
Post Reply

Return to “Modding interface requests”