Skip to content

Instantly share code, notes, and snippets.

@TheyCallMeLinux
Created July 13, 2024 03:32
Show Gist options
  • Select an option

  • Save TheyCallMeLinux/4f73b38a59c8f0122e7faf1d72f6be80 to your computer and use it in GitHub Desktop.

Select an option

Save TheyCallMeLinux/4f73b38a59c8f0122e7faf1d72f6be80 to your computer and use it in GitHub Desktop.

Revisions

  1. TheyCallMeLinux created this gist Jul 13, 2024.
    37 changes: 37 additions & 0 deletions docker-mcserver-timeset.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/bin/bash

    if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <normal|extended>"
    exit 1
    fi

    MODE=$1

    case $MODE in
    normal)
    echo "Setting time to normal mode..."
    docker exec mcserver rcon-cli gamerule doDaylightCycle true
    ;;
    extended)
    echo "Setting time to extended mode..."
    docker exec mcserver rcon-cli gamerule doDaylightCycle false

    # Time steps for a slower cycle, low the sun moves in small increments, high less server impact but the sun is teleporting, lol
    DAY_LENGTH=$((24000 * 10))
    STEP=50
    INTERVAL=10 # Adjust this to make the cycle slower or faster

    CURRENT_TIME=$(docker exec mcserver rcon-cli time query daytime | grep -o '[0-9]*')

    while true; do
    docker exec mcserver rcon-cli time add $STEP
    sleep $INTERVAL
    done
    ;;
    *)
    echo "Invalid mode. Use 'normal' or 'extended'."
    exit 1
    ;;
    esac

    echo "Time setting complete."