diff --git a/BP/manifest.json b/BP/manifest.json index 7798b97..701e12c 100644 --- a/BP/manifest.json +++ b/BP/manifest.json @@ -1,7 +1,7 @@ { "format_version": 2, "header": { - "name": "Lumber Axe BP: Chopping made easy! 1.0.5", + "name": "Lumber Axe BP: Chopping made easy! 1.0.5 [DEBUG]", "description": "Cut the whole tree with easy as a lumberjack's pie! We create addons/datapack that will ease your survival plays. \n @Created By: @h_YanG_0A & @Brilliant", "uuid": "4538bab6-a78b-4710-89e5-a2e103e97a6a", "version": [ @@ -45,7 +45,7 @@ "dependencies": [ { "module_name": "@minecraft/server", - "version": "1.8.0-beta" + "version": "1.9.0-beta" }, { "module_name": "@minecraft/server-ui", diff --git a/BP/pack_icon.png b/BP/pack_icon.png index 19c5fcf..a7674c9 100644 Binary files a/BP/pack_icon.png and b/BP/pack_icon.png differ diff --git a/BP/scripts/config.js b/BP/scripts/config.js index 5e80fb1..a46374d 100644 --- a/BP/scripts/config.js +++ b/BP/scripts/config.js @@ -1,34 +1,9 @@ export default { - /** - * Enables debug messages to content logs. - */ - debug: false, - /** - * Lumber Axe durability damage per log destroyed. - */ - durabilityDamagePerBlock: 3, - /** - * 1500 above is not recommended. It Does work but it's not recommended. - */ - chopLimit: 300, - /** - * Included blocks for custom logs, but any custom or vanilla logs also work as long as the block identifier ends with "*_log". - * Check: https://github.com/mcbe-mods/Cut-tree-one-click by Lete114. - */ - includedLog: [], - /** - * Excluded blocks for block logs you don't want to be included in being chopped. - * - * Tip: - * - excludedLog is prioritized over includedLog. - * - It's unnecessary to include log blocks that have "*_log" in their block id. - */ - excludedLog: [], - /** - * Disables the watchDogTerminate Log message. If true, it will only show a warning message when you enable content-ui log in the Minecraft settings. - */ - disableWatchDogTerminateLog: true, + debug: true, + durabilityDamagePerBlock: 3, + chopLimit: 300, + includedLog: [], + excludedLog: [], + disableWatchDogTerminateLog: true, }; - -// version (do not change) -export const VERSION = "1.0.5"; \ No newline at end of file +export const VERSION = "1.0.5"; diff --git a/BP/scripts/functions/tree_utils.js b/BP/scripts/functions/tree_utils.js index 334bfcb..5f557a1 100644 --- a/BP/scripts/functions/tree_utils.js +++ b/BP/scripts/functions/tree_utils.js @@ -1,5 +1,5 @@ -import { EntityEquippableComponent, EquipmentSlot, ItemLockMode, ItemStack } from "@minecraft/server"; -import { MinecraftBlockTypes } from "../modules/vanilla-types/index"; +import { EntityEquippableComponent, EquipmentSlot, ItemDurabilityComponent, ItemEnchantableComponent, ItemLockMode, ItemStack, system } from "@minecraft/server"; +import { MinecraftBlockTypes, MinecraftEnchantmentTypes } from "../modules/vanilla-types/index"; import { validLogBlocks, axeEquipments, stackDistribution, durabilityDamagePerBlock, excludedLog, includedLog, chopLimit } from "../index"; async function treeCut(player, dimension, location, blockTypeId) { const equipment = player.getComponent(EntityEquippableComponent.componentId); @@ -12,9 +12,9 @@ async function treeCut(player, dimension, location, blockTypeId) { return; if (player.isSurvival()) currentHeldAxe.lockMode = ItemLockMode.slot; - const itemDurability = currentHeldAxe.getComponent('minecraft:durability'); - const enchantments = currentHeldAxe.getComponent('minecraft:enchantments').enchantments; - const level = enchantments.hasEnchantment('unbreaking'); + const itemDurability = currentHeldAxe.getComponent(ItemDurabilityComponent.componentId); + const enchantments = (currentHeldAxe.getComponent(ItemEnchantableComponent.componentId)); + const level = enchantments.getEnchantment(MinecraftEnchantmentTypes.Unbreaking)?.level | 0; const unbreakingMultiplier = (100 / (level + 1)) / 100; const unbreakingDamage = durabilityDamagePerBlock * unbreakingMultiplier; const visited = await getTreeLogs(dimension, location, blockTypeId, (itemDurability.maxDurability - itemDurability.damage) / unbreakingDamage); @@ -49,12 +49,14 @@ async function treeCut(player, dimension, location, blockTypeId) { }); } } - for (const group of stackDistribution(visited.size)) { - await new Promise((resolve) => { - dimension.spawnItem(new ItemStack(blockTypeId, group), location); - resolve(); - }); - } + system.runTimeout(async () => { + for (const group of stackDistribution(visited.size)) { + await new Promise((resolve) => { + dimension.spawnItem(new ItemStack(blockTypeId, group), location); + resolve(); + }); + } + }, 5); } function isLogIncluded(blockTypeId) { if (excludedLog.includes(blockTypeId) || blockTypeId.includes('stripped_')) @@ -63,26 +65,32 @@ function isLogIncluded(blockTypeId) { return true; return false; } -async function getTreeLogs(dimension, location, blockTypeId, maxNeeded) { - const visited = new Set(); - let queue = getBlockNear(dimension, location); - while (queue.length > 0) { - if (visited.size >= chopLimit || visited.size >= maxNeeded) { - return visited; - } - const _block = queue.shift(); - if (!_block || !isLogIncluded(_block?.typeId)) - continue; - if (_block.typeId !== blockTypeId) - continue; - const pos = JSON.stringify(_block.location); - if (visited.has(pos)) - continue; - visited.add(pos); - queue.push(...getBlockNear(dimension, _block.location)); - } - queue = []; - return visited; +function getTreeLogs(dimension, location, blockTypeId, maxNeeded) { + return new Promise((resolve) => { + const traversingTreeInterval = system.runInterval(() => { + const visited = new Set(); + let queue = getBlockNear(dimension, location); + while (queue.length > 0) { + if (visited.size >= chopLimit || visited.size >= maxNeeded) { + system.clearRun(traversingTreeInterval); + resolve(visited); + } + const _block = queue.shift(); + if (!_block || !isLogIncluded(_block?.typeId)) + continue; + if (_block.typeId !== blockTypeId) + continue; + const pos = JSON.stringify(_block.location); + if (visited.has(pos)) + continue; + visited.add(pos); + queue.push(...getBlockNear(dimension, _block.location)); + } + queue = []; + system.clearRun(traversingTreeInterval); + resolve(visited); + }, 1); + }); } function getBlockNear(dimension, location, radius = 1) { const centerX = location.x; diff --git a/BP/scripts/main.js b/BP/scripts/main.js index 2ec7196..49ee3ac 100644 --- a/BP/scripts/main.js +++ b/BP/scripts/main.js @@ -1,6 +1,7 @@ -import { world, system, ItemDurabilityComponent, ItemEnchantsComponent, WatchdogTerminateReason } from '@minecraft/server'; +import { world, system, ItemDurabilityComponent, ItemEnchantableComponent, WatchdogTerminateReason } from '@minecraft/server'; import { FormCancelationReason, ActionFormData } from "@minecraft/server-ui"; import { disableWatchDogTerminateLog, durabilityDamagePerBlock, axeEquipments, forceShow, getTreeLogs, isLogIncluded, treeCut } from "./index"; +import { MinecraftEnchantmentTypes } from './modules/vanilla-types/index'; const logMap = new Map(); const playerInteractionMap = new Map(); system.beforeEvents.watchdogTerminate.subscribe((e) => { @@ -45,14 +46,14 @@ world.beforeEvents.itemUseOn.subscribe((e) => { return; playerInteractionMap.set(player.id, true); const itemDurability = currentHeldAxe.getComponent(ItemDurabilityComponent.componentId); - const enchantments = currentHeldAxe?.getComponent(ItemEnchantsComponent.componentId)?.enchantments; - const level = enchantments.hasEnchantment('unbreaking'); + const enchantments = currentHeldAxe.getComponent(ItemEnchantableComponent.componentId); + const level = enchantments.getEnchantment(MinecraftEnchantmentTypes.Unbreaking)?.level | 0; const currentDurability = itemDurability.damage; const maxDurability = itemDurability.maxDurability; const unbreakingMultiplier = (100 / (level + 1)) / 100; const unbreakingDamage = durabilityDamagePerBlock * unbreakingMultiplier; const reachableLogs = (maxDurability - currentDurability) / unbreakingDamage; - getTreeLogs(player.dimension, blockInteracted.location, blockInteracted.typeId, reachableLogs + 1).then(async (treeCollected) => { + getTreeLogs(player.dimension, blockInteracted.location, blockInteracted.typeId, reachableLogs + 1).then((treeCollected) => { const totalDamage = (treeCollected.size) * unbreakingDamage; const totalDurabilityConsumed = currentDurability + totalDamage; const canBeChopped = (totalDurabilityConsumed === maxDurability) || (totalDurabilityConsumed < maxDurability); diff --git a/RP/manifest.json b/RP/manifest.json index 898b5fb..eafe645 100644 --- a/RP/manifest.json +++ b/RP/manifest.json @@ -1,7 +1,7 @@ { "format_version": 2, "header": { - "name": "Lumber Axe RP: Chopping made easy! 1.0.5", + "name": "Lumber Axe RP: Chopping made easy! 1.0.5 [DEBUG]", "description": "Cut the whole tree with easy as a lumberjack's pie! We create addons/datapack that will ease your survival plays. \n @Created By: @h_YanG_0A & @Brilliant", "uuid": "62b4cab4-fa42-405b-bff6-1f47b6958dd6", "version": [ diff --git a/RP/pack_icon.png b/RP/pack_icon.png index 19c5fcf..a7674c9 100644 Binary files a/RP/pack_icon.png and b/RP/pack_icon.png differ diff --git a/package.json b/package.json index fb28177..7d0c2e3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "author": "", "license": "ISC", "dependencies": { - "@minecraft/server": "^1.8.0-beta.1.20.50-stable", + "@minecraft/server": "^1.9.0-beta.1.20.60-stable", "@minecraft/server-ui": "^1.2.0-beta.1.20.30-preview.25" } } diff --git a/setup/mc_manifest.json b/setup/mc_manifest.json index cc64218..a690673 100644 --- a/setup/mc_manifest.json +++ b/setup/mc_manifest.json @@ -38,7 +38,7 @@ "bp_dependencies": [ { "module_name": "@minecraft/server", - "version": "1.8.0-beta" + "version": "1.9.0-beta" }, { "module_name": "@minecraft/server-ui", diff --git a/src/config.ts b/src/config.ts index 5e80fb1..931e423 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,7 @@ export default { /** * Enables debug messages to content logs. */ - debug: false, + debug: true, /** * Lumber Axe durability damage per log destroyed. */ diff --git a/src/functions/tree_utils.ts b/src/functions/tree_utils.ts index fd63eb1..5c4c91a 100644 --- a/src/functions/tree_utils.ts +++ b/src/functions/tree_utils.ts @@ -1,5 +1,5 @@ -import { Block, Dimension, EnchantmentList, EntityEquippableComponent, EquipmentSlot, ItemDurabilityComponent, ItemEnchantsComponent, ItemLockMode, ItemStack, Player, Vector3 } from "@minecraft/server"; -import { MinecraftBlockTypes} from "../modules/vanilla-types/index"; +import { Block, Dimension, EntityEquippableComponent, EquipmentSlot, ItemDurabilityComponent, ItemEnchantableComponent, ItemLockMode, ItemStack, Player, System, Vector3, system } from "@minecraft/server"; +import { MinecraftBlockTypes, MinecraftEnchantmentTypes} from "../modules/vanilla-types/index"; import { validLogBlocks, axeEquipments, stackDistribution, durabilityDamagePerBlock, excludedLog, includedLog, chopLimit } from "../index"; @@ -19,9 +19,9 @@ async function treeCut(player: Player, dimension: Dimension, location: Vector3, if (player.isSurvival()) currentHeldAxe.lockMode = ItemLockMode.slot; //! MAKE THIS D-R-Y - const itemDurability: ItemDurabilityComponent = currentHeldAxe.getComponent('minecraft:durability') as ItemDurabilityComponent; - const enchantments: EnchantmentList = (currentHeldAxe.getComponent('minecraft:enchantments') as ItemEnchantsComponent).enchantments; - const level: number = enchantments.hasEnchantment('unbreaking'); + const itemDurability: ItemDurabilityComponent = currentHeldAxe.getComponent(ItemDurabilityComponent.componentId) as ItemDurabilityComponent; + const enchantments: ItemEnchantableComponent = (currentHeldAxe.getComponent(ItemEnchantableComponent.componentId)); + const level: number = enchantments.getEnchantment(MinecraftEnchantmentTypes.Unbreaking)?.level | 0; const unbreakingMultiplier: number = (100 / (level + 1)) / 100; const unbreakingDamage: number = durabilityDamagePerBlock * unbreakingMultiplier; @@ -30,7 +30,7 @@ async function treeCut(player: Player, dimension: Dimension, location: Vector3, const totalDamage: number = visited.size * unbreakingDamage; const postDamagedDurability: number = itemDurability.damage + totalDamage; - //! USE Lumberjack Axe Interface / Class for this + //! Put this to Durability interface // Check if durabiliy is exact that can chop the tree but broke the axe, then broke it. if (postDamagedDurability + 1 === itemDurability.maxDurability) { equipment.setEquipment(EquipmentSlot.Mainhand, undefined); @@ -45,7 +45,7 @@ async function treeCut(player: Player, dimension: Dimension, location: Vector3, equipment.setEquipment(EquipmentSlot.Mainhand, currentHeldAxe.clone()); } - //! Lumberjack Axe Interface / Class + //! IDK where to put this. for (const group of groupAdjacentBlocks(visited)) { const firstElement = JSON.parse(group[0]); const lastElement = JSON.parse(group[group.length - 1]); @@ -63,12 +63,15 @@ async function treeCut(player: Player, dimension: Dimension, location: Vector3, } } - for (const group of stackDistribution(visited.size)) { - await new Promise((resolve) => { - dimension.spawnItem(new ItemStack(blockTypeId, group), location); - resolve(); - }); - } + system.runTimeout( async () => { + for (const group of stackDistribution(visited.size)) { + await new Promise((resolve) => { + dimension.spawnItem(new ItemStack(blockTypeId, group), location); + resolve(); + }); + } + }, 5); + } function isLogIncluded(blockTypeId: string): boolean { @@ -77,26 +80,32 @@ function isLogIncluded(blockTypeId: string): boolean { return false; } -async function getTreeLogs(dimension: Dimension, location: Vector3, blockTypeId: string, maxNeeded: number): Promise> { +function getTreeLogs(dimension: Dimension, location: Vector3, blockTypeId: string, maxNeeded: number): Promise> { // Modified Version // Author: Lete114 // Project: https://github.com/mcbe-mods/Cut-tree-one-click - const visited: Set = new Set(); - let queue: Block[] = getBlockNear(dimension, location); - while (queue.length > 0) { - if(visited.size >= chopLimit || visited.size >= maxNeeded) { - return visited; - } - const _block: Block = queue.shift(); - if (!_block || !isLogIncluded(_block?.typeId)) continue; - if (_block.typeId !== blockTypeId) continue; - const pos: string = JSON.stringify(_block.location); - if (visited.has(pos)) continue; - visited.add(pos); - queue.push(...getBlockNear(dimension, _block.location)); - } - queue = []; - return visited; + return new Promise>((resolve) => { + const traversingTreeInterval: number = system.runInterval(() => { + const visited: Set = new Set(); + let queue: Block[] = getBlockNear(dimension, location); + while (queue.length > 0) { + if(visited.size >= chopLimit || visited.size >= maxNeeded) { + system.clearRun(traversingTreeInterval); + resolve(visited); + } + const _block: Block = queue.shift(); + if (!_block || !isLogIncluded(_block?.typeId)) continue; + if (_block.typeId !== blockTypeId) continue; + const pos: string = JSON.stringify(_block.location); + if (visited.has(pos)) continue; + visited.add(pos); + queue.push(...getBlockNear(dimension, _block.location)); + } + queue = []; + system.clearRun(traversingTreeInterval); + resolve(visited); + }, 1); + }); } function getBlockNear(dimension: Dimension, location: Vector3, radius: number = 1): Block[] { diff --git a/src/main.ts b/src/main.ts index e699742..86b2849 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ -import { world, ItemStack, system, Block, BlockPermutation, Player, ItemDurabilityComponent, ItemEnchantsComponent, ItemUseOnBeforeEvent, WatchdogTerminateBeforeEvent, WatchdogTerminateReason, EnchantmentList, PlayerLeaveAfterEvent, PlayerBreakBlockAfterEvent } from '@minecraft/server'; +import { world, ItemStack, system, Block, BlockPermutation, Player, ItemDurabilityComponent, ItemEnchantableComponent, ItemUseOnBeforeEvent, WatchdogTerminateBeforeEvent, WatchdogTerminateReason, PlayerLeaveAfterEvent, PlayerBreakBlockAfterEvent, EnchantmentType, EnchantmentTypes } from '@minecraft/server'; import { FormCancelationReason, ActionFormData, ActionFormResponse} from "@minecraft/server-ui"; import { disableWatchDogTerminateLog, durabilityDamagePerBlock ,axeEquipments, forceShow, getTreeLogs, isLogIncluded, treeCut} from "./index" +import { MinecraftEnchantmentTypes } from './modules/vanilla-types/index'; const logMap: Map = new Map(); const playerInteractionMap: Map = new Map(); @@ -47,14 +48,14 @@ world.beforeEvents.itemUseOn.subscribe((e: ItemUseOnBeforeEvent) => { //! MAKE THIS D-R-Y const itemDurability: ItemDurabilityComponent = currentHeldAxe.getComponent(ItemDurabilityComponent.componentId) as ItemDurabilityComponent; - const enchantments: EnchantmentList = (currentHeldAxe?.getComponent(ItemEnchantsComponent.componentId) as ItemEnchantsComponent)?.enchantments; - const level: number = enchantments.hasEnchantment('unbreaking'); + const enchantments: ItemEnchantableComponent = (currentHeldAxe.getComponent(ItemEnchantableComponent.componentId) as ItemEnchantableComponent); + const level: number = enchantments.getEnchantment(MinecraftEnchantmentTypes.Unbreaking)?.level | 0; const currentDurability = itemDurability.damage; const maxDurability = itemDurability.maxDurability; const unbreakingMultiplier: number = (100 / (level + 1)) / 100; const unbreakingDamage: number = durabilityDamagePerBlock * unbreakingMultiplier; const reachableLogs = (maxDurability - currentDurability) / unbreakingDamage; - getTreeLogs(player.dimension, blockInteracted.location, blockInteracted.typeId, reachableLogs + 1).then( async (treeCollected: Set) => { + getTreeLogs(player.dimension, blockInteracted.location, blockInteracted.typeId, reachableLogs + 1).then( (treeCollected: Set) => { const totalDamage: number = (treeCollected.size) * unbreakingDamage; const totalDurabilityConsumed: number = currentDurability + totalDamage; const canBeChopped: boolean = (totalDurabilityConsumed === maxDurability) || (totalDurabilityConsumed < maxDurability); diff --git a/tools/build.py b/tools/build.py index 1c7507b..f531428 100644 --- a/tools/build.py +++ b/tools/build.py @@ -12,7 +12,7 @@ addon_name = json.loads(open('setup/mc_manifest.json', 'r').read()).get("header").get("bp_name") build_pack_name = addon_name[:addon_name.rfind(" BP")] -version_tag = 'v1.20.5x-109' +version_tag = 'v1.20.6x-110' def handleError(err): if err: exit(err)