Closed Zeranny closed 1 year ago
When it came to profiling the changes, I was using a 45 radius 3D brush @ a 55 block distance. Possibly not the most scientific test ever, but it seems to be quite clear.
Before changes:
After changes to getBlock().getType:
After also adding the change to isLoaded():
The key column is on the right, which is the # of invocations for a single usage of the brush.
(First time pull requester so hopefully this is right)
Overview
When you use a brush and it looks for the block in sight & range, .getBlock().getType() was called every iteration. This change instead only calls this when loc has actually moved a full block. BlockUtils.isLoaded() also changed to only run when it's a new block.
Added "Material air" as a variable so we only need to run parseMaterial() once.
Fixes #99
Description
getClosest() now keeps track of the last location checked and only updates locBlock & locMaterial when the Block position has changed replacing loc.getBlock().getMaterial(). This is also used to only run BlockUtils.isLoaded(loc) when the position has actually updated.
The change reduces the calls by about 50%.
Additionally added the "air" variable prior to the loop, so that parseMaterial() isn't called every iteration, the performance impact is fairly negligable though.
Checklist