private void timber(Block block, int recursionDepth, ItemStack handItem) {
// Check if the recursion depth exceeds the limit
if (recursionDepth >= MAX_RECURSION_DEPTH) {
return;
}
// Check if the block one of the wood-types to be tree felled (All Logs/Stems and Stripped variants)
if (!isLogMaterial(block.getType())) {
return;
}
// TODO: add wood sound to block breaking
block.breakNaturally();
//TODO: axe durability
//handItem.setDurability((short) (handItem.getDurability() - 1.0));
for (int x = -1; x <= 1; x++) {
for (int y = 0; y <= 1; y++) { // Start at base level. Tree felling upward
for (int z = -1; z <= 1; z++) {
if (x == 0 && y == 0 && z == 0) {
continue;
}
Block adjacentBlock = block.getRelative(x, y, z);
// Recursively call timber for the surrounding block with the updated recursion depth
// Returning handItem for calculating axe durability, not related to performance issues
timber(adjacentBlock, recursionDepth + 1, handItem);
}
}
}
}
Hello, currently attempting to make a timber plugin from scratch. Performance wise, the above code works well and as intended for my purposes (ignore the axe calculations). Currently the plugin will instantly feller any connected blocks up to 32 times. However I would like to put a delay (roughly a few ticks) on each individual block broken in the recursive timber method. I've attempted to use BukkitScheduler but run into performance issues with larger trees, not sure how to ask or approach optimizing the performance.