Double Jet

create skript dungeon generator, Write a highly optimized, complex, and scalable random dungeon generator Skript for Minecraft version [INSERT YOUR VERSION, e.g., 1.21.11]. The system must use a grid-based or cell-based generation algorithm (like a simplified random walk or cellular automata) to generate a layout of connected rooms and hallways using pre-existing structures, schematics, or structural palettes. Please include the following features in the Skript: 1. CONFIGURATION SECTION: - Adjustable grid size (e.g., 5x5 or 10x10 grid of potential room slots). - Maximum and minimum number of rooms per dungeon. - Room spacing/offset (X and Z distances between room centers). - Palette definitions for blocks (floors, walls, ceilings) OR hooks to paste templates via WorldEdit/Skript-Mirror if preferred. 2. GENERATION ALGORITHM: - Use a function generateDungeon(center: location) to initiate the process. - Track generated rooms using a 2D grid index stored in metadata or localized list variables (e.g., {-dungeon::%_id%::grid::%_x%::%_z%}). - Ensure a logical path always connects the starting room to a designated "Boss Room" or exit, with branching side-rooms for loot. - Automatically place connecting hallways/corridors between adjacent valid rooms. 3. ROOM VARIETY & POPULATION: - Support at least 3 room types: "Spawn", "Standard Loot", and "Boss Room". - Dynamically spawn themed monsters (using standard NBT or mythicmobs commands if noted) inside rooms upon generation. - Populate "Standard Loot" rooms with chests containing randomized loot tables managed within the Skript. 4. PERFORMANCE OPTIMIZATION: - Avoid server crashes or massive tps drops by spreading block placement over ticks using a queue or wait 1 tick interval after a set number of block operations. - Clean up variables and delete temporary local/global lists after the dungeon finishes generating. 5. ADMINISTRATION COMMANDS: - /dungeon generate -> Generates a new dungeon at the player's current location. - /dungeon clear -> Safely removes or reverts the blocks of the last generated dungeon (optional but helpful). Provide clean, heavily commented code following modern Skript best practices, avoiding obsolete expressions. ```

Kodari AI
KodariSep 3 at 6:56 am 1
DungeonForge
Advanced random dungeon generator Skript for Minecraft 1.21.11 using grid-based cellular automata. Generates connected rooms and hallways with configurable grid sizes, room counts, and spacing. Features three room types (Spawn, Standard Loot, Boss) with themed monster spawning and randomized loot chests. Includes performance optimization through tick-based block placement queues and variable cleanup. Admin commands for dungeon generation and clearing. Supports WorldEdit/Skript-Mirror template pasting or block palettes for structural variety.

Place dungeon.sk in plugins/Skript/scripts/, then run /sk reload dungeon. Grant administrators the dungeon.admin permission.

Kodari can make mistakes. Review important code before using.
Files
dungeon.sk
Code
1 425
dungeon.sk
# Dungeon Generator
# Minecraft: 1.21.x
# Skript: 2.8+
#
# Installation:
# 1. Save this file as plugins/Skript/scripts/dungeon.sk
# 2. Run: /sk reload dungeon
#
# This script uses only standard Skript syntax.
# It creates rooms and corridors from configurable block palettes,
# places blocks through a throttled queue, populates loot rooms, and
# snapshots overwritten blocks so the latest dungeon can be restored.

options:
    prefix: &8[&5Dungeon&8]&r

    # Generation settings
    grid-size: 9
    min-rooms: 6
    max-rooms: 14
    room-spacing: 12
    room-radius: 3
    room-height: 4
    corridor-width: 3
    corridor-height: 3

    # Maximum number of blocks placed before yielding for one server tick
    blocks-per-tick: 80

    # Dungeon block palette
    floor-block: polished deepslate
    wall-block: deepslate bricks
    ceiling-block: polished deepslate
    corridor-floor-block: stone bricks
    corridor-ceiling-block: deepslate tiles
    light-block: glowstone

on script load:
    delete {dungeon::generating::*}

# Adds one block operation to the dungeon queue.
# The original block is saved once so /dungeon clear can restore it.
function queueDungeonBlock(dungeon-id: text, block-location: location, block-type: itemtype):
    set {_location-key} to "%{_block-location}%"

    if {dungeon::%{_dungeon-id}%::snapshot::%{_location-key}%} is not set:
        set {dungeon::%{_dungeon-id}%::snapshot::%{_location-key}%} to type of block at {_block-location}
        add {_block-location} to {dungeon::%{_dungeon-id}%::snapshot-locations::*}

    if {dungeon::%{_dungeon-id}%::queue-size} is not set:
        set {dungeon::%{_dungeon-id}%::queue-size} to 0

    add 1 to {dungeon::%{_dungeon-id}%::queue-size}
    set {_queue-index} to {dungeon::%{_dungeon-id}%::queue-size}

    set {dungeon::%{_dungeon-id}%::queue-location::%{_queue-index}%} to {_block-location}
    set {dungeon::%{_dungeon-id}%::queue-type::%{_queue-index}%} to {_block-type}

# Executes queued block operations in batches to avoid a large single-tick lag spike.
function flushDungeonQueue(dungeon-id: text):
    set {_queue-total} to {dungeon::%{_dungeon-id}%::queue-size}
    if {_queue-total} is not set:
        stop

    set {_queue-index} to 1
    while {_queue-index} <= {_queue-total}:
        set block at {dungeon::%{_dungeon-id}%::queue-location::%{_queue-index}%} to {dungeon::%{_dungeon-id}%::queue-type::%{_queue-index}%}

        if {_queue-index} mod {@blocks-per-tick} is 0:
            wait 1 tick

        add 1 to {_queue-index}

    delete {dungeon::%{_dungeon-id}%::queue-location::*}
    delete {dungeon::%{_dungeon-id}%::queue-type::*}
    delete {dungeon::%{_dungeon-id}%::queue-size}

# Builds a square room shell with an open interior.
function buildDungeonRoom(dungeon-id: text, room-center: location, room-type: text):
    set {_world} to world of {_room-center}
    set {_center-x} to rounded down (x-coordinate of {_room-center})
    set {_center-y} to rounded down (y-coordinate of {_room-center})
    set {_center-z} to rounded down (z-coordinate of {_room-center})

    set {_radius} to {@room-radius}
    set {_height} to {@room-height}
    set {_negative-radius} to 0 - {_radius}

    set {_relative-x} to {_negative-radius}
    while {_relative-x} <= {_radius}:
        set {_relative-z} to {_negative-radius}

        while {_relative-z} <= {_radius}:
            set {_block-x} to {_center-x} + {_relative-x}
            set {_block-z} to {_center-z} + {_relative-z}

            set {_floor-location} to location at {_block-x}, {_center-y}, {_block-z} in {_world}
            set {_ceiling-location} to location at {_block-x}, {_center-y} + {_height} + 1, {_block-z} in {_world}

            queueDungeonBlock({_dungeon-id}, {_floor-location}, {@floor-block})
            queueDungeonBlock({_dungeon-id}, {_ceiling-location}, {@ceiling-block})

            set {_is-edge} to false
            if {_relative-x} is {_negative-radius}:
                set {_is-edge} to true
            if {_relative-x} is {_radius}:
                set {_is-edge} to true
            if {_relative-z} is {_negative-radius}:
                set {_is-edge} to true
            if {_relative-z} is {_radius}:
                set {_is-edge} to true

            set {_relative-y} to 1
            while {_relative-y} <= {_height}:
                set {_wall-location} to location at {_block-x}, {_center-y} + {_relative-y}, {_block-z} in {_world}

                if {_is-edge} is true:
                    queueDungeonBlock({_dungeon-id}, {_wall-location}, {@wall-block})
                else:
                    queueDungeonBlock({_dungeon-id}, {_wall-location}, air)

                add 1 to {_relative-y}

            add 1 to {_relative-z}

        add 1 to {_relative-x}

    # Add a simple light near the rear of the room.
    set {_light-location} to location at {_center-x}, {_center-y} + {@room-height}, {_center-z} in {_world}
    queueDungeonBlock({_dungeon-id}, {_light-location}, {@light-block})

    flushDungeonQueue({_dungeon-id})

    set {_population-location} to location at {_center-x}, {_center-y} + 1, {_center-z} in {_world}

    if {_room-type} is "standard":
        set {_chest-location} to location at {_center-x}, {_center-y} + 1, {_center-z} in {_world}
        set block at {_chest-location} to chest

        # Each standard room receives six independently randomized loot slots.
        set {_loot-count} to 0
        while {_loot-count} < 6:
            set {_slot} to random integer between 0 and 26
            set {_loot-roll} to random integer between 1 and 8

            if {_loot-roll} is 1:
                set slot {_slot} of inventory of block at {_chest-location} to 2 bread
            else if {_loot-roll} is 2:
                set slot {_slot} of inventory of block at {_chest-location} to 4 torch
            else if {_loot-roll} is 3:
                set slot {_slot} of inventory of block at {_chest-location} to iron ingot
            else if {_loot-roll} is 4:
                set slot {_slot} of inventory of block at {_chest-location} to gold ingot
            else if {_loot-roll} is 5:
                set slot {_slot} of inventory of block at {_chest-location} to arrow
            else if {_loot-roll} is 6:
                set slot {_slot} of inventory of block at {_chest-location} to cooked beef
            else if {_loot-roll} is 7:
                set slot {_slot} of inventory of block at {_chest-location} to emerald
            else:
                set slot {_slot} of inventory of block at {_chest-location} to golden apple

            add 1 to {_loot-count}

        spawn 2 zombies at {_population-location}
        spawn a spider at {_population-location}

    else if {_room-type} is "boss":
        spawn a ravager at {_population-location}
        spawn 2 wither skeletons at {_population-location}

# Builds a corridor between two directly adjacent room centers.
function buildDungeonCorridor(dungeon-id: text, first-center: location, second-center: location):
    set {_world} to world of {_first-center}
    set {_first-x} to rounded down (x-coordinate of {_first-center})
    set {_first-y} to rounded down (y-coordinate of {_first-center})
    set {_first-z} to rounded down (z-coordinate of {_first-center})
    set {_second-x} to rounded down (x-coordinate of {_second-center})
    set {_second-z} to rounded down (z-coordinate of {_second-center})

    set {_half-width} to rounded down ({@corridor-width} / 2)
    set {_negative-half-width} to 0 - {_half-width}

    # Horizontal corridor.
    if {_first-z} is {_second-z}:
        set {_start-x} to {_first-x}
        set {_end-x} to {_second-x}

        if {_start-x} > {_end-x}:
            set {_temporary-x} to {_start-x}
            set {_start-x} to {_end-x}
            set {_end-x} to {_temporary-x}

        set {_corridor-x} to {_start-x} + {@room-radius}
        while {_corridor-x} <= {_end-x} - {@room-radius}:
            set {_corridor-z-offset} to {_negative-half-width}

            while {_corridor-z-offset} <= {_half-width}:
                set {_corridor-z} to {_first-z} + {_corridor-z-offset}
                set {_floor-location} to location at {_corridor-x}, {_first-y}, {_corridor-z} in {_world}