@echo off
REM ============================================================
REM  Minecraft modpack + Java one-click extractor (for a new PC)
REM  How it works: Windows 10/11 ships tar.exe with built-in
REM  zstd support, so no extra software is required.
REM ============================================================
setlocal
cd /d "%~dp0"

set "TAR=%SystemRoot%\System32\tar.exe"

if not exist "%TAR%" (
    echo [ERROR] System tar.exe not found: %TAR%
    echo Your Windows version is too old. Use 7-Zip or PeaZip to extract the .tar.zst files instead.
    pause
    exit /b 1
)

echo ============================================
echo  Extracting ^(system tar + zstd, very fast^)
echo ============================================
echo.

echo [1/2] Extracting Java runtime -^> java\
if exist "java.tar.zst" (
    if not exist "java" mkdir "java"
    "%TAR%" -xf "java.tar.zst" -C "java"
    if errorlevel 1 ( echo    [FAILED] && goto :err )
    echo    Done: java\java-runtime-delta\bin\java.exe
) else (
    echo    [SKIPPED] java.tar.zst not found in this folder
)
echo.

echo [2/2] Extracting Minecraft modpack -^> minecraft\
if exist "minecraft.tar.zst" (
    "%TAR%" -xf "minecraft.tar.zst" -C "."
    if errorlevel 1 ( echo    [FAILED] && goto :err )
    echo    Done: minecraft\
) else (
    echo    [SKIPPED] minecraft.tar.zst not found in this folder
)
echo.

echo ============================================
echo  All done!
echo ============================================
echo.
echo  Next steps ^(in the PCL2 launcher^):
echo   1. Set the "minecraft" folder in this directory as the game directory,
echo      or import versions\1.21.1-NeoForge_21.1.230 into PCL.
echo   2. PCL - Settings - Launch Options - Java, then manually select:
echo      %~dp0java\java-runtime-delta\bin\javaw.exe
echo   3. Launch the game - Multiplayer - connect to play together.
echo.
pause
exit /b 0

:err
echo.
echo Extraction failed. Verify the files are complete, or extract manually with 7-Zip.
pause
exit /b 1
