Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] buildscript refine: generate mmc instance and modrinth mods compatibility #1231

Open
wants to merge 6 commits into
base: master-ceu
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ Special thanks to our volunteers:
## Building the pack
1. Run `pip install requests` first to install required package.
2. Run `python build/main.py`.
> [!NOTE]
> Run `python build/main.py -i` or `python build/main.py --instance` to generate PrismLauncher instance for test
> `PrismLauncher -> Settings -> Launcher -> Features -> Folders -> Instance` can reset the instances folder
3. Check `buildOut` folder.
63 changes: 63 additions & 0 deletions build/instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
import re
import shutil
import subprocess

instance_dir = './buildOut/instances'

def nextInstanceNum():
all_items = os.listdir(instance_dir)
folders = [item for item in all_items if os.path.isdir(os.path.join(instance_dir, item))]

numbers = []
for folder in folders:
if folder.startswith("Test"):
numbers.append(int(folder[-1]))

return max(numbers, default=0) + 1

def createConfiguration(name: str):
cfg = f'''
InstanceType=OneSix
JavaPath=Replace this with your java path
LogPrePostOutput=true
ManagedPack=false
ManagedPackID=
ManagedPackName=
ManagedPackType=
ManagedPackVersionID=
ManagedPackVersionName=
iconKey=default
lastLaunchTime=0
lastTimePlayed=0
name={name}
notes=
totalTimePlayed=0
'''
with open(f'{instance_dir}/{name}/instance.cfg', 'w', encoding='utf-8') as file:
file.write(cfg)

def createMMCPackJson(name: str):
shutil.copy(
f'./build/instance/mmc-pack.json',
f'{instance_dir}/{name}/mmc-pack.json'
)


def newInstance(number: int):
name = f'Test {number}'
os.makedirs(f'{instance_dir}/{name}')

# Configurations
createConfiguration(name)
createMMCPackJson(name)

minecraft = f'{instance_dir}/{name}/minecraft'
os.makedirs(minecraft)

os.chdir('build/server')
subprocess.run(['java', '-jar', 'packwiz-installer-bootstrap.jar', '../../pack.toml'], check=True)
os.chdir('../..')

for folder in ['config', 'groovy', 'journeymap', 'mods', 'resourcepacks', 'resources', 'structures']:
shutil.copytree(f'./build/server/{folder}', f'{instance_dir}/{name}/minecraft/{folder}')
37 changes: 37 additions & 0 deletions build/instance/mmc-pack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"components": [
{
"cachedName": "LWJGL 2",
"cachedVersion": "2.9.4-nightly-20150209",
"dependencyOnly": true,
"uid": "org.lwjgl",
"version": "2.9.4-nightly-20150209"
},
{
"cachedName": "Minecraft",
"cachedRequires": [
{
"suggests": "2.9.4-nightly-20150209",
"uid": "org.lwjgl"
}
],
"cachedVersion": "1.12.2",
"important": true,
"uid": "net.minecraft",
"version": "1.12.2"
},
{
"cachedName": "Forge",
"cachedRequires": [
{
"equals": "1.12.2",
"uid": "net.minecraft"
}
],
"cachedVersion": "14.23.5.2860",
"uid": "net.minecraftforge",
"version": "14.23.5.2860"
}
],
"formatVersion": 1
}
49 changes: 39 additions & 10 deletions build/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
import subprocess
import zipfile

import requests

# Used to run questbook.py
import questbook

import instance
import download

# used to map a projects classId on curseforge to a folder
class_id_to_dir = {
6: "mods",
12: "resourcepacks",
-1: "other"
}
# put the modrinth mod's modname in this array
modrinth_files = [
""
]


def parse_args():
Expand All @@ -37,6 +33,8 @@ def parse_args():
help="makes a folder with all the files symlinked for development. probally only works on linux")
parser.add_argument("-c", "--client", action="store_true",
help="only builds the client pack")
parser.add_argument("-i", "--instance", action="store_true",
help="generate Prism(MMC) instance")
parser.add_argument("--prefix",
type=str,
default="susy",
Expand Down Expand Up @@ -70,20 +68,39 @@ def build(args):
sys.exit(0)

refresh()

if args.instance:
gen_prism_instance()
return

export_client_pack() # Client

if args.client:
print("done")
return

export_modlist()
export_server_pack()
print("done")

def refresh():
subprocess.run([packwizName, 'refresh'], check=True)

def export_client_pack():
print("Client Pack Exporting")
subprocess.run([packwizName, 'curseforge', 'export', '-o', 'client.zip'], check=True)

def remove_folder_from_zip(zip_path, folder_name):
temp_zip_path = zip_path + "_temp"
with zipfile.ZipFile(zip_path, 'r') as zip_in:
with zipfile.ZipFile(temp_zip_path, 'w') as zip_out:
for entry in zip_in.infolist():
if not entry.filename.startswith(folder_name + '/'):
zip_out.writestr(entry, zip_in.read(entry.filename))
os.replace(temp_zip_path, zip_path)

remove_folder_from_zip("client.zip", "mods")

shutil.copy('./client.zip', './buildOut/')
os.remove('./client.zip')
print("Client Pack Export Done")
Expand Down Expand Up @@ -116,15 +133,27 @@ def export_server_pack():

def export_modlist():
print("Modlist Exporting")
result = subprocess.run([packwizName, 'list'], capture_output=True, encoding='utf-8').stdout.strip().split('\n')
result = subprocess.run([packwizName, 'list', '-s', 'client'], capture_output=True, encoding='utf-8').stdout.strip().split('\n')
with open(basePath + "/buildOut/modlist.html", "w") as file:
data = "<html><body><h1>Modlist</h1><ul>"
for mod in result:
if mod in modrinth_files: continue
data += "<li>" + mod + "</li>"
data += "</ul></body></html>"
file.write(data)
print("Modlist Export Done")

def gen_prism_instance():
print('Generating PrismLauncher Instance')
instance_dir = './buildOut/instances'
if os.path.isdir(instance_dir):
print('Instance folder exist')
instance.newInstance(instance.nextInstanceNum())
else:
print('Initial Instance')
os.mkdir(instance_dir)
instance.newInstance(1)


if __name__ == "__main__":
build(parse_args())