Date: 2024/01/26 13:18:17 UTC-08:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
TreeFellingCommand:
type: command
name: treefell
description: "Toggles the tree felling feature on for 10 minutes, or off if currently on."
usage: "/treefell"
script:
- if <player.has_flag[tree_felling]>:
- flag player tree_felling:!
- narrate "Tree felling feature has been disabled early."
- else:
- flag player tree_felling:<time[10m]>
- narrate "<aqua>Tree felling feature enabled for 10 minutes."
- wait 10m
- if <player.has_flag[tree_felling]>:
- flag player tree_felling:!
- narrate "<aqua><player.name> Your tree felling feature has now been automatically disabled."
TreeFelling:
type: world
debug: false
events:
on player breaks block:
- if <player.has_flag[tree_felling]>:
- if <player.flag[tree_felling].is_expired>:
- flag player tree_felling:!
- else:
- if <context.block.material.is_log> || <context.block.material.is_leaves> || <context.block.material.name.ends_with[_mushroom_block]>:
- determine passively
- define axe <player.item_in_hand>
- define tree_base <context.block>
- if <[axe].material.name.ends_with[_axe]>:
- define blocks_to_break <proc[recursive_tree_felling].context[<tree_base>].run>
- foreach <[blocks_to_break]> as:tree_block:
- modifyblock <[tree_block]> air
- adjust <[axe]> durability:<[axe].durability.add[1]>
- if <[axe].durability> <[axe].max_durability>:
- inventory clear slot:<player.equipment_slot.held_item>
- stop
recursive_tree_felling:
type: procedure
script:
- define start_block <context[1]>
- define blocks_to_check <list[<start_block>]>
- define checked_blocks <list>
- define blocks_to_break <list>
- while !<[blocks_to_check].is_empty>:
- define current_block <[blocks_to_check].remove[1]>
- define adjacent_blocks <current_block.adjacent_blocks[log|mushroom_block|leaves]>
- foreach <[adjacent_blocks]> as:adj_block:
- if !<[checked_blocks].contains[<[adj_block]>]>:
- define blocks_to_check <[blocks_to_check].include[<[adj_block]>]>
- define checked_blocks <[checked_blocks].include[<[current_block]>]>
- define blocks_to_break <[blocks_to_break].include[<[current_block]>]>
- determine <[blocks_to_break]>