From 1160a10a3afecae6b119a703f7a3b8597a16f298 Mon Sep 17 00:00:00 2001 From: Joey Eamigh <55670930+JoeyEamigh@users.noreply.github.com> Date: Tue, 20 Jun 2023 20:54:41 -0400 Subject: [PATCH] init and some qol stuff for a modpack maker --- .envrc | 3 + .gitignore | 17 ++++ .vscode/settings.json | 7 ++ README.md | 24 +++++ client/client.ps1 | 46 +++++++++ client/client.py | 3 + client/client.sh | 22 +++++ client/requirements.txt | 5 + modpack/manifest.json | 194 +++++++++++++++++++++++++++++++++++++ modpack/overrides/.gitkeep | 0 pyproject.toml | 6 ++ requirements.txt | 5 + tooling.py | 95 ++++++++++++++++++ venv.ps1 | 18 ++++ venv.sh | 15 +++ 15 files changed, 460 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 client/client.ps1 create mode 100644 client/client.py create mode 100644 client/client.sh create mode 100644 client/requirements.txt create mode 100644 modpack/manifest.json create mode 100644 modpack/overrides/.gitkeep create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 tooling.py create mode 100644 venv.ps1 create mode 100755 venv.sh diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..65fceab --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +#!/bin/bash + +source .venv/bin/activate diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..635c6e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +### PAX ### +pax +pax.exe +libssl*.dll +libcrypto*.dll +cacert.pem + +### Modpack ### +.out/ +.dist/ + +# python +.venv + +# client +client/.version +client/curseforge diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f4f20c2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none", + "python.analysis.typeCheckingMode": "basic" +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee46b72 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# FishPog Pixelmon + +This is the repo for FishPog Pixelmon, and a bit of experimental tooling to make my life easier in designing, updating, and getting non-technical people to be able to easily install the modpack, all without having to use curseforge. + +## Building the modpack + +```bash +git clone https://git.233hfd.com/joey/FishPogPixelmon.git +cd FishPogPixelmon + +source ./venv.sh # or just venv.bat on windows + +python tooling.py --setup +``` + +now, pax will be installed, which will allow you to edit the modpack. refer to the pax github for more info. + +## exporting the modpack + +```bash +python tooling.py --export +``` + +this command will package up the pack with pax, then bundle some scripts with it that allows for auto-updating and automatically downloading the mods from curseforge, rather than having to distribute a large zip file. diff --git a/client/client.ps1 b/client/client.ps1 new file mode 100644 index 0000000..462b111 --- /dev/null +++ b/client/client.ps1 @@ -0,0 +1,46 @@ +# check if winget is installed and if so, set a flag to true +$winget = Get-Command winget -ErrorAction SilentlyContinue + +if (!$winget) { + Write-Host "Error: winget is not installed." -Foreground Red + Write-Host "This script may not work withotu winget." -Foreground Red + Write-Host "Run 'Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe' in an admin powershell prompt to install winget." -Foreground Red +} + +# Check that python is installed +if (-not (Get-Command "python" -ErrorAction SilentlyContinue)) { + Write-Host "Error: python is not installed." -Foreground Red + + if ($winget) { + Write-Host "Attempting to install python." + winget install --id=Python.Python.3.11 -e + } + else { + Write-Host "Please install python to continue." -Foreground Red + exit 1 + } +} + +# Check that java is installed +if (-not (Get-Command "java" -ErrorAction SilentlyContinue)) { + Write-Host "Error: java is not installed." -Foreground Red + + if ($winget) { + Write-Host "Attempting to install java." + winget install AdoptOpenJDK.OpenJDK.11 + } + else { + Write-Host "Please install java to continue." -Foreground Red + exit 1 + } + +} + +if (Test-Path ".venv") { } else { python -m venv .venv } + +.venv\Scripts\Activate + +python -m pip install --upgrade pip +python -m pip install -r requirements.txt + +python .\client.py \ No newline at end of file diff --git a/client/client.py b/client/client.py new file mode 100644 index 0000000..8b55be2 --- /dev/null +++ b/client/client.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 + +DOWNLOADER_URL = "https://github.com/North-West-Wind/CurseForge-CLI/releases/latest/download/curseforge.zip" diff --git a/client/client.sh b/client/client.sh new file mode 100644 index 0000000..485d20d --- /dev/null +++ b/client/client.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# check that python is installed +if ! [ -x "$(command -v python)" ]; then + echo 'Error: python is not installed. Please install it to continue.' >&2 + exit 1 +fi + +# check that java is installed +if ! [ -x "$(command -v java)" ]; then + echo 'Error: java is not installed. Please install it to continue.' >&2 + exit 1 +fi + +if [ -d .venv ]; then; else python -m venv .venv; fi + +source .venv/bin/activate + +python -m pip install --upgrade pip +python -m pip install -r requirements.txt + +python ./client.py diff --git a/client/requirements.txt b/client/requirements.txt new file mode 100644 index 0000000..cf89e54 --- /dev/null +++ b/client/requirements.txt @@ -0,0 +1,5 @@ +certifi==2023.5.7 +charset-normalizer==3.1.0 +idna==3.4 +requests==2.31.0 +urllib3==2.0.3 diff --git a/modpack/manifest.json b/modpack/manifest.json new file mode 100644 index 0000000..270ee9f --- /dev/null +++ b/modpack/manifest.json @@ -0,0 +1,194 @@ +{ + "minecraft": { + "version": "1.16.5", + "modLoaders": [ + { + "id": "forge-36.2.34", + "primary": true + } + ] + }, + "manifestType": "minecraftModpack", + "overrides": "overrides", + "manifestVersion": 1, + "version": "0.1.0", + "author": "Liightninggod", + "name": "FishPog Pixelmon", + "files": [ + { + "projectID": 32274, + "fileID": 4012858, + "required": true, + "__meta": { + "name": "JourneyMap" + } + }, + { + "projectID": 223852, + "fileID": 3776277, + "required": true, + "__meta": { + "name": "Storage Drawers" + } + }, + { + "projectID": 233342, + "fileID": 3216206, + "required": true, + "__meta": { + "name": "Fairy Lights" + } + }, + { + "projectID": 235279, + "fileID": 3376782, + "required": true, + "__meta": { + "name": "Chisel", + "dependencies": [ + 267602 + ] + } + }, + { + "projectID": 237307, + "fileID": 3738137, + "required": true, + "__meta": { + "name": "Cosmetic Armor Reworked" + } + }, + { + "projectID": 238222, + "fileID": 4371666, + "required": true, + "__meta": { + "name": "Just Enough Items (JEI)" + } + }, + { + "projectID": 247560, + "fileID": 4024011, + "required": true, + "__meta": { + "name": "Oh The Biomes You'll Go" + } + }, + { + "projectID": 252848, + "fileID": 3382150, + "required": true, + "__meta": { + "name": "Nature's Compass" + } + }, + { + "projectID": 267602, + "fileID": 3137659, + "required": true, + "__meta": { + "name": "ConnectedTexturesMod" + } + }, + { + "projectID": 268495, + "fileID": 3863227, + "required": true, + "__meta": { + "name": "Simple Storage Network" + } + }, + { + "projectID": 328085, + "fileID": 3536025, + "required": true, + "__meta": { + "name": "Create", + "dependencies": [ + 486392 + ] + } + }, + { + "projectID": 361385, + "fileID": 3276350, + "required": true, + "__meta": { + "name": "Pam's HarvestCraft 2 - Crops" + } + }, + { + "projectID": 365460, + "fileID": 3281234, + "required": true, + "__meta": { + "name": "Pam's HarvestCraft 2 - Trees" + } + }, + { + "projectID": 372534, + "fileID": 3190867, + "required": true, + "__meta": { + "name": "Pam's HarvestCraft 2 - Food Core" + } + }, + { + "projectID": 389487, + "fileID": 4564388, + "required": true, + "__meta": { + "name": "Pixelmon" + } + }, + { + "projectID": 402231, + "fileID": 3418627, + "required": true, + "__meta": { + "name": "Pam's HarvestCraft 2 - Food Extended", + "dependencies": [ + 372534 + ] + } + }, + { + "projectID": 486392, + "fileID": 3535459, + "required": true, + "__meta": { + "name": "Flywheel" + } + }, + { + "projectID": 509285, + "fileID": 3503936, + "required": true, + "__meta": { + "name": "Create Deco", + "dependencies": [ + 328085 + ] + } + }, + { + "projectID": 535563, + "fileID": 3882536, + "required": true, + "__meta": { + "name": "Create gear addon", + "dependencies": [ + 328085 + ] + } + }, + { + "projectID": 818696, + "fileID": 4369234, + "required": true, + "__meta": { + "name": "PokeFactory Compatibility" + } + } + ] +} \ No newline at end of file diff --git a/modpack/overrides/.gitkeep b/modpack/overrides/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f00cd89 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.isort] +profile = "black" + +[tool.black] +line-length = 119 +target-version = ['py311'] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cf89e54 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +certifi==2023.5.7 +charset-normalizer==3.1.0 +idna==3.4 +requests==2.31.0 +urllib3==2.0.3 diff --git a/tooling.py b/tooling.py new file mode 100644 index 0000000..9e17281 --- /dev/null +++ b/tooling.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 + +import os, sys, argparse, tempfile, subprocess, shutil, requests + +parser = argparse.ArgumentParser(description="a helper script for liightninggod modpacks") + +parser.add_argument("--export", "-e", help="export modpack zip", action="store_true") +parser.add_argument("--setup", "-s", help="setup project and install dependencies", action="store_true") +parser.add_argument("--force", "-f", help="forces things when needed, like redoing setup", action="store_true") +parser.add_argument("--build-pax", help="builds pax from source, even if on a supported platform", action="store_true") +args = parser.parse_args() + +WORKING_DIR = os.getcwd() + +PAX_GITHUB = "https://github.com/froehlichA/pax" +PAX_LATEST_RELEASE = f"{PAX_GITHUB}/releases/latest/download" +PAX_LINUX = f"{PAX_LATEST_RELEASE}/pax" +PAX_WINDOWS = f"{PAX_LATEST_RELEASE}/pax-windows.zip" + + +OS = sys.platform + + +def __main__(): + if args.setup: + print("setting up pack") + setup_pack() + return + elif args.export: + print("exporting modpack") + return + + print( + "no command provided. pass the -h flag to see commands for pack, or run ./pax to interact with the modpack's files" + ) + + +def setup_pack(): + pax() + + +# pax +def pax(): + if os.path.isfile(os.path.join(WORKING_DIR, "pax")) and not args.force: + print("pax is already installed") + return + + if OS == "darwin" or args.build_pax: + print("building pax from source...") + pax_from_source() + print("pax built successfully") + return + + if OS == "linux": + print("downloading pax binary for linux...") + r = requests.get(PAX_LINUX, allow_redirects=True) + open("pax", "wb").write(r.content) + os.chmod("pax", 0o755) + return + + if OS == "windows": + print("downloading and extracting pax for windows...") + r = requests.get(PAX_WINDOWS, allow_redirects=True) + open("pax-windows.zip", "wb").write(r.content) + shutil.unpack_archive("pax-windows.zip", ".") + os.remove("pax-windows.zip") + return + + +def pax_from_source(): + if OS == "windows": + print("building from source not supported on windows yet") + os._exit(1) + + if not command_exists("nimble"): + print("nim is not installed - make sure it is installed for your platform") + os._exit(1) + + TMP = tempfile.mkdtemp() + os.chdir(TMP) + + subprocess.run(["git", "clone", PAX_GITHUB], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + os.chdir("pax") + + subprocess.run(["nimble", "build", "-d:release"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocess.run(["cp", "./pax", WORKING_DIR]) + + +# helper functions +def command_exists(binary_name): + return shutil.which(binary_name) is not None + + +# entry +__main__() diff --git a/venv.ps1 b/venv.ps1 new file mode 100644 index 0000000..e63c0d5 --- /dev/null +++ b/venv.ps1 @@ -0,0 +1,18 @@ +# Check for python3 or python +if (Get-Command "python3") { + $python = "python3" +} else { + $python = "python" +} + +# Check if .venv directory exists +if (-Not (Test-Path "./.venv")) { + & $python -m venv .venv +} + +# Activate the virtual environment +. ./.venv/bin/Activate.ps1 + +# Install required packages +& $python -m pip install --upgrade pip +& $python -m pip install -r requirements.txt \ No newline at end of file diff --git a/venv.sh b/venv.sh new file mode 100755 index 0000000..c287fe3 --- /dev/null +++ b/venv.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if command -v python3 &> /dev/null; then + python="python3" +else + python="python" +fi + +if [ -d .venv ]; then exit 0; fi + +$python -m venv .venv +source .venv/bin/activate + +$python -m pip install --upgrade pip +$python -m pip install -r requirements.txt