Slow mine generation help

  • 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 comminuty!

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

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

ItsDarkElf

Member
Mar 27, 2022
3
0
1
Finland
I am trying to make a custom mine generation system for a large scale mine.

The problem I'm having is that this works but really and I mean really slow and laggy. So it would be nice if someone could help me speed it up so it's faster and more light weight.

Code:
function andesiteGen(block: block, chunk: chunk, chunkPlace: boolean):
    wait 5 ticks
    loop all blocks in radius random integer between 3 and 5 of {_block}:
        if y-coordinate of loop-block > 318:
            stop
        else if y-coordinate of loop-block < -63:
            stop
        if {_chunkPlace} is true:
            if loop-block is within {_chunk}:
                set loop-block to andesite
        else if loop-block is within {mine.pos1} and {mine.pos2}:
            set loop-block to andesite

function tuffGen(block: block, chunk: chunk, chunkPlace: boolean):
    wait 5 ticks
    loop all blocks in radius random integer between 3 and 5 of {_block}:
        if y-coordinate of loop-block > 318:
            stop
        else if y-coordinate of loop-block < -63:
            stop
        if {_chunkPlace} is true:
            if loop-block is within {_chunk}:
                set loop-block to tuff
        if loop-block is within {mine.pos1} and {mine.pos2}:
            set loop-block to tuff

function blackstoneGen(block: block, chunk: chunk, chunkPlace: boolean):
    wait 5 ticks
    loop all blocks in radius random integer between 3 and 5 of {_block}:
        if y-coordinate of loop-block > 318:
            stop
        else if y-coordinate of loop-block < -63:
            stop
        if {_chunkPlace} is true:
            if loop-block is within {_chunk}:
                set loop-block to blackstone
        if loop-block is within {mine.pos1} and {mine.pos2}:
            set loop-block to blackstone

function silverGen(block: block, chunk: chunk, chunkPlace: boolean):
    wait 5 ticks
    loop all blocks in radius 1 of {_block}:
        if y-coordinate of loop-block > 318:
            stop
        else if y-coordinate of loop-block < -63:
            stop
        if {_chunkPlace} is true:
            if loop-block is within {_chunk}:
                blockSet(location of loop-block, note block, 0, "banjo", false)
                wait 1 tick
        if loop-block is within {mine.pos1} and {mine.pos2}:
            blockSet(location of loop-block, note block, 0, "banjo", false)
            wait 1 tick
    loop all blocks in radius 1 of location(({_block}'s x-coordinate + random integer between 1 and -1), ({_block}'s y-coordinate + random integer between 1 and -1), ({_block}'s z-coordinate + random integer between 1 and -1)):
        if y-coordinate of loop-block > 318:
            stop
        else if y-coordinate of loop-block < -63:
            stop
        if {_chunkPlace} is true:
            if loop-block is within {_chunk}:
                blockSet(location of loop-block, note block, 0, "banjo", false)
                wait 1 tick
        if loop-block is within {mine.pos1} and {mine.pos2}:
            blockSet(location of loop-block, note block, 0, "banjo", false)
            wait 1 tick

command /minereset <text> <integer>:
    permission: op
    trigger:
        if arg-1 is not set:
            send "this is no longer supported" to player
        else if arg-1 is set:
            set server tick rate to 40
            set {mineGeneration} to true
            set {_curTime2} to now
            set {_chunksGen} to 0
            if arg-1 is "player":
                set {_loc} to location of player
            else if arg-1 is "mine_loc":
                set {_loc} to location of {mine.pos3}
            set {_percemtageMaxValue} to 0
            loop arg-2 times:
                loop arg-2 times:
                    set {_curTime} to now
                    set {_time} to 0
                    loop all blocks within chunk at location((x-coordinate of {_loc} + (16 * loop-value-1)), y-coordinate of {_loc}, (z-coordinate of {_loc} + (16 * loop-value-2)), (world of {_loc})):
                        add 1 to {_time}
                        if y-coordinate of loop-block > 20:
                            set loop-block to stone
                            chance of 2%:
                                set loop-block to cobblestone
                        else if y-coordinate of loop-block > 17:
                            set loop-block to stone
                            chance of 60%:
                                set loop-block to deepslate
                        else if y-coordinate of loop-block < -30:
                            set loop-block to netherrack
                            chance of 0.1%:
                                set loop-block to lava
                        else if y-coordinate of loop-block < -27:
                            set loop-block to netherrack
                            chance of 40%:
                                set loop-block to deepslate
                        else:
                            set loop-block to deepslate
                            chance of 10%:
                                set loop-block to cobbled deepslate
                        #ore/vein generation
                        if y-coordinate of loop-block > 318:
                            set loop-block to bedrock
                        else if y-coordinate of loop-block < -63:
                            set loop-block to bedrock
                        else if y-coordinate of loop-block > 20:
                            chance of 0.035%:
                                silverGen(loop-block, chunk at location((x-coordinate of {_loc} + (16 * loop-value-1)), y-coordinate of {_loc}, (z-coordinate of {_loc} + (16 * loop-value-2)), (world of {_loc})), true)
                            chance of 0.0025%:
                                andesiteGen(loop-block, chunk at location((x-coordinate of {_loc} + (16 * loop-value-1)), y-coordinate of {_loc}, (z-coordinate of {_loc} + (16 * loop-value-2)), (world of {_loc})), true)
                            chance of 0.0005%:
                                blockSet(location of loop-block, note block, 1, "banjo", false)
                            chance of 0.005%:
                                set loop-block to gold ore
                        else if y-coordinate of loop-block < -30:
                            chance of 0.0025%:
                                blackstoneGen(loop-block, chunk at location((x-coordinate of {_loc} + (16 * loop-value-1)), y-coordinate of {_loc}, (z-coordinate of {_loc} + (16 * loop-value-2)), (world of {_loc})), true)
                        else:
                            chance of 0.0025%:
                                tuffGen(loop-block, chunk at location((x-coordinate of {_loc} + (16 * loop-value-1)), y-coordinate of {_loc}, (z-coordinate of {_loc} + (16 * loop-value-2)), (world of {_loc})), true)
                            chance of 0.001%:
                                set loop-block to deepslate diamond ore
                        if {_time} is 15000:
                            wait 1 ticks
                            set {_time} to 0
                    wait 1 second
                    add 1 to {_chunksGen}
                    set {_tempTimeValue} to difference between now and {_curTime}
                    set {_timeSpan} to (((arg-2 * arg-2) - {_chunksGen}) * ({_tempTimeValue}))
                    send "&7The chunk (%loop-value-1%, %loop-value-2%)has generated, estimated time to finish %{_timeSpan}%,%newline%&8tps: %tps%" to console
                send "&7The line number %loop-value-1% has generated" to console
            broadcast "&7The full mine area has generated in %difference between now and {_curTime2}%"
            set {mineGeneration} to false
            set server tick rate to 20

Thank you!