Paste #125926: Unnamed Denizen Script Paste

Date: 2024/08/24 15:02:36 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# switch BLOCK state:on to Toggle CommandBlocks
# modifyblock BLOCK MATERIAL to Change Blocks
# execute as_server COMMAND
# Command Modify Limit -> 65792
# Run update_chunk def.ChunkX:31 def.ChunkZ:3 def.ChunkWorld:world_sky
update_chunk:
    debug: false
    type: task
    script:
        # Run update_chunk def.ChunkX:31 def.ChunkZ:3 def.ChunkWorld:world_sky
        - if <[ChunkX].exists> = false:
            - define ChunkX:0
        - if <[ChunkZ].exists> = false:
            - define ChunkZ:0
        - if <[ChunkWorld].exists> = false:
            - define ChunkWorld:world_sky

        - define ProcessChunk <chunk[<[ChunkX]>,<[ChunkZ]>,<[ChunkWorld]>]>

        - define MinX <[ChunkX]>
        - define MinX:*:16
        - define MinZ <[ChunkZ]>
        - define MinZ:*:16
        - define MaxX <[MinX]>
        - define MaxX:+:15
        - define MaxZ <[MinZ]>
        - define MaxZ:+:15

        - if <chunk[<[ProcessChunk]>].is_loaded> = false:
            - define time_start <util.current_time_millis>
            - chunkload <[ProcessChunk]> duration:10s
            - define elapsed <util.current_time_millis>
            - define elapsed:-:<[time_start]>
            - narrate "Loaded Chunk in <[elapsed]>ms"
        - narrate "Updating Chunk: <[ProcessChunk]> Loaded: <chunk[<[ProcessChunk]>].is_loaded>"
        - if !<[ProcessChunk].has_flag[worked]>:
            - narrate "Updating in Progress, ..."
            # Move Main Chunk Down
            - define time_start <util.current_time_millis>
            - if !<[ProcessChunk].has_flag[moved]>:
                - flag <[ProcessChunk]> moved
                - ~schematic create name:move_chunk area:<cuboid[<[ChunkWorld]>,<[MinX]>,0,<[MinZ]>,<[MaxX]>,256,<[MaxZ]>]> <location[<[MinX]>,0,<[MinZ]>,<[ChunkWorld]>]> entities delayed 
                - ~schematic paste name:move_chunk <location[<[MinX]>,-64,<[MinZ]>,<[ChunkWorld]>]> delayed
                - ~schematic unload name:move_chunk delayed

            # Move neighbor Chunks
            - definemap Chunklist
                1:<chunk[<[ChunkX].add[1]>,<[ChunkZ]>,<[ChunkWorld]>]> 
                2:<chunk[<[ChunkX].add[1]>,<[ChunkZ].add[1]>,<[ChunkWorld]>]> 
                3:<chunk[<[ChunkX].add[1]>,<[ChunkZ].sub[1]>,<[ChunkWorld]>]> 
                4:<chunk[<[ChunkX]>,<[ChunkZ].add[1]>,<[ChunkWorld]>]> 
                5:<chunk[<[ChunkX]>,<[ChunkZ].sub[1]>,<[ChunkWorld]>]> 
                6:<chunk[<[ChunkX].sub[1]>,<[ChunkZ]>,<[ChunkWorld]>]> 
                7:<chunk[<[ChunkX].sub[1]>,<[ChunkZ].add[1]>,<[ChunkWorld]>]> 
                8:<chunk[<[ChunkX].sub[1]>,<[ChunkZ].sub[1]>,<[ChunkWorld]>]>
            - foreach <[Chunklist]> as:chunk:
                - if <chunk[<[chunk]>].is_loaded> = false:
                    - chunkload <[chunk]> duration:10s
                - if !<[chunk].has_flag[moved]>:
                    - flag <[chunk]> moved
                    - ~schematic create name:move_chunk area:<[chunk].cuboid> <location[<[MinX]>,0,<[MinZ]>,<[ChunkWorld]>]> entities delayed
                    - ~schematic paste name:move_chunk <location[<[MinX]>,-64,<[MinZ]>,<[ChunkWorld]>]> delayed
                    - ~schematic unload name:move_chunk delayed
            - define elapsed <util.current_time_millis>
            - define elapsed:-:<[time_start]>
            - narrate "Loaded and Moved all Chunks in <[elapsed]>ms"

            # Replace Blocks
            - definemap block_replacements
                black_concrete:deepslate
                gray_concrete:tuff
                white_concrete:calcite
                magenta_stained_glass:amethyst_block
                pink_stained_glass:budding_amethyst
                orange_concrete:copper_ore
                blue_terracotta:sculk
                pink_terracotta:sculk_catalyst
                purple_terracotta:dripstone_block
                green_terracotta:moss_block
                light_blue_terracotta:water
                magenta_terracotta:water
                coarse_dirt:mud
                green_carpet:moss_carpet
            - definemap block_overlays
                green_terracotta:dirt
                light_blue_terracotta:clay
                magenta_terracotta:calcite
                blue_terracotta:deepslate
                pink_terracotta:sculk
            - definemap block_underlays
                green_terracotta:true
                light_blue_terracotta:false
                magenta_terracotta:false
                blue_terracotta:true
                pink_terracotta:false
            - definemap block_surround
                magenta_terracotta:true
                light_blue_terracotta:true
            - definemap ore_replace
                coal_ore:deepslate_coal_ore
                copper_ore:deepslate_copper_ore
                lapis_ore:deepslate_lapis_ore
                iron_ore:deepslate_iron_ore
                gold_ore:deepslate_gold_ore
                redstone_ore:deepslate_redstone_ore
                diamond_ore:deepslate_diamond_ore
                emerald_ore:deepslate_emerald_ore
            - definemap saplings
                cherry_sapling:cherry
                mangrove_propagule:mangrove
            - definemap makeunfloat
                cherry_log:cherry_log
            - definemap waterplants
                water:True
                small_dripleaf:True
                big_dripleaf:True
                big_dripleaf_stem:True
            - definemap fluidreplacer
                blue_wool:water
                red_wool:lava
            - define time_start <util.current_time_millis>
            - define blocks <[ProcessChunk].cuboid.blocks>
            - foreach <[blocks]> as:block:
                - define replace_y <[block].y>
                - if <[block].y> == -64:
                    - modifyblock <[block]> bedrock delayed
                - else:
                    - define block_above <[block].relative[0,1,0]>
                    - define block_below <[block].relative[0,-1,0]>
                    - define block_north <[block].relative[0,0,-1]>
                    - define block_south <[block].relative[0,0,1]>
                    - define block_east <[block].relative[1,0,0]>
                    - define block_west <[block].relative[-1,0,0]>
                    - define change_block false
                    - if <[block].material.name> = command_block:
                        - define command <[block].command_block>
                        - define parts <[command].split[ ]>
                        - if <[parts].get[1]> = "blockreplacer":
                            - define block_type <[parts].get[2]>
                            - if <[block_type]> in <[saplings].keys>:
                                - modifyblock <[block]> air delayed
                                - execute as_server "/world <[ChunkWorld]>" silent
                                - execute as_server "/pos1 <[block].x>,<[block].y>,<[block].z>" silent
                                - execute as_server "/pos2 <[block].x>,<[block].y.sub[1]>,<[block].z>" silent
                                - execute as_server "/forest <[saplings.<[block_type]>]> 100" delayed
                            - else:
                                - if <[parts].get[3].exists>:
                                    - execute as_server "/world <[ChunkWorld]>" silent
                                    - execute as_server "/pos1 <[block].x>,<[block].y>,<[block].z>" silent
                                    - execute as_server "/pos2 <[block].x>,<[block].y>,<[block].z>" silent
                                    - execute as_server "/set <[block_type]>" delayed
                                - else:
                                    - modifyblock <[block]> <[block_type]>  delayed
                        - if <[parts].get[1]> = "schematic":
                            # Make sure the Schematic is saved in WorldEdit as Sponge.2 otherwise Denizen cannot load it.
                            - define PlaceY:<[replace_y]>
                            - define PlaceX:<[block].x>
                            - define PlaceZ:<[block].z>
                            - if <[parts].get[3].exists>:
                                - define PlaceY:+:<[parts].get[3]>
                            - if <[parts].get[4].exists>:
                                - define PlaceX:+:<[parts].get[4]>
                            - if <[parts].get[5].exists>:
                                - define PlaceZ:+:<[parts].get[5]>
                            - if <[parts].get[2]> not in <schematic.list>:
                                - ~schematic load name:<[parts].get[2]>

                            - define mask_area:<schematic[<[parts].get[2]>].cuboid[<location[<[PlaceX]>,<[PlaceY]>,<[PlaceZ]>,<[ChunkWorld]>]>]>
                            - define mask_list <[mask_area].blocks.parse[material]>

                            ## - Basic Mask - ##
                            - define mask <material[air].name>|<material[grass_block].name>|<material[cherry_leaves].name>|<material[oak_leaves].name>|<material[spruce_leaves].name>|<material[birch_leaves].name>|<material[jungle_leaves].name>|<material[acacia_leaves].name>|<material[dark_oak_leaves].name>|<material[mangrove_leaves].name>|<material[azalea_leaves].name>|<material[flowering_azalea_leaves].name>

                            - ~schematic paste name:<[parts].get[2]> mask:<[mask]> noair <location[<[PlaceX]>,<[PlaceY]>,<[PlaceZ]>,<[ChunkWorld]>]>
                    # Replace blocks based on the replacement dictionary
                    - if <[block].material.name> in <[block_overlays].keys>:
                        - if not <[block_above].material.is_solid>:
                            - define change_block true
                        - if not <[block_below].material.is_solid>:
                            - if <[block_underlays.<[block].material.name>]> = true:
                                - define change_block true
                        - if <[block].material.name> in <[block_surround].keys>:
                            - if not <[block_north].material.is_solid>:
                                - if <[block_north].material.name> not in <[waterplants].keys>:
                                    - define change_block false
                            - if not <[block_east].material.is_solid>:
                                - if <[block_east].material.name> not in <[waterplants].keys>:
                                    - define change_block false
                            - if not <[block_west].material.is_solid>:
                                - if <[block_west].material.name> not in <[waterplants].keys>:
                                    - define change_block false
                            - if not <[block_south].material.is_solid>:
                                - if <[block_south].material.name> not in <[waterplants].keys>:
                                    - define change_block false
                        - if <[change_block]> = true:
                            - if <[block].material.name> in <[block_replacements].keys>:
                                - modifyblock <[block]> <[block_replacements.<[block].material.name>]> delayed
                        - else:
                            - modifyblock <[block]> <[block_overlays.<[block].material.name>]> delayed
                    - else:
                        - if <[block].material.name> in <[block_replacements].keys>:
                            - modifyblock <[block]> <[block_replacements.<[block].material.name>]> delayed
                    - if <[block].material.name> = dirt or <[block].material.name> = coarse_dirt:
                        - define random_index <util.random.int[1].to[15]>
                        - if <[random_index]> = 1:
                            - if <[block_below].material.name> = air or <[block_below].material.name> = cave_air:
                                - modifyblock <[block_below]> hanging_roots delayed
                    - if <[block].material.name> in <[makeunfloat].keys>:
                        - if not <[block_below].material.is_solid>:
                            - modifyblock <[block_below]> <[block_above].material.name> delayed
                            - execute as_server "/world <[ChunkWorld]>" silent
                            - execute as_server "/pos1 <[block].x>,<[block].y>,<[block].z>" silent
                            - execute as_server "/pos2 <[block].x>,<[block].y.sub[1]>,<[block].z>" silent
                            - execute as_server "/set <[block_above].material.name>"
                    - if <[replace_y]> <= -1:
                        - if <[block].material.name> in <[ore_replace].keys>:
                            - modifyblock <[block]> <[ore_replace.<[block].material.name>]> delayed
                    - if <[block].material.name> in <[fluidreplacer].keys>:
                        - define change_block true
                        - if not <[block_north].material.is_solid> or <[block_north].material.name> != <[fluidreplacer.<[block].material.name>]>:
                                - define change_block false
                        - if not <[block_east].material.is_solid> or <[block_east].material.name> != <[fluidreplacer.<[block].material.name>]>:
                                - define change_block false
                        - if not <[block_west].material.is_solid> or <[block_west].material.name> != <[fluidreplacer.<[block].material.name>]>:
                                - define change_block false
                        - if not <[block_south].material.is_solid> or <[block_south].material.name> != <[fluidreplacer.<[block].material.name>]>:
                                - define change_block false
                        - if not <[block_below].material.is_solid> or <[block_below].material.name> != <[fluidreplacer.<[block].material.name>]>:
                                - define change_block false
                        - if <[change_block]> = true:
                            - modifyblock <[block]> <[fluidreplacer.<[block].material.name>]> delayed
                        - else:
                            - if <[block].y> <= 0:
                                - modifyblock <[block]> deepslate delayed
                            - else:
                                - if <[block].y> <= 64 and not <[block_above].material.is_solid>:
                                    - modifyblock <[block]> grass_block delayed
                                - else:
                                    - modifyblock <[block]> stone delayed
                - define elapsed <util.current_time_millis>
                - define elapsed:-:<[time_start]>
                - narrate "Scanned and Adjusted Blocks in <[elapsed]>ms"
            - flag <[ProcessChunk]> worked
        - else:
            - narrate "Already Updated, ..."
        - narrate "Updating Done: <[ProcessChunk]>"