Lothrazar / Cyclic

Minecraft mod written in Java
MIT License
160 stars 96 forks source link

Optimize anti beacon to not deadlock worldgen or lag entities #2334

Closed TelepathicGrunt closed 9 months ago

TelepathicGrunt commented 11 months ago

resolves https://github.com/Lothrazar/Cyclic/issues/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.

Lothrazar commented 10 months ago

oh hey this looks amazing! ill take a look this weekend and try to pull it in.

quick question do you think this LivingEntityCapProvider type system would also work if later i tried to backport this to mc1.18 or even 1.16.5 ?

TelepathicGrunt commented 10 months ago

I don’t think caps changed that much so it should work the same in older Mc versions. At the core, caps it just attaching data to entities and reading it back so even if cap code changed a bit in older forge, the concept is still the same