Paste #55152: Untitled Paste

Date: 2019/07/02 23:51:47 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


FastLeafDecay_Events:
    type: world
    debug: false
    events:
        on player breaks Oak_Log:
        - define Leaf "Oak_Leaves"
        - inject FastLeafDecay_Task

        on player breaks Spruce_Log:
        - define Leaf "Spruce_Leaves"
        - inject FastLeafDecay_Task

        on player breaks Birch_Log:
        - define Leaf "Birch_Leaves"
        - inject FastLeafDecay_Task

        on player breaks Jungle_Log:
        - define Leaf "Jungle_Leaves"
        - inject FastLeafDecay_Task

        on player breaks Acacia_Log:
        - define Leaf "Acacia_Leaves"
        - inject FastLeafDecay_Task

        on player breaks Dark_Oak_Log:
        - define Leaf "Dark_Oak_Leaves"
        - inject FastLeafDecay_Task

FastLeafDecay_Task:
    type: task
    debug: false
    speed: 0
    script:
    # Check if block has another log ontop of it.
    - if <context.location.add[0,1,0].material> == <context.material>:
        # Top of the tree hasn't been reached yet.
        - queue clear

        # Grab all the leaves in a radius of the log broken.
        - define Leaves <context.location.find.blocks[<def[Leaf]>].within[<server.flag[FastLeafDecayRange]||7>]>

        # Clearing queue if there are no leaves.
        - if <def[Leaves].size> == 0:
            - queue clear

        # Destroying leaves naturally.
        - foreach <def[Leaves].random[<def[leaves].size>]>:
            # Check for additional logs within a 5-block radius, excluding the broken log from the results.
            - if <def[value].find.blocks[<context.material.name>].within[3].exclude[<context.location>].size> == 0:
                # Destroy the block
                - modifyblock <def[value]> air naturally
                # Play a sound.
                - playsound <def[value]> sound:block_grass_break volume:0.05 pitch:1.2 sound_category:blocks

                # Play a particle effect.
                - playeffect effect:happy_villager at:<def[value].add[0.5,0.5,0.5]> offset:0.2 quantity:10 visibility:15
                - wait 2t
                - playeffect effect:happy_villager at:<def[value].add[0.5,0.5,0.5]> offset:0.2 quantity:10 visibility:15

FastLeafDecay_Init:
    type: task
    debug: false
    speed: 0
    script:
    - flag server FastLeafDecayRange:12