Solved Tree Feller Skript!

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

Heres a basic version of one I have.
The version I use is a bit different (uses gravity rather than just breaking the blocks like that GIF)

code_language.skript:
function chain(b: block, n: number, p: player):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log block:
                if block below loop-block is air or any leaves or any log:
                    set block below loop-block to air
                    chain(loop-block,{_n}, {_p})
                    break loop-block naturally
                    play sound "BLOCK_WOOD_BREAK" with volume 1 at location of loop-block for all players
                    wait 10 tick
                    
on break:
    if gamemode of player is survival:
        if event-block is any log block:
            set {_tree} to false
            loop blocks above event-block:
                if loop-block is any leaves:
                    set {_tree} to true
            if {_tree} is true:
                chain(event-block, 0, player)
 
Hi, I'd like to post an "upgraded" version of this script.
I know this is an old post, but Google still offers this as a search result, so lemme explain:
- this code is great as a base template, but has many issues
- it can easily break whole houses if you have the tree accidentaly touching it (house is within a 3 block radius, which can happen)
- I found the checks pretty much not very reliable and inefficient
- I added condition checks that should prevent breaking huge parts of houses (I tested it and it only had issues with jungle trees right next to the house which will not even grow like that in normal game, I had to use WE)
I know I am looping "blocks above" 2 times, but it was necesarry for the code to not have issues with acacia trees :emoji_grinning:

So here's my "upgrade" on the latest version of Skript up to this date for those who are still curious:
(note- I'm using some addons but none should interfere in this code, so it should be vanilla)
Code:
function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log:
                loop blocks above loop-block:
                    loop-block-2 is air:
                        block above loop-block-2 is air
                        exit 1 loop
                    exit 1 loop
                loop blocks above loop-block:
                    loop-block-2 is any leaves
                    chain(loop-block-1, {_n})
                    break loop-block-1
                    wait 10 tick
              
on break:
    player's gamemode is survival
    if event-block is any log:
        loop blocks above event-block:
            set {_l} to 0
            if loop-block is any leaves:
                loop all blocks in radius 2 of loop-block:
                    loop-block-2 is any leaves
                    add 1 to {_l}
                {_l} > 7
                set {_tree} to true
        if {_tree} is true:
            chain(event-block, 0)

Hope this will come in handy to people in 2023+ :emoji_slight_smile:
 
  • Love
Reactions: _PAPER_PLANE_
Hi, I'd like to post an "upgraded" version of this script.
I know this is an old post, but Google still offers this as a search result, so lemme explain:
- this code is great as a base template, but has many issues
- it can easily break whole houses if you have the tree accidentaly touching it (house is within a 3 block radius, which can happen)
- I found the checks pretty much not very reliable and inefficient
- I added condition checks that should prevent breaking huge parts of houses (I tested it and it only had issues with jungle trees right next to the house which will not even grow like that in normal game, I had to use WE)
I know I am looping "blocks above" 2 times, but it was necesarry for the code to not have issues with acacia trees :emoji_grinning:

So here's my "upgrade" on the latest version of Skript up to this date for those who are still curious:
(note- I'm using some addons but none should interfere in this code, so it should be vanilla)
Code:
function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log:
                loop blocks above loop-block:
                    loop-block-2 is air:
                        block above loop-block-2 is air
                        exit 1 loop
                    exit 1 loop
                loop blocks above loop-block:
                    loop-block-2 is any leaves
                    chain(loop-block-1, {_n})
                    break loop-block-1
                    wait 10 tick
              
on break:
    player's gamemode is survival
    if event-block is any log:
        loop blocks above event-block:
            set {_l} to 0
            if loop-block is any leaves:
                loop all blocks in radius 2 of loop-block:
                    loop-block-2 is any leaves
                    add 1 to {_l}
                {_l} > 7
                set {_tree} to true
        if {_tree} is true:
            chain(event-block, 0)

Hope this will come in handy to people in 2023+ :emoji_slight_smile:
Sorry for bumping but I really wanna help who looking for like that.
So I make a new one with working on 1.21.1
Your version is still broken, If I use my axe on placed blocks script dropping all of blocks who I placed.
So here is the fixed version:

Code:
on place of any log:
    set metadata value "placedLog" of event-block to true

on break:
    player's gamemode is survival
    if event-block is any log:
        if metadata value "placedLog" of event-block is not set:
            loop blocks above event-block:
                set {_l} to 0
                if loop-block is any leaves:
                    loop all blocks in radius 2 of loop-block:
                        if loop-block-2 is any leaves:
                            add 1 to {_l}
                    if {_l} > 7:
                        set {_tree} to true
            if {_tree} is true:
                chain(event-block, 0)

function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log:
                if metadata value "placedLog" of loop-block is not set:
                    loop blocks above loop-block:
                        if loop-block-2 is air:
                            block above loop-block-2 is air
                            exit 1 loop
                        exit 1 loop
                    loop blocks above loop-block:
                        if loop-block-2 is any leaves:
                            chain(loop-block-1, {_n})
                            break loop-block-1
                            wait 10 tick
 
Last edited:
Sorry for bumping but I really wanna help who looking for like that.
So I make a new one with working on 1.21.1
Your version is still broken, If I use my axe on placed blocks script dropping all of blocks who I placed.
So here is the fixed version:

Code:
on place of any log:
    set metadata value "placedLog" of event-block to true

on break:
    player's gamemode is survival
    if event-block is any log:
        if metadata value "placedLog" of event-block is not set:
            loop blocks above event-block:
                set {_l} to 0
                if loop-block is any leaves:
                    loop all blocks in radius 2 of loop-block:
                        if loop-block-2 is any leaves:
                            add 1 to {_l}
                    if {_l} > 7:
                        set {_tree} to true
            if {_tree} is true:
                chain(event-block, 0)

function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log:
                if metadata value "placedLog" of loop-block is not set:
                    loop blocks above loop-block:
                        if loop-block-2 is air:
                            block above loop-block-2 is air
                            exit 1 loop
                        exit 1 loop
                    loop blocks above loop-block:
                        if loop-block-2 is any leaves:
                            chain(loop-block-1, {_n})
                            break loop-block-1
                            wait 10 tick
"The durability decreases by the amount of blocks you break in the script below. If you set it to {durability_less} * 2, it will decrease by double.


Code:
function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        set {durabilityless} to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log:
                if metadata value "placedLog" of loop-block is not set:
                    loop blocks above loop-block:
                        if loop-block-2 is air:
                            block above loop-block-2 is air
                            exit 1 loop
                        exit 1 loop
                    loop blocks above loop-block:
                        if loop-block-2 is any leaves:
                            chain(loop-block-1, {_n})
                            break loop-block-1
                            wait 10 ticks

on place of any log:
    set metadata value "placedLog" of event-block to true

on break of any log:
    if player's gamemode is survival:
        if player's tool is an axe:   
            if metadata value "placedLog" of event-block is not set:
                loop blocks above event-block:
                    set {_l} to 0
                    if loop-block is any leaves:
                        loop all blocks in radius 2 of loop-block:
                            if loop-block-2 is any leaves:
                                add 1 to {_l}
                        if {_l} > 7:
                            set {_tree} to true
                if {_tree} is true:
                    chain(event-block, 0)
    
                    # Handle durability
                    set {_durability::%player%} to durability of player's tool
                    if {_durability::%player%} >= 1:
                        set durability of player's tool to {_durability::%player%} - {durabilityless}
                    else:
                        delete player's tool
                        play sound "entity.item.break" with volume 1 to player
 
"The durability decreases by the amount of blocks you break in the script below. If you set it to {durability_less} * 2, it will decrease by double.


Code:
function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        set {durabilityless} to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log:
                if metadata value "placedLog" of loop-block is not set:
                    loop blocks above loop-block:
                        if loop-block-2 is air:
                            block above loop-block-2 is air
                            exit 1 loop
                        exit 1 loop
                    loop blocks above loop-block:
                        if loop-block-2 is any leaves:
                            chain(loop-block-1, {_n})
                            break loop-block-1
                            wait 10 ticks

on place of any log:
    set metadata value "placedLog" of event-block to true

on break of any log:
    if player's gamemode is survival:
        if player's tool is an axe:  
            if metadata value "placedLog" of event-block is not set:
                loop blocks above event-block:
                    set {_l} to 0
                    if loop-block is any leaves:
                        loop all blocks in radius 2 of loop-block:
                            if loop-block-2 is any leaves:
                                add 1 to {_l}
                        if {_l} > 7:
                            set {_tree} to true
                if {_tree} is true:
                    chain(event-block, 0)
   
                    # Handle durability
                    set {_durability::%player%} to durability of player's tool
                    if {_durability::%player%} >= 1:
                        set durability of player's tool to {_durability::%player%} - {durabilityless}
                    else:
                        delete player's tool
                        play sound "entity.item.break" with volume 1 to player

Here is the last version of my script coming with auto plant and permission "break.log" and fixed somethings.


Code:
function chain(b: block, n: integer):
    wait 1 tick
    if {_n} is less than 50:
        add 1 to {_n}
        set {durabilityless} to {_n}
        loop blocks in radius 3 around {_b}:
            if loop-block is any log or crimson_stem or warped_stem:
                if metadata value "placedLog" of loop-block is not set:
                    loop blocks above loop-block:
                        if loop-block-2 is air:
                            block above loop-block-2 is air
                            exit 1 loop
                        exit 1 loop
                    loop blocks above loop-block:
                        if loop-block-2 is any leaves or nether_wart_block or warped_wart_block:
                            chain(loop-block-1, {_n})
                            break loop-block-1
                            wait 10 ticks

on place of any log or crimson_stem or warped_stem:
    set metadata value "placedLog" of event-block to true

on break of any log or crimson_stem or warped_stem:
    if player has permission "break.log":  # Check for permission
        if player's gamemode is survival:
            if player's tool is an axe:
                if player is sneaking:  # Check if the player is holding shift
                    stop  # Stop the script if the player is sneaking
                if metadata value "placedLog" of event-block is not set:
                    loop blocks above event-block:
                        set {_l} to 0
                        if loop-block is any leaves or nether_wart_block or warped_wart_block:
                            loop all blocks in radius 2 of loop-block:
                                if loop-block-2 is any leaves or nether_wart_block or warped_wart_block:
                                    add 1 to {_l}
                            if {_l} > 7:
                                set {_tree} to true
                    if {_tree} is true:
                        chain(event-block, 0)
                        plantSapling(event-block)
    
                        # Handle durability
                        set {_durability::%player%} to durability of player's tool
                        if {_durability::%player%} >= 1:
                            if level of unbreaking of player's tool is equal to 1:
                                set durability of player's tool to {_durability::%player%} - {durabilityless} * 4
                            if level of unbreaking of player's tool is equal to 2:
                                set durability of player's tool to {_durability::%player%} - {durabilityless} * 2
                            if level of unbreaking of player's tool is equal to 3:
                                set durability of player's tool to {_durability::%player%} - {durabilityless} * 1
                            else:
                                set durability of player's tool to {_durability::%player%} - {durabilityless} * 8
                        else:
                            delete player's tool
                            play sound "entity.item.break" with volume 1 to player

function plantSapling(b: block):
    # Ağacın en alt log bloğunu bulmak için döngü
    loop blocks below {_b}:
        if loop-block is not any log or crimson_stem or warped_stem:
            if loop-block is dirt or grass_block or podzol or coarse_dirt or mycelium or soul_soil or warped_nylium or crimson_nylium:
                set {_lowestLog} to block above loop-block
                exit loop
            else:
                exit loop
    if {_lowestLog} is oak log:
        set block at {_lowestLog} to oak sapling
    else if {_lowestLog} is spruce log:
        set block at {_lowestLog} to spruce sapling
    else if {_lowestLog} is birch log:
        set block at {_lowestLog} to birch sapling
    else if {_lowestLog} is jungle log:
        set block at {_lowestLog} to jungle sapling
    else if {_lowestLog} is acacia log:
        set block at {_lowestLog} to acacia sapling
    else if {_lowestLog} is dark oak log:
        set block at {_lowestLog} to dark oak sapling
    else if {_lowestLog} is cherry log:
        set block at {_lowestLog} to cherry sapling
    else if {_lowestLog} is crimson stem:
        set block at {_lowestLog} to crimson fungus
    else if {_lowestLog} is warped stem:
        set block at {_lowestLog} to warped fungus
 
Last edited: