getting a loaded chunk is one of the most hottest pieces of code in the game.
Often, getChunkAt is called for the same chunk multiple times in a row, often
from getType();
Optimize this look up by using a Last Access cache.
should be fully working now as I pretty much fell back to existing
methods so anything touching the unloadQueue set should behave correctly.
And maintained NMS Reflection safe change too
While the previous logic was logically correct, some CB API's before
would request a chunk without removing it from the unload queue.
While this is logically wrong, some plugins seem to be causing unload issues.
This change will make anything using that one API that use to not remove from
queue, no longer remove from queue.
Hopefully other activities on the server will touch the chunk if it REALLY is in use.
Use an optimized method to test if a block position meets a desired light level.
This method benefits from returning as soon as the desired light level matches.
Also Optimize Grass more
Mojang included some sanity checks on arguments passed to the BlockData.
This code results in the Hash look up occuring twice per call, one to test if it exists
and another to retrieve the result.
This code should ideally never be hit, unless mojang released a bad build. We can discover bugs with this as furthur code that never expects a null
would then NPE, so it would not result in hidden issues.
This is super hot code, so removing those checks should give decent gains.
Removing chunks from the unload queue when performing chunk lookups is a costly activity.
It drastically slows down server performance as many methods call getChunkAt, resulting in a bandaid
to skip removing chunks from the unload queue.
This patch optimizes the unload queue to instead use a boolean on the Chunk object itself to mark
if the chunk is active, and then insert into a LinkedList queue.
The benefits here is that all chunk unload queue actions are now O(1) constant time.
A LinkedList will never need to resize, and can be removed from in constant time when
used in a queue like method.
We mark the chunk as active in many places that notify it is still being used, so that
when the chunk unload queue reaches that chunk, and sees the chunk became active again,
it will skip it and move to next.