diff --git a/README.md b/README.md index 6cca1a9..d4c1c84 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ To download, you need to go to the GitHub repository [releases](https://github.c (Drains axe endurance, supports axes with enchanted endurance, stops cutting trees when axe endurance is reduced to 1 point) -![](logo/tree.gif) +![](logo/animation.gif) ## Debugger diff --git a/logo/animation.gif b/logo/animation.gif index 26a4699..ffd079a 100644 Binary files a/logo/animation.gif and b/logo/animation.gif differ diff --git a/logo/tree.gif b/logo/tree.gif deleted file mode 100644 index b54baf0..0000000 Binary files a/logo/tree.gif and /dev/null differ diff --git a/src/behavior_pack/manifest.json b/src/behavior_pack/manifest.json index 3f98b69..3ae266c 100644 --- a/src/behavior_pack/manifest.json +++ b/src/behavior_pack/manifest.json @@ -4,7 +4,7 @@ "description": "pack.description", "name": "pack.name", "uuid": "1c874d6e-707e-484e-9027-0efff2b048a6", - "version": [1, 0, 0], + "version": [1, 0, 1], "min_engine_version": [1, 20, 0] }, "modules": [ @@ -13,14 +13,14 @@ "language": "javascript", "type": "script", "uuid": "9717780a-c69f-4679-bbe6-dbf6dfcdd7de", - "version": [1, 0, 0], + "version": [1, 0, 1], "entry": "scripts/main.js" } ], "dependencies": [ { "module_name": "@minecraft/server", - "version": "1.3.0-beta" + "version": "1.4.0-beta" } ] } diff --git a/src/behavior_pack/scripts/main.ts b/src/behavior_pack/scripts/main.ts index b78dc62..fb9e9ef 100644 --- a/src/behavior_pack/scripts/main.ts +++ b/src/behavior_pack/scripts/main.ts @@ -91,9 +91,11 @@ async function treeCut(location: Vector3, dimension: Dimension, logLocations: Ve }) } -function getLeavesLocations(dimension: Dimension, logLocations: Vector3[]) { +// eslint-disable-next-line max-statements +async function clearLeaves(dimension: Dimension, logLocations: Vector3[]) { const visited = new Set() - const leavesLocations: Vector3[] = [] + const batchSize = 27 // Size of each batch + let counter = 0 for (const logLocation of logLocations) { const locations = getRadiusRange(logLocation) @@ -119,20 +121,21 @@ function getLeavesLocations(dimension: Dimension, logLocations: Vector3[]) { // eslint-disable-next-line max-depth if (isIncludesLog) continue - leavesLocations.push(location) locations.push(...getRadiusRange(block.location)) - } - } - } - return leavesLocations.sort((a, b) => a.y - b.y) -} + // eslint-disable-next-line max-depth + if (counter === batchSize) { + // Add a short delay to allow the event loop to execute the toggle + await new Promise((resolve) => system.runTimeout(resolve)) + counter = 0 + } -// eslint-disable-next-line max-statements -async function clearLeaves(dimension: Dimension, leavesLocations: Vector3[]) { - for (const location of leavesLocations) { - const command = `setblock ${Object.values(location).join(' ')} air destroy` - dimension.runCommand(command) + counter++ + + const command = `setblock ${Object.values(location).join(' ')} air destroy` + dimension.runCommandAsync(command) + } + } } } @@ -154,8 +157,7 @@ world.afterEvents.blockBreak.subscribe(async (e) => { await treeCut(block.location, dimension, logLocations) - const leavesLocations = getLeavesLocations(dimension, logLocations) - await clearLeaves(dimension, leavesLocations) + clearLeaves(dimension, logLocations) } catch (error) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const err = error as any