Paste #125332: Replace Blocks

Date: 2024/08/06 11:43:26 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# 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
        - define Toaster_Dev true
        - 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

        # Debugging Information
        - if <[Toaster_Dev]> = true:
            - narrate "Updating Chunk: <[ProcessChunk]> Loaded: <chunk[<[ProcessChunk]>].is_loaded>"
            - narrate "BoundingBox is: X:<[MinX]> - <[MaxX]> Z:<[MinZ]> - <[MaxZ]>"

        # Load the chunk if not loaded
        - if <chunk[<[ProcessChunk]>].is_loaded> = false:
            - chunkload <[ProcessChunk]>

        # Replace Blocks
        - definemap block_replacements black_concrete:deepslate
        - definemap saplings cherry_sapling:cherry mangrove_propagule:mangrove
        - define blocks <[ProcessChunk].cuboid.blocks>
        - foreach <[blocks]> as:block:
            - define replace_y <[block].y>
            - if <[block].material.name> = command_block:
                - define command <[block].command_block>
                - define parts <[command].split[ ]>
                - define block_type <[parts].get[2]>

                # Handle saplings and generate trees
                - if <[block_type]> in <[saplings].keys>:
                    - modifyblock <[block]> air
                    - adjust <[block]> generate_tree:<[saplings.<[block_type]>]>
                - else:
                    - define counter:3
                    - define counter_2:4
                    - while <[counter]> >= 3:
                        - modifyblock <[block]> <[block_type]>
                        - if <[parts].get[<[counter]>].exists>:
                            - if <[parts].get[<[counter_2]>].exists>:
                                - narrate <[parts].get[<[counter]>]>:<[parts].get[<[counter_2]>]>
                                - if <[parts].get[<[counter]>]> = "direction":
                                    - adjustblock <[block]> direction:<[parts].get[<[counter_2]>]>
                                - if <[parts].get[<[counter]>]> = "waterlogged":
                                    - adjustblock <[block]> waterlogged:<[parts].get[<[counter_2]>]>
                                - if <[parts].get[<[counter]>]> = "age":
                                    - adjustblock <[block]> age:<[parts].get[<[counter_2]>]>
                        - else:
                            - define counter:0
                        - define counter:+:1
                        - define counter_2:+:1

            # Replace blocks based on the replacement dictionary
            - if <[block].material.name> in <[block_replacements].keys>:
                - modifyblock <[block]> <[block_replacements.<[block].material.name>]>