Trees shouldn't regenerate health from 0

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Trees shouldn't regenerate health from 0

Post by Muppet9010 »

If you set a tree's health to 0 to make it indestructible and can not be attacked, it will slowly regenerate health from 0.
0 would seem to have a special significance given it impacts biters and its not a reachable state in normal scenarios without the tree dieing. So I don't believe health should be regenerated from it, as it takes the tree out of this special can't be attacked state.

https://lua-api.factorio.com/latest/Lua ... ity.health


This was originally posted as a bug as I believe it to be, but Rseding believes it is working as "intended" and is therefore a request to change "intended".
viewtopic.php?p=530064

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Trees shouldn't regenerate health from 0

Post by posila »

0 healh is not special invincibility state, entities just can't be attacked when they have 0 health due to implementation details of targeting and damage dealing systems, so the behavior is documented, as some people expected setting health to 0 to kill the entity. I consider setting health to 0 to make an entity invincible to be a hack.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Trees shouldn't regenerate health from 0

Post by Rseding91 »

As Posila said: there's nothing special about 0 health. Simply: to attack an entity you must be able to damage it. To damage an entity it must have a positive health value after subtracting all existing damage-to-be-taken. In the case of 0 health; 0 is not positive so an entity with 0 health doesn't satisfy those requirements and can't be attacked.

If you want to set an entity with health to be indestructible there's an explicit flag to do that: https://lua-api.factorio.com/latest/Lua ... structible
If you want to get ahold of me I'm almost always on Discord.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Trees shouldn't regenerate health from 0

Post by Klonan »

Muppet9010 wrote:
Sun Jan 03, 2021 6:23 pm
If you set a tree's health to 0 to make it indestructible
Why not just set the tree `destructible = false` to make it indestructible?

https://lua-api.factorio.com/latest/Lua ... structible

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Trees shouldn't regenerate health from 0

Post by DaveMcW »

Since the kill check is only performed during a successful attack, would it make sense to add the kill check to the LuaEntity.health setter? Thus eliminating the hack.

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: Trees shouldn't regenerate health from 0

Post by Muppet9010 »

This arose as a work around for this other bug: viewtopic.php?f=7&t=93880

Basically I have a modded mine that makes everything in its radius inactive and indestructible. But other biters that were trying to path through these would often start attacking trees or player force entities, despite them being indestructible.

Mod concept:
Image
https://mods.factorio.com/mod/stasis_mine

When I looked around I found the references to health of 0 made things unattackable and this fixed my issue. On reading the API docs I believed it was saying health of 0 was special. A 0 health entity had no health bar shown, but I saw trees would regain health and thus show a health bar of near 0 after a few seconds. Hence this bug/suggestion around tree health.

So sounds like I have taken a rather confused walk and ended up somewhere odd.

Post Reply

Return to “Modding interface requests”