#!/bin/bash

# shellcheck source=start-utils
. "$(dirname "$0")/start-utils"
isDebugging && set -x
set -o pipefail

resultsFile=/data/.install-vanilla.env

args=(
  --output-directory=/data
  --results-file="${resultsFile}"
  --version="${VERSION}"
)

if isTrue "${FORCE_REDOWNLOAD}"; then
  log "Forcing re-install of Minecraft"
  args+=(--force-reinstall)
fi

if ! mc-image-helper install-vanilla "${args[@]}"; then
  logError "Failed to install vanilla Minecraft version $VERSION"
  exit 1
fi

applyResultsFile "${resultsFile}"

log "Successfully setup vanilla Minecraft version $VERSION"

isDebugging && ls -l
export FAMILY=VANILLA
exec "$(dirname "$0")/start-setupWorld" "$@"
