Skip to content

Commit

Permalink
feat: add isTree function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lete114 committed Oct 4, 2023
1 parent 0d880d8 commit efc79c6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/behavior_pack/manifest.json
Expand Up @@ -4,7 +4,7 @@
"description": "pack.description",
"name": "pack.name",
"uuid": "1c874d6e-707e-484e-9027-0efff2b048a6",
"version": [1, 0, 1],
"version": [1, 0, 2],
"min_engine_version": [1, 20, 0]
},
"modules": [
Expand All @@ -13,7 +13,7 @@
"language": "javascript",
"type": "script",
"uuid": "9717780a-c69f-4679-bbe6-dbf6dfcdd7de",
"version": [1, 0, 1],
"version": [1, 0, 2],
"entry": "scripts/main.js"
}
],
Expand Down
22 changes: 22 additions & 0 deletions src/behavior_pack/scripts/main.ts
Expand Up @@ -26,6 +26,25 @@ const getPlayerAction = (player: Player) => {
return player.isSneaking && currentSlotItem?.typeId.endsWith('_axe')
}

function isTree(dimension: Dimension, location: Vector3, currentBreakBlockTypeId: string) {
const _location = Object.assign({}, location)
let block: Block

do {
_location.y++
block = dimension.getBlock(_location)!
if (block.typeId.includes('leaves')) {
return true
}

if (block.typeId !== currentBreakBlockTypeId) {
return false
}
} while (block.typeId === currentBreakBlockTypeId)

return false
}

function consumeAxeDurability(player: Player, logLocations: Vector3[]) {
const currentSlot = player.selectedSlot
const inventory = player.getComponent('inventory') as EntityInventoryComponent
Expand Down Expand Up @@ -150,6 +169,9 @@ world.afterEvents.blockBreak.subscribe(async (e) => {
const action = getPlayerAction(player)
if (!action) return

const _isTree = isTree(dimension, block.location, currentBreakBlockTypeId)
if (!_isTree) return

const logLocations = getLogLocations(dimension, block.location, currentBreakBlockTypeId)

const survivalPlayer = isSurvivalPlayer(dimension, player)
Expand Down
2 changes: 1 addition & 1 deletion src/behavior_pack/texts/en_US.lang
@@ -1,2 +1,2 @@
pack.name=Cut tree one click v1.0.0
pack.name=Cut tree one click v1.0.2
pack.description=Cutting down trees in minecraft is really a waste of time
2 changes: 1 addition & 1 deletion src/behavior_pack/texts/zh_CN.lang
@@ -1,2 +1,2 @@
pack.name=一键砍树 v1.0.0
pack.name=一键砍树 v1.0.2
pack.description=在《我的世界》中砍树真的是一件很浪费时间的事情

0 comments on commit efc79c6

Please sign in to comment.