Additional-Mods / additionaladditions

A Minecraft Fabric mod that that aims to add additional uses for Copper, Amethyst and Glow Ink Sacs as well as other useful additional additions to the game.
GNU Lesser General Public License v3.0
41 stars 23 forks source link

Amethyst Lamp's checkLampNearby method takes up too much world tick time #32

Closed TelepathicGrunt closed 2 years ago

TelepathicGrunt commented 2 years ago

Copy/pasted from discord:

just wanted to quickly get to you before some modpack makers complain lol. So some people found that this check lamp is nearby mixin https://github.com/Dqu1J/additionaladditions/blob/a43b01bfa76fab8a5eed59ab25f332c61ccf0691/src/main/java/dqu/additionaladditions/mixin/MobEntityMixin.java#L31 is taking up 20% of tick time for a world. https://spark.lucko.me/FBbcLnqlsy?hl=6233

I was thinking, maybe you can use the POI system instead as it should be faster than checking 4000+ blocks. https://github.com/TelepathicGrunt/Bumblezone-Fabric/blob/1.18/src/main/java/com/telepathicgrunt/the_bumblezone/modinit/BzPOI.java https://github.com/TelepathicGrunt/Bumblezone-Fabric/blob/7d175d0a280ed658010f60c3979d256d36586c90/src/main/java/com/telepathicgrunt/the_bumblezone/effects/WrathOfTheHiveEffect.java#L110

Downside of POI is it is not backwards compatible so existing world's lamps wont get the poi attached until they are broken and placed again.

A more backward's compat solution could be to cache the chunk and iterate through it vertically. world.getBlockState is slow due to overhead with getChunk inside. If you take the x/z, do world.getChunk, cache that chunk, and then iterate over top y to bottom y of your search area, and call getBlockState on the cached chunk itself, that will give a massive performance boost. (just be sure to cache the next chunk if the x/z goes into a new chunk)

Dqu1J commented 2 years ago

You can for now disable the amethyst lamps in the config and it will fix the lag