Optimize anti beacon to not deadlock worldgen or lag entities #2334
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves #2269 (hopefully)
This works by having caps on living entities that the closest active anti beacon will save its own position into. Then when entities gets an effect, they only need to check the position to see if close enough, anti beacon is still there, and anti beacon is unpowered. Much much much less intensive in modpacks than block scan on every effect add (and these effect scans could load ungenerated chunks too for more lag). Many mods and datapacks expect effect add to be fast and block scans can be problematic. Some tries to add effects every few ticks to refresh the effect timer and so forth. This is when block scans can really start to add up.
We basically move the heavy lifting from entities into antibeacon and antibeacon does entity scan which is much faster than block scan too and wont load ungenerated chunks.
Also added is a check to make sure chunk is fully generated to prevent a deadlock if entity is being spawned by worldgen and given an effect right away. And I noticed the tick field in the block entity was never decremented so the effect clearing that anti beacons do wasn't actually working.